Interface ShutdownManager
public interface ShutdownManager
Allows services to register to take action as part of an orderly shutdown procedure
-
Method Summary
Modifier and TypeMethodDescriptionvoid
register
(StoppableService service) Registers a service to be notified when the system shuts down
The ShutdownManager will hold a strong reference to this object, preventing it from being garbage collected until shutdown.void
shutdown()
Request that all registered services perform an orderly shutdown.
-
Method Details
-
register
Registers a service to be notified when the system shuts down
The ShutdownManager will hold a strong reference to this object, preventing it from being garbage collected until shutdown. After shutdown the ShutdownManager will release this reference- Parameters:
service
- the service to register (must not be null)- Throws:
IllegalArgumentException
- if the service provided is null, or if this ShutdownManager has already been shutdown
-
shutdown
void shutdown()Request that all registered services perform an orderly shutdown. Specifically, the ShutdownManager call theStoppableService.shutdown()
method on each registered service in the reverse registration order (that is, the most recently registered service becomes the first to be shutdown).Before the
StoppableService.shutdown()
method is called on anyStoppableService
s, theStoppableService.preShutdown()
method will be called on all services in the same order, allowing them to prepare for the shutdown if they wish.Services are given an unlimited amount of time to complete their shutdown (although taking a long time to shutdown is not advisable - a user may decide the service has crashed and kill the process).
The shutdown method returns when the shutdown method on each of the
StoppableService
s has been called and has returned (whether normally or by throwing an exception)
-