Java Code Examples for io.grpc.ServerStreamTracer#Factory

The following examples show how to use io.grpc.ServerStreamTracer#Factory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalInProcess.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new InProcessTransport.
 *
 * <p>When started, the transport will be registered with the given
 * {@link ServerListener}.
 */
@Internal
public static ConnectionClientTransport createInProcessTransport(
    String name,
    int maxInboundMetadataSize,
    String authority,
    String userAgent,
    Attributes eagAttrs,
    ObjectPool<ScheduledExecutorService> serverSchedulerPool,
    List<ServerStreamTracer.Factory> serverStreamTracerFactories,
    ServerListener serverListener) {
  return new InProcessTransport(
      name,
      maxInboundMetadataSize,
      authority,
      userAgent,
      eagAttrs,
      serverSchedulerPool,
      serverStreamTracerFactories,
      serverListener);
}
 
Example 2
Source File: InternalCensusStatsAccessor.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link ServerStreamTracer.Factory} with custom stats implementation.
 */
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
    Tagger tagger,
    TagContextBinarySerializer tagCtxSerializer,
    StatsRecorder statsRecorder,
    Supplier<Stopwatch> stopwatchSupplier,
    boolean propagateTags,
    boolean recordStartedRpcs,
    boolean recordFinishedRpcs,
    boolean recordRealTimeMetrics) {
  CensusStatsModule censusStats =
      new CensusStatsModule(
          tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
          propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics);
  return censusStats.getServerTracerFactory();
}
 
Example 3
Source File: AbstractServerImplBuilderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_default() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  List<ServerStreamTracer.Factory> factories = builder.getTracerFactories();
  assertEquals(3, factories.size());
  assertThat(factories.get(0)).isInstanceOf(CensusStatsModule.ServerTracerFactory.class);
  assertThat(factories.get(1)).isInstanceOf(CensusTracingModule.ServerTracerFactory.class);
  assertThat(factories.get(2)).isSameAs(DUMMY_USER_TRACER);
}
 
Example 4
Source File: InProcessServer.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
InProcessServer(
    InProcessServerBuilder builder,
    List<? extends ServerStreamTracer.Factory> streamTracerFactories) {
  this.name = builder.name;
  this.schedulerPool = builder.schedulerPool;
  this.maxInboundMetadataSize = builder.maxInboundMetadataSize;
  this.streamTracerFactories =
      Collections.unmodifiableList(checkNotNull(streamTracerFactories, "streamTracerFactories"));
}
 
Example 5
Source File: AbstractServerImplBuilderTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_disableTracing() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  builder.setTracingEnabled(false);

  List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();

  assertEquals(2, factories.size());
  assertThat(factories.get(0).getClass().getName())
      .isEqualTo("io.grpc.census.CensusStatsModule$ServerTracerFactory");
  assertThat(factories.get(1)).isSameInstanceAs(DUMMY_USER_TRACER);
}
 
Example 6
Source File: NettyServerTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
NettyServerTransport(
    Channel channel,
    ChannelPromise channelUnused,
    ProtocolNegotiator protocolNegotiator,
    List<? extends ServerStreamTracer.Factory> streamTracerFactories,
    TransportTracer transportTracer,
    int maxStreams,
    boolean autoFlowControl,
    int flowControlWindow,
    int maxMessageSize,
    int maxHeaderListSize,
    long keepAliveTimeInNanos,
    long keepAliveTimeoutInNanos,
    long maxConnectionIdleInNanos,
    long maxConnectionAgeInNanos,
    long maxConnectionAgeGraceInNanos,
    boolean permitKeepAliveWithoutCalls,
    long permitKeepAliveTimeInNanos) {
  this.channel = Preconditions.checkNotNull(channel, "channel");
  this.channelUnused = channelUnused;
  this.protocolNegotiator = Preconditions.checkNotNull(protocolNegotiator, "protocolNegotiator");
  this.streamTracerFactories =
      Preconditions.checkNotNull(streamTracerFactories, "streamTracerFactories");
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.maxStreams = maxStreams;
  this.autoFlowControl = autoFlowControl;
  this.flowControlWindow = flowControlWindow;
  this.maxMessageSize = maxMessageSize;
  this.maxHeaderListSize = maxHeaderListSize;
  this.keepAliveTimeInNanos = keepAliveTimeInNanos;
  this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos;
  this.maxConnectionIdleInNanos = maxConnectionIdleInNanos;
  this.maxConnectionAgeInNanos = maxConnectionAgeInNanos;
  this.maxConnectionAgeGraceInNanos = maxConnectionAgeGraceInNanos;
  this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls;
  this.permitKeepAliveTimeInNanos = permitKeepAliveTimeInNanos;
  SocketAddress remote = channel.remoteAddress();
  this.logId = InternalLogId.allocate(getClass(), remote != null ? remote.toString() : null);
}
 
