• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Listener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.grpc.ServerCall.Listener的典型用法代码示例。如果您正苦于以下问题:Java Listener类的具体用法?Java Listener怎么用?Java Listener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Listener类属于io.grpc.ServerCall包,在下文中一共展示了Listener类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:benalexau,项目名称:rpc-bench,代码行数:17,代码来源:ConnectionInterceptor.java


示例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);
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:26,代码来源:ExternalRpcServer.java


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


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


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


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


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


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


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


示例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;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:6,代码来源:MessagePrincipalListener.java


示例11: delegate

import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
protected Listener<R> delegate() {
    return delegate;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:5,代码来源:MessagePrincipalListener.java


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


示例13: ContextualizedServerCallListener

import io.grpc.ServerCall.Listener; //导入依赖的package包/类
public ContextualizedServerCallListener(ServerCall.Listener<ReqT> delegate, Context context) {
  super(delegate);
  this.context = context;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:5,代码来源:AuthGrpcServerInterceptor.java


示例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;
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:6,代码来源:ExternalRpcServer.java


示例15: delegate

import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
protected Listener<R> delegate() {
	return delegate;
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:5,代码来源:ExternalRpcServer.java


示例16: shutdownShouldCancelOngoingUploads

import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Test(timeout = 10000)
public void shutdownShouldCancelOngoingUploads() throws Exception {
  withEmptyMetadata.attach();
  RemoteRetrier retrier =
      new RemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, Retrier.ALLOW_ALL_CALLS);
  ByteStreamUploader uploader =
      new ByteStreamUploader(INSTANCE_NAME, channel, null, 3, retrier, retryService);

  CountDownLatch cancellations = new CountDownLatch(2);

  ServerServiceDefinition service =
      ServerServiceDefinition.builder(ByteStreamGrpc.SERVICE_NAME)
      .addMethod(ByteStreamGrpc.METHOD_WRITE,
          new ServerCallHandler<WriteRequest, WriteResponse>() {
            @Override
            public Listener<WriteRequest> startCall(ServerCall<WriteRequest, WriteResponse> call,
                Metadata headers) {
              // Don't request() any messages from the client, so that the client will be blocked
              // on flow control and thus the call will sit there idle long enough to receive the
              // cancellation.
              return new Listener<WriteRequest>() {
                @Override
                public void onCancel() {
                  cancellations.countDown();
                }
              };
            }
          })
      .build();

  serviceRegistry.addService(service);

  byte[] blob1 = new byte[CHUNK_SIZE];
  Chunker chunker1 = new Chunker(blob1, CHUNK_SIZE, DIGEST_UTIL);

  byte[] blob2 = new byte[CHUNK_SIZE + 1];
  Chunker chunker2 = new Chunker(blob2, CHUNK_SIZE, DIGEST_UTIL);

  ListenableFuture<Void> f1 = uploader.uploadBlobAsync(chunker1);
  ListenableFuture<Void> f2 = uploader.uploadBlobAsync(chunker2);

  assertThat(uploader.uploadsInProgress()).isTrue();

  uploader.shutdown();

  cancellations.await();

  assertThat(f1.isCancelled()).isTrue();
  assertThat(f2.isCancelled()).isTrue();

  blockUntilInternalStateConsistent(uploader);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:53,代码来源:ByteStreamUploaderTest.java


示例17: interceptCall

import io.grpc.ServerCall.Listener; //导入依赖的package包/类
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(
    ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
  return next.startCall(call, headers);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:6,代码来源:HeaderClientInterceptorTest.java


示例18: handleAuthTokenException

import io.grpc.ServerCall.Listener; //导入依赖的package包/类
/**
 * Handle AuthToken Exception.
 * <p>
 * 1. illegal token, need to ask client side to relogin
 * </p>
 * <p>
 * 2. refresh token is expired, need to ask client side to relogin
 * </p>
 * 
 * @param call
 * @param userPrincipal
 * @param tokenAuthenticator
 * @param tokenStatus
 * @return Listener<ReqT>
 */
private <ReqT, RespT> Listener<ReqT> handleAuthTokenException(ServerCall<ReqT, RespT> call, TokenStatus tokenStatus) {
  Metadata trailers = new Metadata();
  // illegal rpc access or the refresh token is expired
  if (TokenStatus.INVALID.getCode().equals(tokenStatus.getCode())
      || TokenStatus.EXPIRED.getCode().equals(tokenStatus.getCode())) {
    trailers.put(errorDetailsKey, ErrorReporter.UNAUTHENTICATED
        .withSpecificErrorMsg(MessageErrorCode.ERROR_UNAUTHENTICATED_KEY, true).toErrorDetails());
    call.close(Status.UNAUTHENTICATED, trailers);
  }
  return new ServerCall.Listener<ReqT>() {};
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:27,代码来源:AuthGrpcServerInterceptor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PreemptionContainerProto类代码示例发布时间:2022-05-22
下一篇:
Java GetContainerStatusesResponseProtoOrBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap