/** * 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; }
/** * 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(); } }
@After public void tearDown() throws Exception { testServer.shutdownNow().awaitTermination(); }
@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(); } }
/** Await termination on the main thread since the grpc library uses daemon threads. */ private void blockUntilShutdown() throws InterruptedException { if (server != null) { server.awaitTermination(); } }
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(); }
/** * 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()); }
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(); })); } }
private void stop() { if (server != null) { server.shutdown(); } }
@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; } });
/** * @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(); }
@After public void tearDown() { if (server != null && !server.isTerminated()) { server.shutdown(); } }
/** Shuts down the in-memory service. */ public void shutdownNow() { server.shutdownNow(); } }
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(); }
/** Await termination on the main thread since the grpc library uses daemon threads. */ private void blockUntilShutdown() throws InterruptedException { if (server != null) { server.awaitTermination(); } }
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(); }
/** * 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()); }
@After public void tearDown() throws Exception { testServer.shutdownNow().awaitTermination(); testChannel.shutdown(); }
@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(); })); } }