Package org.graylog2.system.shutdown
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
register
(GracefulShutdownHook shutdownHook) Register a shutdown hook with the service.protected void
shutDown()
protected void
startUp()
void
unregister
(GracefulShutdownHook shutdownHook) 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
-
Constructor Details
-
GracefulShutdownService
public GracefulShutdownService()
-
-
Method Details
-
startUp
protected void startUp()- Specified by:
startUp
in classcom.google.common.util.concurrent.AbstractIdleService
-
shutDown
protected void shutDown()- Specified by:
shutDown
in classcom.google.common.util.concurrent.AbstractIdleService
-
register
Register a shutdown hook with the service.- Parameters:
shutdownHook
- a class that implementsGracefulShutdownHook
- Throws:
IllegalStateException
- if the server shutdown is already in progress and the hook cannot be registeredNullPointerException
- if the shutdown hook argument is null
-
unregister
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 implementsGracefulShutdownHook
- Throws:
IllegalStateException
- if the server shutdown is already in progress and the hook cannot be unregisteredNullPointerException
- if the shutdown hook argument is null
-