/** * Creates a new instance with the specified parameters. */ static RpcRequest of(Class<?> serviceType, String method, Object... params) { requireNonNull(params, "params"); switch (params.length) { case 0: return of(serviceType, method); case 1: return of(serviceType, method, params[0]); default: return new DefaultRpcRequest(serviceType, method, params); } }
/** * Returns a {@link RpcRequest} corresponding to the given {@link MethodDescriptor}. */ public static RpcRequest rpcRequest(MethodDescriptor<?, ?> method) { // See below to learn why we use GrpcLogUtil.class here. return RpcRequest.of(GrpcLogUtil.class, method.getFullMethodName()); }
/** * Returns a {@link RpcRequest} corresponding to the given {@link MethodDescriptor}. */ public static RpcRequest rpcRequest(MethodDescriptor<?, ?> method, Object message) { // We don't actually use the RpcRequest for request processing since it doesn't fit well with streaming. // We still populate it with a reasonable method name for use in logging. The service type is currently // arbitrarily set as gRPC doesn't use Class<?> to represent services - if this becomes a problem, we // would need to refactor it to take a Object instead. return RpcRequest.of(GrpcLogUtil.class, method.getFullMethodName(), message); }
/** * Creates a new instance with the specified parameters. */ static RpcRequest of(Class<?> serviceType, String method, Iterable<?> params) { requireNonNull(params, "params"); if (!(params instanceof Collection)) { return new DefaultRpcRequest(serviceType, method, params); } final Collection<?> paramCollection = (Collection<?>) params; switch (paramCollection.size()) { case 0: return of(serviceType, method); case 1: if (paramCollection instanceof List) { return of(serviceType, method, ((List<?>) paramCollection).get(0)); } else { return of(serviceType, method, paramCollection.iterator().next()); } default: return new DefaultRpcRequest(serviceType, method, paramCollection.toArray()); } }
private static RpcRequest toRpcRequest(Class<?> serviceType, String method, TBase<?, ?> thriftArgs) { requireNonNull(thriftArgs, "thriftArgs"); // NB: The map returned by FieldMetaData.getStructMetaDataMap() is an EnumMap, // so the parameter ordering is preserved correctly during iteration. final Set<? extends TFieldIdEnum> fields = FieldMetaData.getStructMetaDataMap(thriftArgs.getClass()).keySet(); // Handle the case where the number of arguments is 0 or 1. final int numFields = fields.size(); switch (numFields) { case 0: return RpcRequest.of(serviceType, method); case 1: return RpcRequest.of(serviceType, method, ThriftFieldAccess.get(thriftArgs, fields.iterator().next())); } // Handle the case where the number of arguments is greater than 1. final List<Object> list = new ArrayList<>(numFields); for (TFieldIdEnum field : fields) { list.add(ThriftFieldAccess.get(thriftArgs, field)); } return RpcRequest.of(serviceType, method, list); }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
final RpcRequest rpcReq = RpcRequest.of(HelloService.Iface.class, "hello", "Armeria"); final HttpResponse res = HttpResponse.of(HttpStatus.OK); final RpcResponse rpcRes = RpcResponse.of("Hello, Armeria!");
.build(); final RpcRequest rpcReq = RpcRequest.of(HelloService.Iface.class, "hello", "trustin"); final HttpResponse res = HttpResponse.of(HttpStatus.OK); final RpcResponse rpcRes = RpcResponse.of("Hello, trustin!");
/** * Returns a {@link RpcRequest} corresponding to the given {@link MethodDescriptor}. */ public static RpcRequest rpcRequest(MethodDescriptor<?, ?> method, Object message) { // We don't actually use the RpcRequest for request processing since it doesn't fit well with streaming. // We still populate it with a reasonable method name for use in logging. The service type is currently // arbitrarily set as gRPC doesn't use Class<?> to represent services - if this becomes a problem, we // would need to refactor it to take a Object instead. return RpcRequest.of(GrpcLogUtil.class, method.getFullMethodName(), message); }
/** * Returns a {@link RpcRequest} corresponding to the given {@link MethodDescriptor}. */ public static RpcRequest rpcRequest(MethodDescriptor<?, ?> method) { // See below to learn why we use GrpcLogUtil.class here. return RpcRequest.of(GrpcLogUtil.class, method.getFullMethodName()); }
private static RpcRequest toRpcRequest(Class<?> serviceType, String method, TBase<?, ?> thriftArgs) { requireNonNull(thriftArgs, "thriftArgs"); // NB: The map returned by FieldMetaData.getStructMetaDataMap() is an EnumMap, // so the parameter ordering is preserved correctly during iteration. final Set<? extends TFieldIdEnum> fields = FieldMetaData.getStructMetaDataMap(thriftArgs.getClass()).keySet(); // Handle the case where the number of arguments is 0 or 1. final int numFields = fields.size(); switch (numFields) { case 0: return RpcRequest.of(serviceType, method); case 1: return RpcRequest.of(serviceType, method, ThriftFieldAccess.get(thriftArgs, fields.iterator().next())); } // Handle the case where the number of arguments is greater than 1. final List<Object> list = new ArrayList<>(numFields); for (TFieldIdEnum field : fields) { list.add(ThriftFieldAccess.get(thriftArgs, field)); } return RpcRequest.of(serviceType, method, list); }
private static RpcRequest toRpcRequest(Class<?> serviceType, String method, TBase<?, ?> thriftArgs) { requireNonNull(thriftArgs, "thriftArgs"); // NB: The map returned by FieldMetaData.getStructMetaDataMap() is an EnumMap, // so the parameter ordering is preserved correctly during iteration. final Set<? extends TFieldIdEnum> fields = FieldMetaData.getStructMetaDataMap(thriftArgs.getClass()).keySet(); // Handle the case where the number of arguments is 0 or 1. final int numFields = fields.size(); switch (numFields) { case 0: return RpcRequest.of(serviceType, method); case 1: return RpcRequest.of(serviceType, method, ThriftFieldAccess.get(thriftArgs, fields.iterator().next())); } // Handle the case where the number of arguments is greater than 1. final List<Object> list = new ArrayList<>(numFields); for (TFieldIdEnum field : fields) { list.add(ThriftFieldAccess.get(thriftArgs, field)); } return RpcRequest.of(serviceType, method, list); }
private static RpcRequest toRpcRequest(Class<?> serviceType, String method, TBase<?, ?> thriftArgs) { requireNonNull(thriftArgs, "thriftArgs"); // NB: The map returned by FieldMetaData.getStructMetaDataMap() is an EnumMap, // so the parameter ordering is preserved correctly during iteration. final Set<? extends TFieldIdEnum> fields = FieldMetaData.getStructMetaDataMap(thriftArgs.getClass()).keySet(); // Handle the case where the number of arguments is 0 or 1. final int numFields = fields.size(); switch (numFields) { case 0: return RpcRequest.of(serviceType, method); case 1: return RpcRequest.of(serviceType, method, ThriftFieldAccess.get(thriftArgs, fields.iterator().next())); } // Handle the case where the number of arguments is greater than 1. final List<Object> list = new ArrayList<>(numFields); for (TFieldIdEnum field : fields) { list.add(ThriftFieldAccess.get(thriftArgs, field)); } return RpcRequest.of(serviceType, method, list); }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }
private RpcResponse execute0( String path, Class<?> serviceType, @Nullable String serviceName, String method, Object[] args) { path = concatPaths(uri().getRawPath(), path); final PathAndQuery pathAndQuery = PathAndQuery.parse(path); if (pathAndQuery == null) { return RpcResponse.ofFailure(new IllegalArgumentException("invalid path: " + path)); } // A thrift path is always good to cache as it cannot have non-fixed parameters. pathAndQuery.storeInCache(path); final RpcRequest call = RpcRequest.of(serviceType, method, args); return execute(HttpMethod.POST, pathAndQuery.path(), null, serviceName, call, (ctx, cause) -> new DefaultRpcResponse(cause)); } }