Package org.graylog2.system.shutdown
Interface GracefulShutdownHook
- All Known Implementing Classes:
JobWorkerPool
public interface GracefulShutdownHook
Services can implement this to participate in a graceful shutdown of the server.
A service can register itself with the GracefulShutdownService
like this:
class MyService implements GracefulShutdownHook {
private final GracefulShutdownService shutdownService;
@Inject
public MyService(GracefulShutdownService shutdownService) {
this.shutdownService = shutdownService;
}
// This will be executed by the GracefulShutdownService on server shutdown
@Override
void doGracefulShutdown() throws Exception {
runShutdownTasks();
}
public void start() {
// Let the GracefulShutdownService know about this service
this.shutdownService.register(this);
}
// This will be executed by some service manager when this service is stopped
public void stop() {
// Remove this service from the GracefulShutdownService because it's stopped before server shutdown and
// we don't need any graceful shutdown for it anymore
this.shutdownService.unregister(this);
runShutdownTasks();
}
private void runShutdownTasks() {
// Run the actual shutdown tasks for the service here
}
}
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Execute shutdown tasks for the service that implements this interface.
-
Method Details
-
doGracefulShutdown
Execute shutdown tasks for the service that implements this interface.Warning:
- This method is called from another thread so the class that implements
GracefulShutdownHook
must be thread-safe. - The server shutdown is waiting for this method call to complete. Blocking this method will block the server shutdown!
- Throws:
Exception
- This method is called from another thread so the class that implements
-