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
  • 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:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • stop

      public void stop(Runnable callback)
      Specified by:
      stop in interface org.springframework.context.SmartLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • getPort

      public int getPort()
    • getFactory

      public GrpcServerFactory getFactory()
      Gets the server factory used to create the server.
      Returns:
      the server factory to create the server
    • createAndStartGrpcServer

      protected void createAndStartGrpcServer() throws IOException
      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.