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


Java ServerCall类代码示例

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

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

示例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);
}
 
开发者ID:benalexau,项目名称:rpc-bench,代码行数:17,代码来源:ConnectionInterceptor.java

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

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

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

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

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

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

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

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

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

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

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

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


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