當前位置: 首頁>>代碼示例>>Java>>正文


Java Server.awaitTermination方法代碼示例

本文整理匯總了Java中io.grpc.Server.awaitTermination方法的典型用法代碼示例。如果您正苦於以下問題:Java Server.awaitTermination方法的具體用法?Java Server.awaitTermination怎麽用?Java Server.awaitTermination使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.grpc.Server的用法示例。


在下文中一共展示了Server.awaitTermination方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: close

import io.grpc.Server; //導入方法依賴的package包/類
/**
 * Shutdown the gRPC {@link Server} when this object is closed.
 */
@Override
public void close() throws Exception {
    final Server server = server();

    if (server != null) {
        server.shutdown();

        try {
            // TODO: Maybe we should catch the InterruptedException from this?
            server.awaitTermination(shutdownWaitTimeInMillis, TimeUnit.MILLISECONDS);
        } finally {
            server.shutdownNow();

            this.server = null;
        }
    }
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:21,代碼來源:GrpcServerHost.java

示例2: shutdownGracefully

import io.grpc.Server; //導入方法依賴的package包/類
/**
 * Attempt to {@link Server#shutdown()} the {@link Server} gracefully. If the max wait time is exceeded, give up and
 * perform a hard {@link Server#shutdownNow()}.
 *
 * @param server the server to be shutdown
 * @param timeout the max amount of time to wait for graceful shutdown to occur
 * @param unit the time unit denominating the shutdown timeout
 * @return the given server
 * @throws InterruptedException if waiting for termination is interrupted
 */
public static Server shutdownGracefully(Server server, long timeout, TimeUnit unit) throws InterruptedException {
    Preconditions.checkNotNull(server, "server");
    Preconditions.checkArgument(timeout > 0, "timeout must be greater than 0");
    Preconditions.checkNotNull(unit, "unit");

    server.shutdown();

    try {
        server.awaitTermination(timeout, unit);
    } finally {
        server.shutdownNow();
    }

    return server;
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:26,代碼來源:Servers.java

示例3: serverRunsAndRespondsCorrectly

import io.grpc.Server; //導入方法依賴的package包/類
@Test
public void serverRunsAndRespondsCorrectly() throws ExecutionException,
        IOException,
        InterruptedException,
        TimeoutException {
    final String name = UUID.randomUUID().toString();

    Server server = ServerBuilder.forPort(9999)
            .addService(new GreeterImpl())
            .build();

    server.start();

    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", server.getPort())
            .usePlaintext(true)
            .build();

    GreeterGrpc8.GreeterCompletableFutureStub stub = GreeterGrpc8.newCompletableFutureStub(channel);

    CompletableFuture<HelloResponse> response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());

    await().atMost(3, TimeUnit.SECONDS).until(() -> response.isDone() && response.get().getMessage().contains(name));

    channel.shutdown();
    channel.awaitTermination(1, TimeUnit.MINUTES);
    channel.shutdownNow();

    server.shutdown();
    server.awaitTermination(1, TimeUnit.MINUTES);
    server.shutdownNow();
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:32,代碼來源:CompletableFutureEndToEndTest.java

示例4: main

import io.grpc.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
	
	Server server=ServerBuilder.forPort(Config.getLocalPortProvider())
					.addService(new AddService())
					.build();
	try {
		server.start();
		
		ProviderBootstrap.init();
		
		server.awaitTermination();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
開發者ID:laddcn,項目名稱:grpcx,代碼行數:18,代碼來源:Provider.java

示例5: main

import io.grpc.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException, InterruptedException {
  RxMetricsServiceGrpc.MetricsServiceImplBase service = new RxMetricsServiceGrpc.MetricsServiceImplBase() {

    @Override
    public Single<Streaming.Average> collect(Flowable<Streaming.Metric> request) {
      return request.map(m -> m.getMetric())
          .map(m -> new State(m, 1))
          .reduce((a, b) -> new State(a.sum + b.sum, a.count + b.count))
          .map(s -> Streaming.Average.newBuilder().setVal(s.sum / s.count).build())
          .toSingle();
    }
  };

  Server server = ServerBuilder.forPort(8080)
      .addService(service)
      .build();

  server.start();
  server.awaitTermination();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:21,代碼來源:RxMetricsServer.java

示例6: run

import io.grpc.Server; //導入方法依賴的package包/類
void run() throws Exception {
  // Port 0 means that the operating system will pick an available port to use.
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      responseObserver.onError(Status.INTERNAL
          .withDescription("Eggplant Xerxes Crybaby Overbite Narwhal").asRuntimeException());
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext(true).build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:24,代碼來源:ErrorHandlingClient.java

示例7: run

import io.grpc.Server; //導入方法依賴的package包/類
void run() throws Exception {
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      Metadata trailers = new Metadata();
      trailers.put(DEBUG_INFO_TRAILER_KEY, DEBUG_INFO);
      responseObserver.onError(Status.INTERNAL.withDescription(DEBUG_DESC)
          .asRuntimeException(trailers));
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext(true).build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:25,代碼來源:DetailErrorSample.java

示例8: main

import io.grpc.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException, IOException {

        // Build server
        Server server = ServerBuilder.forPort(SERVER_PORT)
                .addService(new ChatServiceImpl())
                .build();

        // Start server
        System.out.println("Starting server on port " + SERVER_PORT);
        server.start();

        // Keep it running
        System.out.println("Server started!");
        server.awaitTermination();
    }
 
開發者ID:meteatamel,項目名稱:grpc-samples-java,代碼行數:16,代碼來源:ChatServer.java

示例9: main

import io.grpc.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException, InterruptedException {

        // Build server
        Server server = ServerBuilder.forPort(SERVER_PORT)
                .addService(new GreetingServiceImpl())
                .build();

        // Start server
        System.out.println("Starting GreeterServer on port " + SERVER_PORT);
        server.start();

        // Keep it running
        System.out.println("GreeterServer started!");
        server.awaitTermination();
    }
 
開發者ID:meteatamel,項目名稱:grpc-samples-java,代碼行數:16,代碼來源:GreeterServer.java

示例10: main

import io.grpc.Server; //導入方法依賴的package包/類
static public void main(String [] args) throws IOException, InterruptedException {
  Server server = ServerBuilder.forPort(8080)
      .addService(new GreetingServiceImpl()).build();

  System.out.println("Starting server...");
  server.start();
  System.out.println("Server started!");
  server.awaitTermination();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:10,代碼來源:MyGrpcServer.java

示例11: main

import io.grpc.Server; //導入方法依賴的package包/類
static public void main(String[] args) throws IOException, InterruptedException {

    Server server = ServerBuilder.forPort(8080)
        .addService(new EchoServiceImpl()).build();

    System.out.println("Starting server...");
    server.start();
    System.out.println("Server started!");
    server.awaitTermination();
  }
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:11,代碼來源:EchoServer.java

示例12: main

import io.grpc.Server; //導入方法依賴的package包/類
static public void main(String [] args) throws IOException, InterruptedException {
  Brave brave = Constant.brave("greeting-service");
  Server greetingServer = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new GreetingServiceImpl(),
          new BraveGrpcServerInterceptor(brave),
          MonitoringServerInterceptor.create(Configuration.allMetrics())))
      .build();
  greetingServer.start();

  System.out.println("Server started!");
  greetingServer.awaitTermination();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:13,代碼來源:GreetingServer.java

示例13: main

import io.grpc.Server; //導入方法依賴的package包/類
static public void main(String[] args) throws IOException, InterruptedException {
  UnknownStatusDescriptionInterceptor unknownStatusDescriptionInterceptor = new UnknownStatusDescriptionInterceptor(Arrays.asList(
      IllegalArgumentException.class
  ));
  Server server = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new ErrorServiceImpl(), unknownStatusDescriptionInterceptor))
      .build();

  System.out.println("Starting server...");
  server.start();
  System.out.println("Server started!");
  server.awaitTermination();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:14,代碼來源:ErrorGrpcServer.java

示例14: main

import io.grpc.Server; //導入方法依賴的package包/類
static public void main(String [] args) throws IOException, InterruptedException {
  JwtServerInterceptor jwtInterceptor = new JwtServerInterceptor(Constant.JWT_SECRET);

  Server greetingServer = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new GreetingServiceImpl(), jwtInterceptor, new TraceIdServerInterceptor()))
      .build();
  greetingServer.start();

  System.out.println("Server started!");
  greetingServer.awaitTermination();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:12,代碼來源:GreetingServer.java

示例15: main

import io.grpc.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  Options opts = parseOptionsOrDie(args, new Options());
  Connection hbase = hbase(opts);
  ExecutorService service = Executors.newFixedThreadPool(opts.nthreads);

  FunbaseGrpcService grpcService = new FunbaseGrpcService(hbase, service);
  Server server = ServerBuilder.forPort(opts.port)
      .addService(grpcService)
      .build();
  LOG.info("hbase grpc is taking the stage on 0.0.0.0:" + opts.port);
  server.start();
  // run forever.
  server.awaitTermination();
}
 
開發者ID:christian-lefty,項目名稱:funbase,代碼行數:15,代碼來源:Funbase.java


注:本文中的io.grpc.Server.awaitTermination方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。