io.grpc.Server类的使用及代码示例

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

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

Server介绍

[英]Server for listening for and dispatching incoming calls. It is not expected to be implemented by application code or interceptors.
[中]用于监听和发送来电的服务器。它预计不会由应用程序代码或拦截器实现。

代码示例

代码示例来源: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: Alluxio/alluxio

/**
 * Shuts down the server.
 *
 * @return {@code true} if the server was successfully terminated.
 * @throws InterruptedException
 */
public boolean shutdown() {
 mServer.shutdown();
 try {
  return mServer.awaitTermination(mServerShutdownTimeoutMs, TimeUnit.MILLISECONDS);
 } catch (InterruptedException ie) {
  Thread.currentThread().interrupt();
  return false;
 } finally {
  mServer.shutdownNow();
 }
}

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

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

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

@After
public void tearDown() throws Exception {
 testServer.shutdownNow().awaitTermination();
}

代码示例来源: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: google/rejoiner

/** Await termination on the main thread since the grpc library uses daemon threads. */
private void blockUntilShutdown() throws InterruptedException {
 if (server != null) {
  server.awaitTermination();
 }
}

代码示例来源:origin: com.thoughtworks.gauge/gauge-java

private static void startGRPCServer(MessageDispatcher messageDispatcher) throws IOException, InterruptedException {
  Server server;
  LspServer lspServer = new LspServer(messageDispatcher);
  server = ServerBuilder.forPort(0).addService(lspServer).build();
  lspServer.addServer(server);
  server.start();
  int port = server.getPort();
  System.out.println("Listening on port:" + port);
  server.awaitTermination();
}

代码示例来源:origin: apache/incubator-nemo

/**
 * This method starts a {@link Server} with random port, and register the ip address with the local sender id
 * to the name server.
 *
 * @throws Exception when any network exception occur during starting procedure
 */
void start() throws Exception {
 // 1. Bind to random port
 this.server = ServerBuilder.forPort(0)
   .addService(new MessageService())
   .build();
 // 2. Start the server
 server.start();
 Runtime.getRuntime().addShutdownHook(new Thread(() -> GrpcMessageServer.this.server.shutdown()));
 // 3. Register the bounded ip address to name server
 registerToNameServer(server.getPort());
}

代码示例来源:origin: cd.connect.features/connect-feature-service

public GrpcServer(FeatureRpcResource featureRpcResource, int port) throws IOException {

    log.info("starting grpc server on port {}", port);

    server = ServerBuilder.forPort(port)
      .addService(featureRpcResource).build().start();

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
      log.info("Shutting down grpc server on port {}" + port);
      server.shutdown();
    }));
  }
}

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

private void stop() {
 if (server != null) {
  server.shutdown();
 }
}

代码示例来源:origin: glowroot/glowroot

@Override
  public @Nullable Void call() throws Exception {
    server.shutdown();
    if (!server.awaitTermination(10, SECONDS)) {
      throw new IllegalStateException("Could not terminate channel");
    }
    executor.shutdown();
    if (!executor.awaitTermination(10, SECONDS)) {
      throw new IllegalStateException("Could not terminate executor");
    }
    if (!bossEventLoopGroup.shutdownGracefully(0, 0, SECONDS).await(10, SECONDS)) {
      throw new IllegalStateException(
          "Could not terminate gRPC boss event loop group");
    }
    if (!workerEventLoopGroup.shutdownGracefully(0, 0, SECONDS).await(10, SECONDS)) {
      throw new IllegalStateException(
          "Could not terminate gRPC worker event loop group");
    }
    socketHeartbeat.close();
    return null;
  }
});

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

/**
 * @return the port that server is bound to, or null if the server is not bound to an address yet.
 */
public int getBindPort() {
 return mServer.getPort();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@After
public void tearDown() {
 if (server != null && !server.isTerminated()) {
  server.shutdown();
 }
}

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

/** Shuts down the in-memory service. */
 public void shutdownNow() {
  server.shutdownNow();
 }
}

代码示例来源: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();
}

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

/** Await termination on the main thread since the grpc library uses daemon threads. */
private void blockUntilShutdown() throws InterruptedException {
 if (server != null) {
  server.awaitTermination();
 }
}

代码示例来源:origin: getgauge/gauge-java

private static void startGRPCServer(MessageDispatcher messageDispatcher) throws IOException, InterruptedException {
  Server server;
  LspServer lspServer = new LspServer(messageDispatcher);
  server = ServerBuilder.forPort(0).addService(lspServer).build();
  lspServer.addServer(server);
  server.start();
  int port = server.getPort();
  System.out.println("Listening on port:" + port);
  server.awaitTermination();
}

代码示例来源:origin: org.apache.nemo/nemo-runtime-common

/**
 * This method starts a {@link Server} with random port, and register the ip address with the local sender id
 * to the name server.
 *
 * @throws Exception when any network exception occur during starting procedure
 */
void start() throws Exception {
 // 1. Bind to random port
 this.server = ServerBuilder.forPort(0)
   .addService(new MessageService())
   .build();
 // 2. Start the server
 server.start();
 Runtime.getRuntime().addShutdownHook(new Thread(() -> GrpcMessageServer.this.server.shutdown()));
 // 3. Register the bounded ip address to name server
 registerToNameServer(server.getPort());
}

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

@After
public void tearDown() throws Exception {
 testServer.shutdownNow().awaitTermination();
 testChannel.shutdown();
}

代码示例来源:origin: cd.connect.features/connect-feature-service

@PostConfigured
  public void init() throws IOException {
    log.info("starting grpc server on port {}", port);

    server = ServerBuilder.forPort(port)
      .addService(featureRpcResource).build().start();

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
      log.info("Shutting down grpc server on port {}" + port);
      server.shutdown();
    }));
  }
}

相关文章