Class GracefulShutdownService

java.lang.Object
com.google.common.util.concurrent.AbstractIdleService
org.graylog2.system.shutdown.GracefulShutdownService
All Implemented Interfaces:
com.google.common.util.concurrent.Service

@Singleton public class GracefulShutdownService extends com.google.common.util.concurrent.AbstractIdleService
A service that participates in the Graylog server graceful shutdown.

Services can implement GracefulShutdownHook and register themselves with this service to make sure they get shut down properly on server shutdown. During shutdown the registered hooks will be called in no particular order.

Make sure to use unregister(GracefulShutdownHook) if a registered service is shutting down before the server shutdown to avoid leaking service instances in the GracefulShutdownService. See GracefulShutdownHook for an example.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service

    com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Register a shutdown hook with the service.
    protected void
     
    protected void
     
    void
    Remove a previously registered shutdown hook from the service.

    Methods inherited from class com.google.common.util.concurrent.AbstractIdleService

    addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, startAsync, state, stopAsync, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • GracefulShutdownService

      public GracefulShutdownService()
  • Method Details

    • startUp

      protected void startUp()
      Specified by:
      startUp in class com.google.common.util.concurrent.AbstractIdleService
    • shutDown

      protected void shutDown()
      Specified by:
      shutDown in class com.google.common.util.concurrent.AbstractIdleService
    • register

      public void register(GracefulShutdownHook shutdownHook)
      Register a shutdown hook with the service.
      Parameters:
      shutdownHook - a class that implements GracefulShutdownHook
      Throws:
      IllegalStateException - if the server shutdown is already in progress and the hook cannot be registered
      NullPointerException - if the shutdown hook argument is null
    • unregister

      public void unregister(GracefulShutdownHook shutdownHook)
      Remove a previously registered shutdown hook from the service.

      This needs to be called if a registered service will be stopped before the server shuts down.

      Parameters:
      shutdownHook - a class that implements GracefulShutdownHook
      Throws:
      IllegalStateException - if the server shutdown is already in progress and the hook cannot be unregistered
      NullPointerException - if the shutdown hook argument is null