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


Java NettyServerBuilder类代码示例

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


NettyServerBuilder类属于io.grpc.netty包,在下文中一共展示了NettyServerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
/**
 * Start Netty Grpc Server.
 *
 * @return Server gRPC Server
 * @throws IOException - when something went wrong starting the grpc server
 */
final Server start() throws IOException {
  final int port = 8080;

  log.info("Starting grpc server on port '{}'...", port);
  final Server server =
      NettyServerBuilder
          .forPort(port)
          .addService(productReadService)
          .addService(productUpdateService)
          .addService(ServerInterceptors.intercept(echoService, serviceInterceptor))
          .build();

  server.start();
  log.info("grpc (port={}) server started successfully.", port);

  return server;
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:24,代码来源:GrpcServer.java

示例2: PluginGrpcServer

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
public PluginGrpcServer(int port) {
    this.pluginConnections = new HashMap<>();

    PlayerEvents playerEvents = new PlayerEvents(this);

    this.server = NettyServerBuilder.forPort(port)
            .keepAliveTime(1, TimeUnit.MINUTES)
            .keepAliveTimeout(5, TimeUnit.SECONDS)

            .addService(playerEvents)

            .directExecutor()
            .channelType(EpollServerSocketChannel.class)
            .bossEventLoopGroup(new EpollEventLoopGroup())
            .workerEventLoopGroup(new EpollEventLoopGroup())
            .build();

    // demoPluginConnections();
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:20,代码来源:PluginGrpcServer.java

示例3: before

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
/**
 * Before the test has started, create the server and channel.
 */
@Override
protected void before() throws Throwable {
    serviceRegistry = new MutableHandlerRegistry();

    NettyServerBuilder serverBuilder = NettyServerBuilder
            .forPort(0)
            .fallbackHandlerRegistry(serviceRegistry);

    if (useDirectExecutor) {
        serverBuilder.directExecutor();
    }

    configureServerBuilder.accept(serverBuilder);
    server = serverBuilder.build().start();
    port = server.getPort();

    NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress("localhost", port).usePlaintext(true);
    configureChannelBuilder.accept(channelBuilder);
    channel = channelBuilder.build();
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:24,代码来源:NettyGrpcServerRule.java

示例4: activate

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
@Activate
protected void activate(ComponentContext context) throws IOException {
    modified(context);

    log.debug("Server starting on {}", listenPort);
    try {
        server  = NettyServerBuilder.forPort(listenPort)
                .addService(DeviceProviderRegistryRpcGrpc.bindService(new DeviceProviderRegistryServerProxy()))
                .addService(LinkProviderServiceRpcGrpc.bindService(new LinkProviderServiceServerProxy(this)))
                .build().start();
    } catch (IOException e) {
        log.error("Failed to start gRPC server", e);
        throw e;
    }

    log.info("Started on {}", listenPort);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:GrpcRemoteServiceServer.java

示例5: main

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    NettyServerBuilder.forAddress(LocalAddress.ANY).forPort(19876)
        .maxConcurrentCallsPerConnection(12).maxMessageSize(16777216)
        .addService(new MockApplicationRegisterService())
        .addService(new MockInstanceDiscoveryService())
        .addService(new MockJVMMetricsService())
        .addService(new MockServiceNameDiscoveryService())
        .addService(new MockTraceSegmentService()).build().start();

    Server jettyServer = new Server(new InetSocketAddress("0.0.0.0",
        Integer.valueOf(12800)));
    String contextPath = "/";
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    servletContextHandler.setContextPath(contextPath);
    servletContextHandler.addServlet(GrpcAddressHttpService.class, GrpcAddressHttpService.SERVLET_PATH);
    servletContextHandler.addServlet(ReceiveDataService.class, ReceiveDataService.SERVLET_PATH);
    servletContextHandler.addServlet(ClearReceiveDataService.class, ClearReceiveDataService.SERVLET_PATH);
    jettyServer.setHandler(servletContextHandler);
    jettyServer.start();
}
 
开发者ID:SkywalkingTest,项目名称:skywalking-mock-collector,代码行数:21,代码来源:Main.java

示例6: setUp

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  serviceRegistry.addService(new MaintenanceImplBase() {
     @Override
     public void snapshot(SnapshotRequest request, StreamObserver<SnapshotResponse> observer) {
       try {
         observerQueue.put(observer);
       } catch (InterruptedException e) {
         throw new RuntimeException(e);
       }
     }
   }
  );

  fakeServer = NettyServerBuilder.forPort(TestUtil.findNextAvailablePort())
      .fallbackHandlerRegistry(serviceRegistry)
      .directExecutor()
      .build()
      .start();

  client = Client.builder().endpoints("http://127.0.0.1:" + fakeServer.getPort()).build();
  maintenance = client.getMaintenanceClient();
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:24,代码来源:MaintenanceUnitTest.java

示例7: start

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
@Override
public void start() throws Exception {
    LOG.info("Configuring server on port " + port);
    server = NettyServerBuilder.forPort(port)
        .addService(chatHandler)
        .build();
    LOG.info("Starting server");
    server.start();
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            ChatServerImpl.this.stop();
        }
    });
    blockUntilShutdown();
}
 
开发者ID:aalmiray,项目名称:javatrove,代码行数:17,代码来源:ChatServerImpl.java

示例8: start

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
private AsyncFuture<Void> start() throws IOException {
    final Server server = NettyServerBuilder
        .forAddress(address)
        .addService(bindService())
        .maxMessageSize(maxFrameSize)
        .bossEventLoopGroup(bossGroup)
        .workerEventLoopGroup(workerGroup)
        .build();

    return async.call(() -> {
        server.start();
        this.server.set(server);
        return null;
    }).directTransform(v -> {
        final InetSocketAddress localAddress = extractInetSocketAddress(server);
        bindFuture.resolve(localAddress);
        return null;
    });
}
 
