new SimpleForwardingClientCall(channel.newCall(methodDesc, callOption.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS))) {
@Override public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall( MethodDescriptor<RequestT, ResponseT> methodDescriptor, CallOptions callOptions) { return delegate.newCall(methodDescriptor, callOptions); }
@Override public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall( MethodDescriptor<RequestT, ResponseT> methodDescriptor, CallOptions callOptions) { return delegate.newCall(methodDescriptor, callOptions); }
/** * Create a {@link ClientCall} on a Channel from the pool chosen in a round-robin fashion to the * remote operation specified by the given {@link MethodDescriptor}. The returned {@link * ClientCall} does not trigger any remote behavior until {@link * ClientCall#start(ClientCall.Listener, io.grpc.Metadata)} is invoked. */ @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall( MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions) { return getNextChannel().newCall(methodDescriptor, callOptions); }
/** * Create a {@link ClientCall} on a Channel from the pool chosen in a round-robin fashion to the * remote operation specified by the given {@link MethodDescriptor}. The returned {@link * ClientCall} does not trigger any remote behavior until {@link * ClientCall#start(ClientCall.Listener, io.grpc.Metadata)} is invoked. */ @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall( MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions) { return getNextChannel().newCall(methodDescriptor, callOptions); }
private ClientCall<DynamicMessage, DynamicMessage> createCall(CallOptions callOptions) { return channel.newCall(createGrpcMethodDescriptor(), callOptions); }
protected <ReqT,R> ListenableFuture<R> fuCall(MethodDescriptor<ReqT,R> method, ReqT request, CallOptions callOptions) { return ClientCalls.futureUnaryCall(channel.newCall(method, callOptions), request); }
/** * {@inheritDoc} * <P> * Create a {@link ClientCall} on a Channel from the pool chosen in a round-robin fashion to the * remote operation specified by the given {@link MethodDescriptor}. The returned * {@link ClientCall} does not trigger any remote behavior until * {@link ClientCall#start(ClientCall.Listener, io.grpc.Metadata)} is invoked. */ @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall( MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions) { Preconditions.checkState(!shutdown, "Cannot perform operations on a closed connection"); return getNextChannel().newCall(methodDescriptor, callOptions); }
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions) { final Context timerContext = timer.time(); final AtomicBoolean decremented = new AtomicBoolean(false); return new CheckedForwardingClientCall<ReqT, RespT>(delegate.newCall(methodDescriptor, callOptions)) { @Override protected void checkedStart(ClientCall.Listener<RespT> responseListener, Metadata headers) throws Exception { ClientCall.Listener<RespT> timingListener = wrap(responseListener, timerContext, decremented); getStats().ACTIVE_RPC_COUNTER.inc(); getStats().RPC_METER.mark(); delegate().start(timingListener, headers); } @Override public void cancel(String message, Throwable cause) { if (!decremented.getAndSet(true)) { getStats().ACTIVE_RPC_COUNTER.dec(); } super.cancel(message, cause); } }; }
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"); }
private void refreshBackingStream() { if(finished) return; CallOptions callOpts = getCallOptions(); sentCallOptions = callOpts; callOpts = callOpts.withExecutor(responseExecutor); initialReqStream = ClientCalls.asyncBidiStreamingCall(channel .newCall(method, callOpts), respWrapper); }
private void verifyTargetChannel( ChannelPool pool, List<ManagedChannel> channels, ManagedChannel targetChannel) { MethodDescriptor<Color, Money> methodDescriptor = FakeServiceGrpc.METHOD_RECOGNIZE; CallOptions callOptions = CallOptions.DEFAULT; @SuppressWarnings("unchecked") ClientCall<Color, Money> expectedClientCall = Mockito.mock(ClientCall.class); for (ManagedChannel channel : channels) { Mockito.reset(channel); } Mockito.doReturn(expectedClientCall).when(targetChannel).newCall(methodDescriptor, callOptions); ClientCall<Color, Money> actualCall = pool.newCall(methodDescriptor, callOptions); Truth.assertThat(actualCall).isSameAs(expectedClientCall); Mockito.verify(targetChannel, Mockito.times(1)).newCall(methodDescriptor, callOptions); for (ManagedChannel otherChannel : channels) { if (otherChannel != targetChannel) { Mockito.verify(otherChannel, Mockito.never()).newCall(methodDescriptor, callOptions); } } }
@SuppressWarnings("unchecked") private void mockResponse(ManagedChannel channel, Code statusCode, Object... results) { Status status = statusCode.toStatus(); ClientCall<Integer, ?> clientCall = new MockClientCall<>(results[0], status); ClientCall<Integer, ?>[] moreCalls = new ClientCall[results.length - 1]; for (int i = 0; i < results.length - 1; i++) { moreCalls[i] = new MockClientCall<>(results[i + 1], status); } when(channel.newCall(any(MethodDescriptor.class), any(CallOptions.class))) .thenReturn(clientCall, moreCalls); }
public void addCall(MethodCallProperty methodCallProperty) { Method method = methodCallProperty.getMethod(); MethodDescriptor.Builder<Object, Object> builder = MethodDescriptor.newBuilder( marshallerFactory.emptyJacksonMarshaller(), marshallerFactory.parseReturnMarshaller(methodCallProperty) ).setType(methodCallProperty.getMethodType()) .setFullMethodName(MethodDescriptor.generateFullMethodName(methodCallProperty.getScheme(), methodCallProperty.getMethodName())); clientCallMap.put(method.getName(), channel.newCall(builder.build(), CallOptions.DEFAULT)); }
Mockito.when(channels[i].newCall(methodDescriptor, callOptions)) .thenAnswer( new Answer<ClientCall<Color, Money>>() {
@Test public void testAffinity() { MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE; @SuppressWarnings("unchecked") ClientCall<Color, Money> clientCall0 = Mockito.mock(ClientCall.class); @SuppressWarnings("unchecked") ClientCall<Color, Money> clientCall1 = Mockito.mock(ClientCall.class); ManagedChannel channel0 = Mockito.mock(ManagedChannel.class); ManagedChannel channel1 = Mockito.mock(ManagedChannel.class); Mockito.when(channel0.newCall(Mockito.eq(descriptor), Mockito.<CallOptions>any())) .thenReturn(clientCall0); Mockito.when(channel1.newCall(Mockito.eq(descriptor), Mockito.<CallOptions>any())) .thenReturn(clientCall1); Channel pool = new ChannelPool(Arrays.asList(channel0, channel1)); GrpcCallContext context = GrpcCallContext.createDefault().withChannel(pool); ClientCall<Color, Money> gotCallA = GrpcClientCalls.newCall(descriptor, context.withChannelAffinity(0)); ClientCall<Color, Money> gotCallB = GrpcClientCalls.newCall(descriptor, context.withChannelAffinity(0)); ClientCall<Color, Money> gotCallC = GrpcClientCalls.newCall(descriptor, context.withChannelAffinity(1)); assertThat(gotCallA).isSameAs(gotCallB); assertThat(gotCallA).isNotSameAs(gotCallC); }