本文整理汇总了Java中io.grpc.ServerCall.Listener类的典型用法代码示例。如果您正苦于以下问题:Java Listener类的具体用法?Java Listener怎么用?Java Listener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Listener类属于io.grpc.ServerCall包,在下文中一共展示了Listener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interceptCall
import io.grpc.ServerCall.Listener; //导入依赖的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);
}
示例2: interceptCall
import io.grpc.ServerCall.Listener; //导入依赖的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);
}
}
示例3: getServerBuilder
import io.grpc.ServerCall.Listener; //导入依赖的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;
}
});
}
示例4: callNextTwice
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Test
public void callNextTwice() {
ServerInterceptor interceptor = new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
// Calling next twice is permitted, although should only rarely be useful.
assertSame(listener, next.startCall(call, headers));
return next.startCall(call, headers);
}
};
ServerServiceDefinition intercepted = ServerInterceptors.intercept(serviceDefinition,
interceptor);
assertSame(listener,
getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers));
verify(handler, times(2)).startCall(same(call), same(headers));
verifyNoMoreInteractions(handler);
}
示例5: argumentsPassed
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Test
public void argumentsPassed() {
@SuppressWarnings("unchecked")
final ServerCall<String, Integer> call2 = new NoopServerCall<String, Integer>();
@SuppressWarnings("unchecked")
final ServerCall.Listener<String> listener2 = mock(ServerCall.Listener.class);
ServerInterceptor interceptor = new ServerInterceptor() {
@SuppressWarnings("unchecked") // Lot's of casting for no benefit. Not intended use.
@Override
public <R1, R2> ServerCall.Listener<R1> interceptCall(
ServerCall<R1, R2> call,
Metadata headers,
ServerCallHandler<R1, R2> next) {
assertSame(call, ServerInterceptorsTest.this.call);
assertSame(listener,
next.startCall((ServerCall<R1, R2>)call2, headers));
return (ServerCall.Listener<R1>) listener2;
}
};
ServerServiceDefinition intercepted = ServerInterceptors.intercept(
serviceDefinition, Arrays.asList(interceptor));
assertSame(listener2,
getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers));
verify(handler).startCall(call2, headers);
}
示例6: interceptCall
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
String clientId = headers.get(CLIENT_ID_HEADER_KEY);
if (clientId == null || !authenticator.authenticate(clientId)) {
call.close(Status.UNAUTHENTICATED.withDescription("Invalid or unknown client: " + clientId), headers);
return NOOP_LISTENER;
}
Context context = Context.current().withValue(CLIENT_ID_CONTEXT_KEY, clientId);
return Contexts.interceptCall(context, call, headers, next);
}
示例7: interceptCall
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
RequestMetadata meta = headers.get(METADATA_KEY);
if (meta == null) {
throw new IllegalStateException("RequestMetadata not received from the client.");
}
Context ctx = Context.current().withValue(CONTEXT_KEY, meta);
return Contexts.interceptCall(ctx, call, headers, next);
}
示例8: setup
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
/**
* Set up the registry.
*/
@Setup(Level.Trial)
public void setup() throws Exception {
registry = new MutableHandlerRegistry();
fullMethodNames = new ArrayList<String>(serviceCount * methodCountPerService);
for (int serviceIndex = 0; serviceIndex < serviceCount; ++serviceIndex) {
String serviceName = randomString();
ServerServiceDefinition.Builder serviceBuilder = ServerServiceDefinition.builder(serviceName);
for (int methodIndex = 0; methodIndex < methodCountPerService; ++methodIndex) {
String methodName = randomString();
MethodDescriptor<Void, Void> methodDescriptor = MethodDescriptor.<Void, Void>newBuilder()
.setType(MethodDescriptor.MethodType.UNKNOWN)
.setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName))
.setRequestMarshaller(TestMethodDescriptors.voidMarshaller())
.setResponseMarshaller(TestMethodDescriptors.voidMarshaller())
.build();
serviceBuilder.addMethod(methodDescriptor,
new ServerCallHandler<Void, Void>() {
@Override
public Listener<Void> startCall(ServerCall<Void, Void> call,
Metadata headers) {
return null;
}
});
fullMethodNames.add(methodDescriptor.getFullMethodName());
}
registry.addService(serviceBuilder.build());
}
}
示例9: interceptCall
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
return next.startCall(call, headers);
}
示例10: MessagePrincipalListener
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
public MessagePrincipalListener(ServerCall.Listener<R> delegate,String principal,SeldonGrpcServer server) {
this.delegate = delegate;
this.server = server;
this.principal = principal;
}
示例11: delegate
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
protected Listener<R> delegate() {
return delegate;
}
示例12: interceptCall
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
calledInterceptors.add(2);
return next.startCall(call, headers);
}
示例13: ContextualizedServerCallListener
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
public ContextualizedServerCallListener(ServerCall.Listener<ReqT> delegate, Context context) {
super(delegate);
this.context = context;
}
示例14: SeldonServerCallListener
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
public SeldonServerCallListener(ServerCall.Listener<R> delegate,String client,ExternalRpcServer server) {
this.delegate = delegate;
this.server = server;
this.client = client;
}
示例15: delegate
import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
protected Listener<R> delegate() {
return delegate;
}