Java 类io.grpc.internal.AbstractServerImplBuilder 实例源码

项目:grpc-java    文件:Http2OkHttpTest.java   
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
  // Starts the server with HTTPS.
  try {
    SslProvider sslProvider = SslContext.defaultServerProvider();
    if (sslProvider == SslProvider.OPENSSL && !OpenSsl.isAlpnSupported()) {
      // OkHttp only supports Jetty ALPN on OpenJDK. So if OpenSSL doesn't support ALPN, then we
      // are forced to use Jetty ALPN for Netty instead of OpenSSL.
      sslProvider = SslProvider.JDK;
    }
    SslContextBuilder contextBuilder = SslContextBuilder
        .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"));
    GrpcSslContexts.configure(contextBuilder, sslProvider);
    contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE);
    return NettyServerBuilder.forPort(0)
        .flowControlWindow(65 * 1024)
        .maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
        .sslContext(contextBuilder.build());
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
项目:grpc-java    文件:TransportCompressionTest.java   
@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;
          }
        });
}
项目:grpc-java    文件:Http2NettyTest.java   
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
  // Starts the server with HTTPS.
  try {
    return NettyServerBuilder.forPort(0)
        .flowControlWindow(65 * 1024)
        .maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
        .sslContext(GrpcSslContexts
            .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
            .clientAuth(ClientAuth.REQUIRE)
            .trustManager(TestUtils.loadCert("ca.pem"))
            .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
            .sslProvider(SslProvider.OPENSSL)
            .build());
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
项目:armeria    文件:ArmeriaGrpcServerBuilder.java   
@Override
protected InternalServer buildTransportServer(List<Factory> streamTracerFactories) {
    Object registryBuilder = getFieldByReflection("registryBuilder", this, AbstractServerImplBuilder.class);
    Map<String, ServerServiceDefinition> services = getFieldByReflection("services", registryBuilder, null);
    services.values().forEach(grpcServiceBuilder::addService);

    armeriaServerBuilder.serviceUnder("/", grpcServiceBuilder.build()
                                                             .decorate((delegate, ctx, req) -> {
                                                                 ctxCapture.set(ctx);
                                                                 return delegate.serve(ctx, req);
                                                             }));
    return new ArmeriaGrpcServer(armeriaServerBuilder.build());
}
项目:onos    文件:P4RuntimeGroupTest.java   
@BeforeClass
public static void globalSetup() throws IOException {
    AbstractServerImplBuilder builder = InProcessServerBuilder
            .forName(GRPC_SERVER_NAME).directExecutor();
    builder.addService(p4RuntimeServerImpl);
    grpcServer = builder.build().start();
    grpcChannel = InProcessChannelBuilder.forName(GRPC_SERVER_NAME)
            .directExecutor()
            .usePlaintext(true)
            .build();
}
项目:onos    文件:InProcessServer.java   
public void start() throws IOException, InstantiationException, IllegalAccessException {

        AbstractServerImplBuilder builder = InProcessServerBuilder.forName("test").directExecutor();
        services.forEach(service -> builder.addService(service));
        server = builder.build().start();
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                // Use stderr here since the logger may have been reset by its JVM shutdown hook.
                System.err.println("*** shutting down gRPC server since JVM is shutting down");
                InProcessServer.this.stop();
                System.err.println("*** server shut down");
            }
        });
    }
项目:grpc-java    文件:AbstractInteropTest.java   
private void startServer() {
  AbstractServerImplBuilder<?> builder = getServerBuilder();
  if (builder == null) {
    server = null;
    return;
  }
  testServiceExecutor = Executors.newScheduledThreadPool(2);

  List<ServerInterceptor> allInterceptors = ImmutableList.<ServerInterceptor>builder()
      .add(recordServerCallInterceptor(serverCallCapture))
      .add(TestUtils.recordRequestHeadersInterceptor(requestHeadersCapture))
      .add(recordContextInterceptor(contextCapture))
      .addAll(TestServiceImpl.interceptors())
      .build();

  builder
      .addService(
          ServerInterceptors.intercept(
              new TestServiceImpl(testServiceExecutor),
              allInterceptors))
      .addStreamTracerFactory(serverStreamTracerFactory);
  io.grpc.internal.TestingAccessor.setStatsImplementation(
      builder,
      new CensusStatsModule(
          tagger,
          tagContextBinarySerializer,
          serverStatsRecorder,
          GrpcUtil.STOPWATCH_SUPPLIER,
          true));
  try {
    server = builder.build().start();
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
项目:grpc-java    文件:Http2NettyLocalChannelTest.java   
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
  return NettyServerBuilder
      .forAddress(new LocalAddress("in-process-1"))
      .flowControlWindow(65 * 1024)
      .maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
      .channelType(LocalServerChannel.class);
}
项目:grpc-java    文件:AbstractInteropTest.java   
/**
 * Returns the server builder used to create server for each test run.  Return {@code null} if
 * it shouldn't start a server in the same process.
 */
@Nullable
protected AbstractServerImplBuilder<?> getServerBuilder() {
  return null;
}
项目:grpc-java    文件:AutoWindowSizingOnTest.java   
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
  return NettyServerBuilder.forPort(0).maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
}
项目:grpc-java    文件:InProcessTest.java   
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
  // Starts the in-process server.
  return InProcessServerBuilder.forName(SERVER_NAME);
}