开发者ID:spotify,项目名称:heroic,代码行数:20,代码来源:GrpcRpcProtocolServer.java

示例9: startServer

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
private static Server startServer(String bindAddress, int port, boolean https, File centralDir,
        DownstreamServiceImpl downstreamService, CollectorServiceImpl collectorService)
        throws IOException {
    NettyServerBuilder builder =
            NettyServerBuilder.forAddress(new InetSocketAddress(bindAddress, port));
    if (https) {
        builder.useTransportSecurity(
                getHttpsConfFile(centralDir, "grpc-cert.pem", "cert.pem", "certificate"),
                getHttpsConfFile(centralDir, "grpc-key.pem", "key.pem", "private key"));
    }
    return builder.addService(collectorService.bindService())
            .addService(downstreamService.bindService())
            // need to override default max message size of 4mb until streaming is implemented
            // for DownstreamService.EntriesResponse and FullTraceResponse
            .maxMessageSize(64 * 1024 * 1024)
            .build()
            .start();
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:19,代码来源:GrpcServer.java

示例10: GrpcServerWrapper

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
GrpcServerWrapper(TraceCollector collector, int port) throws IOException {
    bossEventLoopGroup = EventLoopGroups.create("Glowroot-IT-Harness-GRPC-Boss-ELG");
    workerEventLoopGroup = EventLoopGroups.create("Glowroot-IT-Harness-GRPC-Worker-ELG");
    executor = Executors.newCachedThreadPool(
            new ThreadFactoryBuilder()
                    .setDaemon(true)
                    .setNameFormat("Glowroot-IT-Harness-GRPC-Executor-%d")
                    .build());
    downstreamService = new DownstreamServiceImpl();
    server = NettyServerBuilder.forPort(port)
            .bossEventLoopGroup(bossEventLoopGroup)
            .workerEventLoopGroup(workerEventLoopGroup)
            .executor(executor)
            .addService(new CollectorServiceImpl(collector).bindService())
            .addService(downstreamService.bindService())
            .maxMessageSize(1024 * 1024 * 100)
            .build()
            .start();
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:20,代码来源:GrpcServerWrapper.java

示例11: startServer

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
public Server startServer() throws IOException {
  ServerInterceptor headersInterceptor = new TracingMetadataUtils.ServerHeadersInterceptor();
  NettyServerBuilder b =
      NettyServerBuilder.forPort(workerOptions.listenPort)
          .addService(ServerInterceptors.intercept(actionCacheServer, headersInterceptor))
          .addService(ServerInterceptors.intercept(bsServer, headersInterceptor))
          .addService(ServerInterceptors.intercept(casServer, headersInterceptor));

  if (execServer != null) {
    b.addService(ServerInterceptors.intercept(execServer, headersInterceptor));
    b.addService(ServerInterceptors.intercept(watchServer, headersInterceptor));
  } else {
    logger.info("Execution disabled, only serving cache requests.");
  }

  Server server = b.build();
  logger.log(INFO, "Starting gRPC server on port {0,number,#}.", workerOptions.listenPort);
  server.start();

  return server;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:22,代码来源:RemoteWorker.java

示例12: activate

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
@Activate
protected void activate(ComponentContext context) throws IOException {
    executor = newScheduledThreadPool(1, Tools.groupedThreads("grpc", "%d", log));
    modified(context);

    log.debug("Server starting on {}", listenPort);
    try {
        server  = NettyServerBuilder.forPort(listenPort)
                .addService(new DeviceProviderRegistryServerProxy())
                .addService(new LinkProviderServiceServerProxy(this))
                .build().start();
    } catch (IOException e) {
        log.error("Failed to start gRPC server", e);
        throw e;
    }

    log.info("Started on {}", listenPort);
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:19,代码来源:GrpcRemoteServiceServer.java

示例13: start

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
@VisibleForTesting
void start() throws Exception {
  executor = Executors.newSingleThreadScheduledExecutor();
  SslContext sslContext = null;
  if (useTls) {
    sslContext = GrpcSslContexts.forServer(
            TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")).build();
  }
  server = NettyServerBuilder.forPort(port)
      .sslContext(sslContext)
      .maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
      .addService(ServerInterceptors.intercept(
          new TestServiceImpl(executor),
          TestServiceImpl.interceptors()))
      .build().start();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:TestServiceServer.java

示例14: newServer

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
/**
 * Creates and starts a new {@link TestServiceImpl} server.
 */
private Server newServer() throws CertificateException, IOException {
  File serverCertChainFile = TestUtils.loadCert("server1.pem");
  File serverPrivateKeyFile = TestUtils.loadCert("server1.key");
  X509Certificate[] serverTrustedCaCerts = {
    TestUtils.loadX509Cert("ca.pem")
  };

  SslContext sslContext =
      GrpcSslContexts.forServer(serverCertChainFile, serverPrivateKeyFile)
                     .trustManager(serverTrustedCaCerts)
                     .clientAuth(ClientAuth.REQUIRE)
                     .build();

  return NettyServerBuilder.forPort(0)
      .sslContext(sslContext)
      .addService(new TestServiceImpl(serverExecutor))
      .build()
      .start();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:23,代码来源:ConcurrencyTest.java

示例15: getServerBuilder

import io.grpc.netty.NettyServerBuilder; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:23,代码来源:Http2OkHttpTest.java


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