public class GrpcServerHost extends Object implements AutoCloseable, org.springframework.context.ApplicationContextAware
GrpcServerHost
configures a gRPC Server
with services obtained from the ApplicationContext
and manages that server's lifecycle. Services are discovered by finding BindableService
implementations that
are annotated with GrpcService
.Constructor and Description |
---|
GrpcServerHost(int port)
Construct a GrpcServerHost on a given port with a three second shutdown timeout.
|
GrpcServerHost(int port,
long shutdownWaitTimeInMillis)
Construct a GrpcServerHost on a given port with a given shutdown timeout.
|
GrpcServerHost(int port,
long shutdownWaitTimeInMillis,
GrpcServerFactory serverFactory)
Construct a GrpcServerHost on a given port with a given shutdown timeout and
GrpcServerFactory . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Shutdown the gRPC
Server when this object is closed. |
int |
getPort()
Returns the actual port of the running gRPC server.
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
start()
Start the gRPC
Server . |
public GrpcServerHost(int port)
port
- The port to listen onpublic GrpcServerHost(int port, long shutdownWaitTimeInMillis)
port
- The port to listen onshutdownWaitTimeInMillis
- Timeout for shutdownpublic GrpcServerHost(int port, long shutdownWaitTimeInMillis, GrpcServerFactory serverFactory)
GrpcServerFactory
.port
- The port to listen onshutdownWaitTimeInMillis
- Timeout for shutdownserverFactory
- A factory to construct gRPC Server
instancespublic void setApplicationContext(@Nonnull org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public final int getPort()
IllegalStateException
- if called either before the server has started or after it has stoppedpublic void start() throws IOException
Server
.IOException
- if unable to bind to server address or portIllegalStateException
- if any non-BindableService
classes are annotated with GrpcService
public void close() throws Exception
Server
when this object is closed.close
in interface AutoCloseable
Exception
Copyright © 2017. All rights reserved.