Java Code Examples for io.grpc.Server#isTerminated()
The following examples show how to use
io.grpc.Server#isTerminated() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntrospectionAutoConfiguration.java From genie with Apache License 2.0 | 6 votes |
/** * Provide a {@link GenieWebRpcInfo} bean if one hasn't already been defined. * * @param server The gRPC {@link Server} instance. Must not be {@link Server#isShutdown()} or * {@link Server#isTerminated()}. Must be able to get the port the server is listening on. * @return A {@link GenieWebRpcInfo} instance * @throws IllegalStateException When an instance can't be created */ @Bean @ConditionalOnMissingBean( { GenieWebRpcInfo.class } ) public GenieWebRpcInfo genieWebRpcInfo(final Server server) throws IllegalStateException { if (server.isShutdown() || server.isTerminated()) { throw new IllegalStateException("gRPC server is already shut down. Can't start."); } else { final int port = GRpcServerUtils.startServer(server); if (port < 1) { throw new IllegalStateException("gRPC server started on illegal port: " + port); } return new GenieWebRpcInfo(port); } }
Example 2
Source File: StreamsRegistryConfiguration.java From apicurio-registry with Apache License 2.0 | 4 votes |
@Produces @ApplicationScoped public Lifecycle storageGrpcServer( HostInfo storageLocalHost, KeyValueStoreGrpc.KeyValueStoreImplBase storageStoreGrpcImpl, AsyncBiFunctionServiceGrpc.AsyncBiFunctionServiceImplBase storageAsyncBiFunctionServiceGrpcImpl ) { UnknownStatusDescriptionInterceptor unknownStatusDescriptionInterceptor = new UnknownStatusDescriptionInterceptor( ImmutableMap.of( IllegalArgumentException.class, Status.INVALID_ARGUMENT, IllegalStateException.class, Status.FAILED_PRECONDITION, InvalidStateStoreException.class, Status.FAILED_PRECONDITION, Throwable.class, Status.INTERNAL ) ); Server server = ServerBuilder .forPort(storageLocalHost.port()) .addService( ServerInterceptors.intercept( storageStoreGrpcImpl, unknownStatusDescriptionInterceptor ) ) .addService( ServerInterceptors.intercept( storageAsyncBiFunctionServiceGrpcImpl, unknownStatusDescriptionInterceptor ) ) .build(); return new Lifecycle() { @Override public void start() { try { server.start(); } catch (IOException e) { throw new UncheckedIOException(e); } } @Override public void stop() { ConcurrentUtil .<Server>consumer(Server::awaitTermination) .accept(server.shutdown()); } @Override public boolean isRunning() { return !(server.isShutdown() || server.isTerminated()); } }; }