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


Java Context.CancellableContext方法代码示例

本文整理汇总了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);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:ServerImpl.java

示例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());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:ClientCallImplTest.java

示例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;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:11,代码来源:ServerCallImpl.java

示例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;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:ServerImpl.java

示例5: ContextCloser

import io.grpc.Context; //导入方法依赖的package包/类
ContextCloser(Context.CancellableContext context, Throwable cause) {
  this.context = context;
  this.cause = cause;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:5,代码来源:ServerImpl.java


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