Example 7
Source File: NettyServer.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
NettyServer(
    SocketAddress address, Class<? extends ServerChannel> channelType,
    Map<ChannelOption<?>, ?> channelOptions,
    @Nullable EventLoopGroup bossGroup, @Nullable EventLoopGroup workerGroup,
    ProtocolNegotiator protocolNegotiator, List<ServerStreamTracer.Factory> streamTracerFactories,
    TransportTracer.Factory transportTracerFactory,
    int maxStreamsPerConnection, int flowControlWindow, int maxMessageSize, int maxHeaderListSize,
    long keepAliveTimeInNanos, long keepAliveTimeoutInNanos,
    long maxConnectionIdleInNanos,
    long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos,
    boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos,
    InternalChannelz channelz) {
  this.address = address;
  this.channelType = checkNotNull(channelType, "channelType");
  checkNotNull(channelOptions, "channelOptions");
  this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions);
  this.bossGroup = bossGroup;
  this.workerGroup = workerGroup;
  this.protocolNegotiator = checkNotNull(protocolNegotiator, "protocolNegotiator");
  this.streamTracerFactories = checkNotNull(streamTracerFactories, "streamTracerFactories");
  this.usingSharedBossGroup = bossGroup == null;
  this.usingSharedWorkerGroup = workerGroup == null;
  this.transportTracerFactory = transportTracerFactory;
  this.maxStreamsPerConnection = maxStreamsPerConnection;
  this.flowControlWindow = flowControlWindow;
  this.maxMessageSize = maxMessageSize;
  this.maxHeaderListSize = maxHeaderListSize;
  this.keepAliveTimeInNanos = keepAliveTimeInNanos;
  this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos;
  this.maxConnectionIdleInNanos = maxConnectionIdleInNanos;
  this.maxConnectionAgeInNanos = maxConnectionAgeInNanos;
  this.maxConnectionAgeGraceInNanos = maxConnectionAgeGraceInNanos;
  this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls;
  this.permitKeepAliveTimeInNanos = permitKeepAliveTimeInNanos;
  this.channelz = Preconditions.checkNotNull(channelz);
}
 
Example 8
Source File: NettyTransportTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) {
  return NettyServerBuilder
      .forPort(0)
      .flowControlWindow(65 * 1024)
      .setTransportTracerFactory(fakeClockTransportTracer)
      .buildTransportServer(streamTracerFactories);
}
 
Example 9
Source File: OkHttpTransportTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) {
  return AccessProtectedHack.serverBuilderBuildTransportServer(
      NettyServerBuilder
        .forPort(0)
        .flowControlWindow(65 * 1024),
      streamTracerFactories,
      fakeClockTransportTracer);
}
 
Example 10
Source File: InProcessTransportTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) {
  InProcessServerBuilder builder = InProcessServerBuilder
      .forName(TRANSPORT_NAME)
      .maxInboundMetadataSize(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE);
  return new InProcessServer(builder, streamTracerFactories);
}
 
Example 11
Source File: StandaloneInProcessTransportTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
protected List<? extends InternalServer> newServer(
    List<ServerStreamTracer.Factory> streamTracerFactories) {
  return ImmutableList.of(new TestServer(streamTracerFactories));
}
 
