本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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));
}
示例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);
}
示例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());
}
示例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();
}
示例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();
}
示例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);
}
}
示例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);
}
示例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);
}
示例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!");
}
}
示例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());
}