本文整理汇总了Java中io.grpc.Context.CancellableContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.CancellableContext方法的具体用法?Java Context.CancellableContext怎么用?Java Context.CancellableContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.Context
的用法示例。
在下文中一共展示了Context.CancellableContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startCall
import io.grpc.Context; //导入方法依赖的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);
}
示例2: contextCancellationCancelsStream
import io.grpc.Context; //导入方法依赖的package包/类
@Test
public void contextCancellationCancelsStream() throws Exception {
// Attach the context which is recorded when the call is created
Context.CancellableContext cancellableContext = Context.current().withCancellation();
Context previous = cancellableContext.attach();
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(
method,
new SerializingExecutor(Executors.newSingleThreadExecutor()),
baseCallOptions,
provider,
deadlineCancellationExecutor,
channelCallTracer)
.setDecompressorRegistry(decompressorRegistry);
previous.attach();
call.start(callListener, new Metadata());
Throwable t = new Throwable();
cancellableContext.cancel(t);
verify(stream, times(1)).cancel(statusArgumentCaptor.capture());
Status streamStatus = statusArgumentCaptor.getValue();
assertEquals(Status.Code.CANCELLED, streamStatus.getCode());
}
示例3: ServerCallImpl
import io.grpc.Context; //导入方法依赖的package包/类
ServerCallImpl(ServerStream stream, MethodDescriptor<ReqT, RespT> method,
Metadata inboundHeaders, Context.CancellableContext context,
DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry) {
this.stream = stream;
this.method = method;
this.context = context;
this.messageAcceptEncoding = inboundHeaders.get(MESSAGE_ACCEPT_ENCODING_KEY);
this.decompressorRegistry = decompressorRegistry;
this.compressorRegistry = compressorRegistry;
}
示例4: JumpToApplicationThreadServerStreamListener
import io.grpc.Context; //导入方法依赖的package包/类
public JumpToApplicationThreadServerStreamListener(Executor executor,
Executor cancelExecutor, ServerStream stream, Context.CancellableContext context) {
this.callExecutor = executor;
this.cancelExecutor = cancelExecutor;
this.stream = stream;
this.context = context;
}
示例5: ContextCloser
import io.grpc.Context; //导入方法依赖的package包/类
ContextCloser(Context.CancellableContext context, Throwable cause) {
this.context = context;
this.cause = cause;
}