Example 12
Source File: InProcessServer.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
List<ServerStreamTracer.Factory> getStreamTracerFactories() {
  return streamTracerFactories;
}
 
Example 13
Source File: InProcessServerBuilder.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
protected InProcessServer buildTransportServer(
    List<ServerStreamTracer.Factory> streamTracerFactories) {
  return new InProcessServer(this, streamTracerFactories);
}
 
Example 14
Source File: AbstractServerImplBuilder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public final T addStreamTracerFactory(ServerStreamTracer.Factory factory) {
  streamTracerFactories.add(checkNotNull(factory, "factory"));
  return thisT();
}
 
Example 15
Source File: CensusTracingModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the server tracer factory.
 */
ServerStreamTracer.Factory getServerTracerFactory() {
  return serverTracerFactory;
}
 
Example 16
Source File: StandaloneInProcessTransportTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
protected List<? extends InternalServer> newServer(
    int port, List<ServerStreamTracer.Factory> streamTracerFactories) {
  return newServer(streamTracerFactories);
}
 
Example 17
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the server tracer factory.
 */
ServerStreamTracer.Factory getServerTracerFactory() {
  return new ServerTracerFactory();
}
 
Example 18
Source File: OrcaMetricReportingServerInterceptorTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void shareCallMetricRecorderInContext() throws IOException {
  final CallMetricRecorder callMetricRecorder =
      InternalCallMetricRecorder.newCallMetricRecorder();
  ServerStreamTracer.Factory callMetricRecorderSharingStreamTracerFactory =
      new ServerStreamTracer.Factory() {
    @Override
    public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) {
      return new ServerStreamTracer() {
        @Override
        public Context filterContext(Context context) {
          return context.withValue(InternalCallMetricRecorder.CONTEXT_KEY, callMetricRecorder);
        }
      };
    }
  };

  final AtomicReference<CallMetricRecorder> callMetricRecorderCapture = new AtomicReference<>();
  SimpleServiceGrpc.SimpleServiceImplBase simpleServiceImpl =
      new SimpleServiceGrpc.SimpleServiceImplBase() {
        @Override
        public void unaryRpc(
            SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
          callMetricRecorderCapture.set(CallMetricRecorder.getCurrent());
          SimpleResponse response =
              SimpleResponse.newBuilder().setResponseMessage("Simple response").build();
          responseObserver.onNext(response);
          responseObserver.onCompleted();
        }
      };

  ServerInterceptor metricReportingServerInterceptor = new OrcaMetricReportingServerInterceptor();
  String serverName = InProcessServerBuilder.generateName();
  grpcCleanupRule.register(
      InProcessServerBuilder
          .forName(serverName)
          .directExecutor()
          .addStreamTracerFactory(callMetricRecorderSharingStreamTracerFactory)
          .addService(
              ServerInterceptors.intercept(simpleServiceImpl, metricReportingServerInterceptor))
          .build().start());

  ManagedChannel channel =
      grpcCleanupRule.register(InProcessChannelBuilder.forName(serverName).build());
  ClientCalls.blockingUnaryCall(channel, SIMPLE_METHOD, CallOptions.DEFAULT, REQUEST);

  assertThat(callMetricRecorderCapture.get()).isSameInstanceAs(callMetricRecorder);
}
 
Example 19
Source File: InProcessTransportTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
protected List<? extends InternalServer> newServer(
    int port, List<ServerStreamTracer.Factory> streamTracerFactories) {
  return newServer(streamTracerFactories);
}
 
Example 20
Source File: AbstractServerImplBuilder.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * Children of AbstractServerBuilder should override this method to provide transport specific
 * information for the server.  This method is mean for Transport implementors and should not be
 * used by normal users.
 *
 * @param streamTracerFactories an immutable list of stream tracer factories
 */
@Internal
protected abstract io.grpc.internal.InternalServer buildTransportServer(
    List<ServerStreamTracer.Factory> streamTracerFactories);