new SimpleForwardingClientCall(channel.newCall(methodDesc, callOption.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS))) {
/** * Returns a new stub with a deadline that is after the given {@code duration} from now. * * @since 1.0.0 * @see CallOptions#withDeadlineAfter */ public final S withDeadlineAfter(long duration, TimeUnit unit) { return build(channel, callOptions.withDeadlineAfter(duration, unit)); }
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { // Only add a deadline if no other deadline has been set. if (callOptions.getDeadline() == null && Context.current().getDeadline() == null) { callOptions = callOptions.withDeadlineAfter(duration.toMillis(), TimeUnit.MILLISECONDS); } return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { }; } }
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { // Only add a deadline if no other deadline has been set. if (callOptions.getDeadline() == null && Context.current().getDeadline() == null) { callOptions = callOptions.withDeadlineAfter(duration.toMillis(), TimeUnit.MILLISECONDS); } return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { }; } }
public static <ReqT, RespT> void autoCall() throws Exception { DynamicMultiClassLoader loader = DynamicMultiClassLoader.getLoader(toUrl("/home/darrenfu/IdeaProjects/pampas/pampas-grpc/df/open/grpc/hello/grpc-test-229014610914606914.jar")); Class grpc = loader.load("df.open.grpc.hello.HelloServiceGrpc"); Class proto = loader.load("df.open.grpc.hello.HelloServiceProto"); Method getSayHelloMethod = grpc.getDeclaredMethod("getSayHelloMethod"); MethodDescriptor<ReqT, RespT> methodDescriptor = (MethodDescriptor) getSayHelloMethod.invoke(grpc); ClientCall<ReqT, RespT> call = new ForwardingClientCall.SimpleForwardingClientCall(channel.newCall(methodDescriptor, callOption.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS))) { public void start(Listener responseListener, Metadata headers) { System.out.println("start call......"); super.start(responseListener, headers); } }; // ClientCalls.asyncUnaryCall(call, (ReqT) req.newInstance(), responseFuture); Class<?> reqClz = Class.forName("df.open.grpc.hello.HelloServiceProto$HelloReq", false, loader); Constructor<?> constructor = reqClz.getDeclaredConstructor(); constructor.setAccessible(true); System.out.println(constructor.isAccessible()); RespT respT = ClientCalls.blockingUnaryCall(call, (ReqT) constructor.newInstance()); System.out.println(respT); System.out.println("XXXXXXXxx"); }
/** * Create an {@link CallOptions} that has a fail safe RPC deadline to make sure that unary * operations don't hang. This will have to be overridden for streaming RPCs like read rows. * <p> * The logic is as follows: * <ol> * <li> If the user provides a deadline, use the deadline</li> * <li> Else If this is a streaming read, don't set an explicit deadline. The * {@link com.google.cloud.bigtable.grpc.io.Watchdog} will handle hanging</li> * <li> Else Set a deadline of {@link #UNARY_DEADLINE_MINUTES} minutes deadline.</li> * </ol> * * @see com.google.cloud.bigtable.grpc.io.Watchdog Watchdog which handles hanging for streaming * reads. * * @return a {@link CallOptions} */ protected CallOptions getRpcCallOptions() { if (callOptions.getDeadline() != null || isStreamingRead()) { // If the user set a deadline, honor it. // If this is a streaming read, then the Watchdog will take affect and ensure that hanging does not occur. return getOperationCallOptions(); } else { // Unary calls should fail after 6 minutes, if there isn't any response from the server. return callOptions.withDeadlineAfter(UNARY_DEADLINE_MINUTES, TimeUnit.MINUTES); } }
callOptions = callOptions.withDeadlineAfter(traceProperties.getDeadlineMs(), TimeUnit.MILLISECONDS);