io.grpc.Server.start()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(80)

本文整理了Java中io.grpc.Server.start()方法的一些代码示例,展示了Server.start()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server.start()方法的具体详情如下:
包路径:io.grpc.Server
类名称:Server
方法名:start

Server.start介绍

[英]Bind and start the server.
[中]绑定并启动服务器。

代码示例

代码示例来源:origin: Netflix/conductor

@Override
public void start() throws IOException {
  registerShutdownHook();
  server.start();
  logger.info("grpc: Server started, listening on " + server.getPort());
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Start serving.
 *
 * @return this instance of {@link GrpcServer}
 * @throws IOException when unable to start serving
 */
public GrpcServer start() throws IOException {
 RetryUtils.retry("Starting gRPC server", () -> mServer.start(),
   new ExponentialBackoffRetry(100, 500, 5));
 mStarted = true;
 return this;
}

代码示例来源:origin: googleapis/google-cloud-java

/** Starts the in-memory service. */
public void start() {
 try {
  server.start();
 } catch (IOException ex) {
  throw new RuntimeException(ex);
 }
}
/** Resets the state of the in-memory service. */

代码示例来源:origin: google/rejoiner

private void start() throws IOException {
 /* The port on which the server should run */
 int port = 50052;
 server = ServerBuilder.forPort(port).addService(new ShelfService()).build().start();
 logger.info("Server started, listening on " + port);
 Runtime.getRuntime()
   .addShutdownHook(
     new Thread(
       () -> {
        // 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");
        ShelfServer.this.stop();
        System.err.println("*** server shut down");
       }));
}

代码示例来源:origin: google/rejoiner

private void start() throws IOException {
 /* The port on which the server should run */
 int port = 50051;
 server = ServerBuilder.forPort(port).addService(new BookService()).build().start();
 logger.info("Server started, listening on " + port);
 Runtime.getRuntime()
   .addShutdownHook(
     new Thread(
       () -> {
        // 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");
        BookServer.this.stop();
        System.err.println("*** server shut down");
       }));
}

代码示例来源:origin: google/rejoiner

private void start() throws IOException {
 /* The port on which the server should run */
 int port = 50051;
 server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
 logger.info("Server started, listening on " + port);
 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");
       HelloWorldServer.this.stop();
       System.err.println("*** server shut down");
      }
     });
}

代码示例来源:origin: google/rejoiner

private void start() throws IOException {
 /* The port on which the server should run */
 int port = 50051;
 server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
 logger.info("Server started, listening on " + port);
 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");
       HelloWorldServer.this.stop();
       System.err.println("*** server shut down");
      }
     });
}

代码示例来源:origin: google/rejoiner

private void start() throws IOException {
 /* The port on which the server should run */
 int port = 8888;
 server = ServerBuilder.forPort(port).addService(new GraphQlServiceImpl()).build().start();
 logger.info("Server started, listening on " + port);
 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");
       GraphQlGrpcServer.this.stop();
       System.err.println("*** server shut down");
      }
     });
}

代码示例来源:origin: weibocom/motan

@SuppressWarnings("rawtypes")
public void init() throws Exception{
  if(!init){
    synchronized (this) {
      if(!init){
        registry = new MotanHandlerRegistry();
        serviceDefinetions = new HashMap<URL, ServerServiceDefinition>();
        io.grpc.ServerBuilder builder = ServerBuilder.forPort(port);
        builder.fallbackHandlerRegistry(registry);
        if(executor != null){
          builder.executor(executor);
        }
        if(builder instanceof NettyServerBuilder){
          httpHandler = new NettyHttpRequestHandler(executor);
          ((NettyServerBuilder)builder).protocolNegotiator(new HttpProtocolNegotiator(httpHandler));
        }
        server = builder.build();
        server.start();
        init = true;
      }
    }
  }
}

代码示例来源:origin: LogNet/grpc-spring-boot-starter

