Interface ShutdownManager


public interface ShutdownManager
Allows services to register to take action as part of an orderly shutdown procedure
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    Request that all registered services perform an orderly shutdown.
  • Method Details

    • register

      void 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. 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 the StoppableService.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 any StoppableServices, the StoppableService.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 StoppableServices has been called and has returned (whether normally or by throwing an exception)