Class GrpcServerLifecycle
java.lang.Object
org.springframework.grpc.server.lifecycle.GrpcServerLifecycle
- All Implemented Interfaces:
org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
public class GrpcServerLifecycle
extends Object
implements org.springframework.context.SmartLifecycle
Lifecycle bean that automatically starts and stops the grpc server.
- Author:
- Michael ([email protected]), Dave Syer
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionGrpcServerLifecycle(GrpcServerFactory factory, Duration shutdownGracePeriod, org.springframework.context.ApplicationEventPublisher eventPublisher) Creates a new GrpcServerLifecycle. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCreates and starts the grpc server.Gets the server factory used to create the server.intgetPhase()intgetPort()booleanbooleanvoidstart()voidstop()voidprotected voidInitiates an orderly shutdown of the grpc server and releases the references to the server.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable
-
Constructor Details
-
GrpcServerLifecycle
public GrpcServerLifecycle(GrpcServerFactory factory, Duration shutdownGracePeriod, org.springframework.context.ApplicationEventPublisher eventPublisher) Creates a new GrpcServerLifecycle.- Parameters:
factory- The server factory to use.shutdownGracePeriod- The time to wait for the server to gracefully shut down.eventPublisher- The event publisher to use.
-
-
Method Details
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
getPort
public int getPort() -
getFactory
Gets the server factory used to create the server.- Returns:
- the server factory to create the server
-
createAndStartGrpcServer
Creates and starts the grpc server.- Throws:
IOException- If the server is unable to bind the port.
-
stopAndReleaseGrpcServer
protected void stopAndReleaseGrpcServer()Initiates an orderly shutdown of the grpc server and releases the references to the server. This call waits for the server to be completely shut down.
-