@Override
public void run(String... args) throws Exception {
  log.info("Starting gRPC Server ...");
  Collection<ServerInterceptor> globalInterceptors = getBeanNamesByTypeWithAnnotation(GRpcGlobalInterceptor.class, ServerInterceptor.class)
      .map(name -> applicationContext.getBeanFactory().getBean(name, ServerInterceptor.class))
      .collect(Collectors.toList());
  // Adding health service
  serverBuilder.addService(healthStatusManager.getHealthService());
  // find and register all GRpcService-enabled beans
  getBeanNamesByTypeWithAnnotation(GRpcService.class, BindableService.class)
      .forEach(name -> {
        BindableService srv = applicationContext.getBeanFactory().getBean(name, BindableService.class);
        ServerServiceDefinition serviceDefinition = srv.bindService();
        GRpcService gRpcServiceAnn = applicationContext.findAnnotationOnBean(name, GRpcService.class);
        serviceDefinition = bindInterceptors(serviceDefinition, gRpcServiceAnn, globalInterceptors);
        serverBuilder.addService(serviceDefinition);
        String serviceName = serviceDefinition.getServiceDescriptor().getName();
        healthStatusManager.setStatus(serviceName, HealthCheckResponse.ServingStatus.SERVING);
        log.info("'{}' service has been registered.", srv.getClass().getName());
      });
  if (gRpcServerProperties.isEnableReflection()) {
    serverBuilder.addService(ProtoReflectionService.newInstance());
    log.info("'{}' service has been registered.", ProtoReflectionService.class.getName());
  }
  configurer.configure(serverBuilder);
  server = serverBuilder.build().start();
  applicationContext.publishEvent(new GRpcServerInitializedEvent(server));
  log.info("gRPC Server started, listening on port {}.", server.getPort());
  startDaemonAwaitThread();
}

代码示例来源:origin: Netflix/concurrency-limits

private Server startServer(ServerCalls.UnaryMethod<String, String> method) {
  try {
    return NettyServerBuilder.forPort(0)
        .addService(ServerInterceptors.intercept(
            ServerServiceDefinition.builder("service")
                .addMethod(METHOD_DESCRIPTOR, ServerCalls.asyncUnaryCall(method))
                .build(),
            ConcurrencyLimitServerInterceptor.newBuilder(limiter)
                .build())
        )
        .build()
        .start();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: Netflix/concurrency-limits

))
.build()
.start();

代码示例来源:origin: Netflix/concurrency-limits

.build())
.build()
.start();

代码示例来源:origin: Netflix/conductor

private void addService(String name, BindableService service) throws Exception {
    // Create a server, add service, start, and register for automatic graceful shutdown.
    grpcCleanup.register(InProcessServerBuilder
        .forName(name).directExecutor().addService(service).build().start());
  }
}

代码示例来源:origin: googleapis/google-cloud-java

@Before
public void setUp() throws Exception {
 testPublisherServiceImpl = new FakePublisherServiceImpl();
 InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName("test-server");
 serverBuilder.addService(testPublisherServiceImpl);
 testServer = serverBuilder.build();
 testServer.start();
 fakeExecutor = new FakeScheduledExecutorService();
}

代码示例来源:origin: mrdear/JavaWEB

/**
 * 启动服务
 */
public void start() throws IOException {
  server.start();
  System.out.println("Server started, listening on " + port);
  //程序退出时关闭资源
  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    System.err.println("*** shutting down gRPC server since JVM is shutting down");
    RouteGuideServer.this.stop();
    System.err.println("*** server shut down");
  }));
}

代码示例来源:origin: googleapis/google-cloud-java

@Before
public void setUp() throws Exception {
 InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(testName.getMethodName());
 fakeSubscriberServiceImpl = new FakeSubscriberServiceImpl();
 fakeExecutor = new FakeScheduledExecutorService();
 testChannel = InProcessChannelBuilder.forName(testName.getMethodName()).build();
 serverBuilder.addService(fakeSubscriberServiceImpl);
 testServer = serverBuilder.build();
 testServer.start();
}

代码示例来源:origin: apache/servicecomb-pack

@Override
public void start() {
 Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown));
 try {
  server.start();
  server.awaitTermination();
 } catch (IOException e) {
  throw new IllegalStateException("Unable to start grpc server.", e);
 } catch (InterruptedException e) {
  LOG.error("grpc server was interrupted.", e);
  Thread.currentThread().interrupt();
 }
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

private void start(int port, BookstoreData data) throws IOException {
 server = ServerBuilder.forPort(port)
   .addService(new BookstoreService(data))
   .build().start();
}

代码示例来源:origin: ahmetaa/zemberek-nlp

public void start() throws Exception {
 Server server = ServerBuilder.forPort(port)
   .addService(new LanguageIdServiceImpl())
   .addService(new PreprocessingServiceImpl())
   .addService(new NormalizationServiceImpl(context))
   .addService(new MorphologyServiceImpl(context))
   .build()
   .start();
 Log.info("Zemberek grpc server started at port: " + port);
 server.awaitTermination();
}

相关文章