当前位置: 首页>>代码示例>>Java>>正文


Java ClientCall.start方法代码示例

本文整理汇总了Java中io.grpc.ClientCall.start方法的典型用法代码示例。如果您正苦于以下问题:Java ClientCall.start方法的具体用法?Java ClientCall.start怎么用?Java ClientCall.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.ClientCall的用法示例。


在下文中一共展示了ClientCall.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unaryCall

import io.grpc.ClientCall; //导入方法依赖的package包/类
/**
 * Executes a unary call with a response {@link SingleObserver}.
 */
public static <ReqT, RespT> Single<RespT> unaryCall(
    final ClientCall<ReqT, RespT> call,
    final ReqT request) {
  final SingleRequestSender<ReqT> requestSender = new SingleRequestSender<ReqT>(call, request);
  SingleResponseReceiver<RespT> responseReceiver = new SingleResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  call.start(responseReceiver, new Metadata());

  return Single.wrap(responseReceiver.singleSource());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:20,代码来源:ClientCallsRx.java

示例2: serverStreamingCall

import io.grpc.ClientCall; //导入方法依赖的package包/类
/**
 * Executes a server-streaming call with a response {@link Subscriber}.
 */
public static <ReqT, RespT> Flowable<RespT> serverStreamingCall(
    final ClientCall<ReqT, RespT> call,
    ReqT request) {
  final SingleRequestSender<ReqT> requestSender = new SingleRequestSender<ReqT>(call, request);
  StreamingResponseReceiver<RespT> responseReceiver = new StreamingResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  call.start(responseReceiver, new Metadata());

  return Flowable.fromPublisher(responseReceiver.publisher());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:20,代码来源:ClientCallsRx.java

示例3: clientStreamingCall

import io.grpc.ClientCall; //导入方法依赖的package包/类
/**
 * Executes a client-streaming call returning a {@link StreamObserver} for the requestMore messages.
 *
 * @return requestMore stream observer.
 */
public static <ReqT, RespT> Single<RespT> clientStreamingCall(
    ClientCall<ReqT, RespT> call,
    Flowable<ReqT> requests,
    CallOptions options) {
  final StreamRequestSender<ReqT> requestSender = new StreamRequestSender<ReqT>(call, getLowWatermark(options), getHighWatermark(options));
  SingleResponseReceiver<RespT> responseReceiver = new SingleResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  ClientCall.Listener<RespT> delegate = new DelegateClientCallListener<RespT>(requestSender, responseReceiver);
  call.start(delegate, new Metadata());

  requests.subscribe(requestSender.subscriber());

  return Single.wrap(responseReceiver.singleSource());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:26,代码来源:ClientCallsRx.java

示例4: bidiStreamingCall

import io.grpc.ClientCall; //导入方法依赖的package包/类
/**
 * Executes a bidi-streaming call.
 *
 * @return requestMore stream observer.
 */
public static <ReqT, RespT> Flowable<RespT> bidiStreamingCall(
    ClientCall<ReqT, RespT> call,
    Flowable<ReqT> requests,
    CallOptions options) {
  final StreamRequestSender<ReqT> requestSender = new StreamRequestSender<ReqT>(call, getLowWatermark(options), getHighWatermark(options));
  StreamingResponseReceiver<RespT> responseReceiver = new StreamingResponseReceiver<RespT>(call) {
    @Override
    public void startCall() {
      requestSender.startCall();
      super.startCall();
    }
  };

  ClientCall.Listener<RespT> delegate = new DelegateClientCallListener<RespT>(requestSender, responseReceiver);
  call.start(delegate, new Metadata());

  requests.subscribe(requestSender.subscriber());

  return Flowable.fromPublisher(responseReceiver.publisher());
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:26,代码来源:ClientCallsRx.java

示例5: channelStat_callEndFail_oob

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void channelStat_callEndFail_oob() throws Exception {
  createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR);
  OobChannel oob1 = (OobChannel) helper.createOobChannel(addressGroup, "oob1authority");
  ClientCall<String, Integer> call = oob1.newCall(method, CallOptions.DEFAULT);
  call.start(mockCallListener, new Metadata());
  call.cancel("msg", null);

  assertEquals(0, getStats(channel).callsSucceeded);
  assertEquals(0, getStats(channel).callsFailed);
  oobExecutor.runDueTasks();
  // only oob channel stats updated
  verify(mockCallListener).onClose(any(Status.class), any(Metadata.class));
  assertEquals(0, getStats(oob1).callsSucceeded);
  assertEquals(1, getStats(oob1).callsFailed);
  assertEquals(0, getStats(channel).callsSucceeded);
  assertEquals(0, getStats(channel).callsFailed);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:19,代码来源:ManagedChannelImplTest.java

示例6: testWithOAuth2Credential

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void testWithOAuth2Credential() {
  final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
  final OAuth2Credentials oAuth2Credentials = new OAuth2Credentials() {
    @Override
    public AccessToken refreshAccessToken() throws IOException {
      return token;
    }
  };
  interceptor = new ClientAuthInterceptor(oAuth2Credentials, executor);
  ClientCall<String, Integer> interceptedCall =
      interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  Metadata headers = new Metadata();
  interceptedCall.start(listener, headers);
  assertEquals(listener, call.responseListener);
  assertEquals(headers, call.headers);
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  Assert.assertArrayEquals(new String[]{"Bearer allyourbase"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ClientAuthInterceptorTest.java

示例7: verifyServiceUri

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void verifyServiceUri() throws IOException {
  ClientCall<String, Integer> interceptedCall;

  doReturn("example.com:443").when(channel).authority();
  interceptedCall = interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  interceptedCall.start(listener, new Metadata());
  verify(credentials).getRequestMetadata(URI.create("https://example.com/a.service"));
  interceptedCall.cancel("Cancel for test", null);

  doReturn("example.com:123").when(channel).authority();
  interceptedCall = interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  interceptedCall.start(listener, new Metadata());
  verify(credentials).getRequestMetadata(URI.create("https://example.com:123/a.service"));
  interceptedCall.cancel("Cancel for test", null);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:ClientAuthInterceptorTest.java

示例8: updateSubchannelAddresses_existingAddressDoesNotConnect

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void updateSubchannelAddresses_existingAddressDoesNotConnect() {
  ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
  call.start(mockCallListener, new Metadata()); // Create LB
  ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
  verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
  Helper helper = helperCaptor.getValue();
  Subchannel subchannel = helper.createSubchannel(servers.get(0), Attributes.EMPTY);

  subchannel.requestConnection();
  MockClientTransportInfo t0 = newTransports.poll();
  t0.listener.transportReady();

  List<SocketAddress> changedList = new ArrayList<SocketAddress>(servers.get(0).getAddresses());
  changedList.add(new FakeSocketAddress("aDifferentServer"));
  helper.updateSubchannelAddresses(subchannel, new EquivalentAddressGroup(changedList));

  subchannel.requestConnection();
  assertNull(newTransports.poll());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ManagedChannelImplIdlenessTest.java

示例9: delayedTransportHoldsOffIdleness

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void delayedTransportHoldsOffIdleness() throws Exception {
  ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
  call.start(mockCallListener, new Metadata());
  assertTrue(channel.inUseStateAggregator.isInUse());

  // As long as the delayed transport is in-use (by the pending RPC), the channel won't go idle.
  timer.forwardTime(IDLE_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);
  assertTrue(channel.inUseStateAggregator.isInUse());

  // Cancelling the only RPC will reset the in-use state.
  assertEquals(0, executor.numPendingTasks());
  call.cancel("In test", null);
  assertEquals(1, executor.runDueTasks());
  assertFalse(channel.inUseStateAggregator.isInUse());
  // And allow the channel to go idle.
  timer.forwardTime(IDLE_TIMEOUT_SECONDS - 1, TimeUnit.SECONDS);
  verify(mockLoadBalancer, never()).shutdown();
  timer.forwardTime(1, TimeUnit.SECONDS);
  verify(mockLoadBalancer).shutdown();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:ManagedChannelImplIdlenessTest.java

示例10: updateOobChannelAddresses_newAddressConnects

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void updateOobChannelAddresses_newAddressConnects() {
  ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
  call.start(mockCallListener, new Metadata()); // Create LB
  ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
  verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
  Helper helper = helperCaptor.getValue();
  ManagedChannel oobChannel = helper.createOobChannel(servers.get(0), "localhost");

  oobChannel.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
  MockClientTransportInfo t0 = newTransports.poll();
  t0.listener.transportReady();

  helper.updateOobChannelAddresses(oobChannel, servers.get(1));

  oobChannel.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
  MockClientTransportInfo t1 = newTransports.poll();
  t1.listener.transportReady();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:ManagedChannelImplIdlenessTest.java

示例11: startCall

import io.grpc.ClientCall; //导入方法依赖的package包/类
static void startCall(ClientCall<Message, Message> call,
    ClientCall.Listener<Message> responseListener, boolean streamingResponse) {
  call.start(responseListener, new Metadata());
  if (streamingResponse) {
    call.request(1);
  } else {
    call.request(2);
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:10,代码来源:GrpcStreamClientCall.java

示例12: greet

import io.grpc.ClientCall; //导入方法依赖的package包/类
/** Say hello to server. */
public void greet(final String name) {
  final ClientCall<HelloRequest, HelloReply> call =
      channel.newCall(GreeterGrpc.METHOD_SAY_HELLO, CallOptions.DEFAULT);

  final CountDownLatch latch = new CountDownLatch(1);

  call.start(new Listener<HelloReply>() {
    @Override
    public void onHeaders(Metadata headers) {
      super.onHeaders(headers);
      String encoding = headers.get(GrpcUtil.MESSAGE_ENCODING_KEY);
      if (encoding == null) {
        throw new RuntimeException("No compression selected!");
      }
    }

    @Override
    public void onMessage(HelloReply message) {
      super.onMessage(message);
      logger.info("Greeting: " + message.getMessage());
      latch.countDown();
    }

    @Override
    public void onClose(Status status, Metadata trailers) {
      latch.countDown();
      if (!status.isOk()) {
        throw status.asRuntimeException();
      }
    }
  }, new Metadata());

  call.setMessageCompression(true);
  call.sendMessage(HelloRequest.newBuilder().setName(name).build());
  call.request(1);
  call.halfClose();

  Uninterruptibles.awaitUninterruptibly(latch, 100, TimeUnit.SECONDS);
}
 
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:41,代码来源:CompressingHelloWorldClient.java

示例13: newCallExitsIdleness

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void newCallExitsIdleness() throws Exception {
  ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
  call.start(mockCallListener, new Metadata());

  verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class));

  verify(mockNameResolver).start(nameResolverListenerCaptor.capture());
  // Simulate new address resolved to make sure the LoadBalancer is correctly linked to
  // the NameResolver.
  nameResolverListenerCaptor.getValue().onAddresses(servers, Attributes.EMPTY);
  verify(mockLoadBalancer).handleResolvedAddressGroups(servers, Attributes.EMPTY);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:14,代码来源:ManagedChannelImplIdlenessTest.java

示例14: advancedAsyncCall

import io.grpc.ClientCall; //导入方法依赖的package包/类
/**
 * This is more advanced and does not make use of the stub.  You should not normally need to do
 * this, but here is how you would.
 */
void advancedAsyncCall() {
  ClientCall<HelloRequest, HelloReply> call =
      channel.newCall(GreeterGrpc.getSayHelloMethod(), CallOptions.DEFAULT);

  final CountDownLatch latch = new CountDownLatch(1);

  call.start(new ClientCall.Listener<HelloReply>() {

    @Override
    public void onClose(Status status, Metadata trailers) {
      Verify.verify(status.getCode() == Status.Code.INTERNAL);
      Verify.verify(trailers.containsKey(DEBUG_INFO_TRAILER_KEY));
      try {
        Verify.verify(trailers.get(DEBUG_INFO_TRAILER_KEY).equals(DEBUG_INFO));
      } catch (IllegalArgumentException e) {
        throw new VerifyException(e);
      }

      latch.countDown();
    }
  }, new Metadata());

  call.sendMessage(HelloRequest.newBuilder().build());
  call.halfClose();

  if (!Uninterruptibles.awaitUninterruptibly(latch, 1, TimeUnit.SECONDS)) {
    throw new RuntimeException("timeout!");
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:34,代码来源:DetailErrorSample.java

示例15: testCredentialsThrows

import io.grpc.ClientCall; //导入方法依赖的package包/类
@Test
public void testCredentialsThrows() throws IOException {
  when(credentials.getRequestMetadata(any(URI.class))).thenThrow(new IOException("Broken"));
  ClientCall<String, Integer> interceptedCall =
      interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  Metadata headers = new Metadata();
  interceptedCall.start(listener, headers);
  ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
  Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.class));
  Assert.assertNull(headers.getAll(AUTHORIZATION));
  assertNull(call.responseListener);
  assertNull(call.headers);
  Assert.assertEquals(Status.Code.UNAUTHENTICATED, statusCaptor.getValue().getCode());
  Assert.assertNotNull(statusCaptor.getValue().getCause());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:16,代码来源:ClientAuthInterceptorTest.java


注:本文中的io.grpc.ClientCall.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。