本文整理汇总了Java中io.grpc.ServerCall类的典型用法代码示例。如果您正苦于以下问题:Java ServerCall类的具体用法?Java ServerCall怎么用?Java ServerCall使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerCall类属于io.grpc包,在下文中一共展示了ServerCall类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: echoRequestHeadersInterceptor
import io.grpc.ServerCall; //导入依赖的package包/类
/**
* Echo the request headers from a client into response headers and trailers. Useful for
* testing end-to-end metadata propagation.
*/
private static ServerInterceptor echoRequestHeadersInterceptor(final Metadata.Key<?>... keys) {
final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
return new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
final Metadata requestHeaders,
ServerCallHandler<ReqT, RespT> next) {
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void sendHeaders(Metadata responseHeaders) {
responseHeaders.merge(requestHeaders, keySet);
super.sendHeaders(responseHeaders);
}
@Override
public void close(Status status, Metadata trailers) {
trailers.merge(requestHeaders, keySet);
super.close(status, trailers);
}
}, requestHeaders);
}
};
}
示例2: interceptCall
import io.grpc.ServerCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
if (Objects.isNull(SecurityContextHolder.getContext().getAuthentication())) {
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken(key,
"anonymousUser", Collections.singletonList(new SimpleGrantedAuthority("ROLE_ANONYMOUS"))));
log.debug("Populated SecurityContextHolder with anonymous token: {}",
SecurityContextHolder.getContext().getAuthentication());
} else {
log.debug("SecurityContextHolder not populated with anonymous token, as it already contained: {}",
SecurityContextHolder.getContext().getAuthentication());
}
return next.startCall(call, headers);
}
示例3: interceptCall
import io.grpc.ServerCall; //导入依赖的package包/类
@SuppressWarnings("checkstyle:MethodTypeParameterName")
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(
final ServerCall<ReqT, RespT> call, final Metadata headers,
final ServerCallHandler<ReqT, RespT> next) {
TL.set(call);
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void close(final Status status, final Metadata trailers) {
super.close(status, trailers);
TL.remove();
}
}, headers);
}
示例4: MonitoringServerCall
import io.grpc.ServerCall; //导入依赖的package包/类
MonitoringServerCall(
ServerCall<R,S> delegate,
Clock clock,
GrpcMethod grpcMethod,
ServerMetrics serverMetrics,
Configuration configuration) {
super(delegate);
this.clock = clock;
this.grpcMethod = grpcMethod;
this.serverMetrics = serverMetrics;
this.configuration = configuration;
this.startInstant = clock.instant();
// TODO(dino): Consider doing this in the onReady() method of the listener instead.
reportStartMetrics();
}
示例5: interceptCall
import io.grpc.ServerCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,ServerCallHandler<ReqT, RespT> next) {
logger.info("Call intercepted "+headers.toString());
String token = headers.get(authKey);
if (StringUtils.notEmpty(token))
{
try
{
logger.info("Token "+token);
ConsumerBean consumer = resourceServer.validateResourceFromToken(token);
logger.info("Setting call to client "+consumer.getShort_name());
return new SeldonServerCallListener<ReqT>(next.startCall(call, headers),consumer.getShort_name(),this);
}
catch (APIException e)
{
logger.warn("API exception on getting token ",e);
return next.startCall(call, headers);
}
}
else
{
logger.warn("Empty token ignoring call");
return next.startCall(call, headers);
}
}
示例6: clientHeaderDeliveredToServer
import io.grpc.ServerCall; //导入依赖的package包/类
@Test
public void clientHeaderDeliveredToServer() {
grpcServerRule.getServiceRegistry()
.addService(ServerInterceptors.intercept(new GreeterImplBase() {}, mockServerInterceptor));
GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(
ClientInterceptors.intercept(grpcServerRule.getChannel(), new HeaderClientInterceptor()));
ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
try {
blockingStub.sayHello(HelloRequest.getDefaultInstance());
fail();
} catch (StatusRuntimeException expected) {
// expected because the method is not implemented at server side
}
verify(mockServerInterceptor).interceptCall(
Matchers.<ServerCall<HelloRequest, HelloReply>>any(),
metadataCaptor.capture(),
Matchers.<ServerCallHandler<HelloRequest, HelloReply>>any());
assertEquals(
"customRequestValue",
metadataCaptor.getValue().get(HeaderClientInterceptor.CUSTOM_HEADER_KEY));
}
示例7: interceptCall
import io.grpc.ServerCall; //导入依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
final Metadata requestHeaders,
ServerCallHandler<ReqT, RespT> next) {
return next.startCall(
new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void sendHeaders(Metadata headers) {
for (String cacheControlDirective : cacheControlDirectives) {
headers.put(CACHE_CONTROL_METADATA_KEY, cacheControlDirective);
}
super.sendHeaders(headers);
}
},
requestHeaders);
}
示例8: echoRequestMetadataInHeaders
import io.grpc.ServerCall; //导入依赖的package包/类
/**
* Echoes request headers with the specified key(s) from a client into response headers only.
*/
private static ServerInterceptor echoRequestMetadataInHeaders(final Metadata.Key<?>... keys) {
final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
return new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
final Metadata requestHeaders,
ServerCallHandler<ReqT, RespT> next) {
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void sendHeaders(Metadata responseHeaders) {
responseHeaders.merge(requestHeaders, keySet);
super.sendHeaders(responseHeaders);
}
@Override
public void close(Status status, Metadata trailers) {
super.close(status, trailers);
}
}, requestHeaders);
}
};
}
示例9: echoRequestMetadataInTrailers
import io.grpc.ServerCall; //导入依赖的package包/类
/**
* Echoes request headers with the specified key(s) from a client into response trailers only.
*/
private static ServerInterceptor echoRequestMetadataInTrailers(final Metadata.Key<?>... keys) {
final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
return new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
final Metadata requestHeaders,
ServerCallHandler<ReqT, RespT> next) {
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void sendHeaders(Metadata responseHeaders) {
super.sendHeaders(responseHeaders);
}
@Override
public void close(Status status, Metadata trailers) {
trailers.merge(requestHeaders, keySet);
super.close(status, trailers);
}
}, requestHeaders);
}
};
}
示例10: getServerBuilder
import io.grpc.ServerCall; //导入依赖的package包/类
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
return NettyServerBuilder.forPort(0)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.compressorRegistry(compressors)
.decompressorRegistry(decompressors)
.intercept(new ServerInterceptor() {
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
Metadata headers, ServerCallHandler<ReqT, RespT> next) {
Listener<ReqT> listener = next.startCall(call, headers);
// TODO(carl-mastrangelo): check that encoding was set.
call.setMessageCompression(true);
return listener;
}
});
}
示例11: startCall
import io.grpc.ServerCall; //导入依赖的package包/类
/** Never returns {@code null}. */
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
ServerMethodDefinition<ReqT, RespT> methodDef, Metadata headers,
Context.CancellableContext context, StatsTraceContext statsTraceCtx) {
// TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
ServerCallImpl<ReqT, RespT> call = new ServerCallImpl<ReqT, RespT>(
stream, methodDef.getMethodDescriptor(), headers, context,
decompressorRegistry, compressorRegistry);
ServerCallHandler<ReqT, RespT> callHandler = methodDef.getServerCallHandler();
statsTraceCtx.serverCallStarted(
new ServerCallInfoImpl<ReqT, RespT>(
methodDef.getMethodDescriptor(),
call.getAttributes(),
call.getAuthority()));
for (ServerInterceptor interceptor : interceptors) {
callHandler = InternalServerInterceptors.interceptCallHandler(interceptor, callHandler);
}
ServerCall.Listener<ReqT> listener = callHandler.startCall(call, headers);
if (listener == null) {
throw new NullPointerException(
"startCall() returned a null listener for method " + fullMethodName);
}
return call.newServerStreamListener(listener);
}
示例12: testClientClose_cancelTriggersImmediateCancellation
import io.grpc.ServerCall; //导入依赖的package包/类
@Test
public void testClientClose_cancelTriggersImmediateCancellation() throws Exception {
AtomicBoolean contextCancelled = new AtomicBoolean(false);
AtomicReference<Context> context = new AtomicReference<Context>();
AtomicReference<ServerCall<String, Integer>> callReference
= new AtomicReference<ServerCall<String, Integer>>();
ServerStreamListener streamListener = testClientClose_setup(callReference,
context, contextCancelled);
// For close status being non OK:
// isCancelled is expected to be true immediately after calling closed(), without needing
// to wait for the main executor to run any tasks.
assertFalse(callReference.get().isCancelled());
assertFalse(context.get().isCancelled());
streamListener.closed(Status.CANCELLED);
assertEquals(1, executor.runDueTasks(CONTEXT_CLOSER_TASK_FITLER));
assertTrue(callReference.get().isCancelled());
assertTrue(context.get().isCancelled());
assertEquals(1, executor.runDueTasks());
assertTrue(contextCancelled.get());
}
示例13: testClientClose_OkTriggersDelayedCancellation
import io.grpc.ServerCall; //导入依赖的package包/类
@Test
public void testClientClose_OkTriggersDelayedCancellation() throws Exception {
AtomicBoolean contextCancelled = new AtomicBoolean(false);
AtomicReference<Context> context = new AtomicReference<Context>();
AtomicReference<ServerCall<String, Integer>> callReference
= new AtomicReference<ServerCall<String, Integer>>();
ServerStreamListener streamListener = testClientClose_setup(callReference,
context, contextCancelled);
// For close status OK:
// isCancelled is expected to be true after all pending work is done
assertFalse(callReference.get().isCancelled());
assertFalse(context.get().isCancelled());
streamListener.closed(Status.OK);
assertFalse(callReference.get().isCancelled());
assertFalse(context.get().isCancelled());
assertEquals(1, executor.runDueTasks());
assertTrue(callReference.get().isCancelled());
assertTrue(context.get().isCancelled());
assertTrue(contextCancelled.get());
}
示例14: cannotDisableAutoFlowControlAfterServiceInvocation
import io.grpc.ServerCall; //导入依赖的package包/类
@Test
public void cannotDisableAutoFlowControlAfterServiceInvocation() throws Exception {
final AtomicReference<ServerCallStreamObserver<Integer>> callObserver =
new AtomicReference<ServerCallStreamObserver<Integer>>();
ServerCallHandler<Integer, Integer> callHandler =
ServerCalls.asyncBidiStreamingCall(
new ServerCalls.BidiStreamingMethod<Integer, Integer>() {
@Override
public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) {
callObserver.set((ServerCallStreamObserver<Integer>) responseObserver);
return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
callHandler.startCall(serverCall, new Metadata());
callListener.onMessage(1);
try {
callObserver.get().disableAutoInboundFlowControl();
fail("Cannot set onCancel handler after service invocation");
} catch (IllegalStateException expected) {
// Expected
}
}
示例15: disablingInboundAutoFlowControlSuppressesRequestsForMoreMessages
import io.grpc.ServerCall; //导入依赖的package包/类
@Test
public void disablingInboundAutoFlowControlSuppressesRequestsForMoreMessages() throws Exception {
ServerCallHandler<Integer, Integer> callHandler =
ServerCalls.asyncBidiStreamingCall(
new ServerCalls.BidiStreamingMethod<Integer, Integer>() {
@Override
public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) {
ServerCallStreamObserver<Integer> serverCallObserver =
(ServerCallStreamObserver<Integer>) responseObserver;
serverCallObserver.disableAutoInboundFlowControl();
return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
callHandler.startCall(serverCall, new Metadata());
callListener.onReady();
// Transport should not call this if nothing has been requested but forcing it here
// to verify that message delivery does not trigger a call to request(1).
callListener.onMessage(1);
// Should never be called
assertThat(serverCall.requestCalls).isEmpty();
}