Class ServiceShutdownHook

java.lang.Object
org.apache.hadoop.service.launcher.ServiceShutdownHook
All Implemented Interfaces:
Runnable

@Private @Unstable public class ServiceShutdownHook extends Object implements Runnable
JVM Shutdown hook for Service which will stop the Service gracefully in case of JVM shutdown. This hook uses a weak reference to the service, and when shut down, calls Service.stop() if the reference is valid.
  • Constructor Details

    • ServiceShutdownHook

      public ServiceShutdownHook(Service service)
      Create an instance.
      Parameters:
      service - the service
  • Method Details

    • register

      public void register(int priority)
      Register the service for shutdown with Hadoop's ShutdownHookManager.
      Parameters:
      priority - shutdown hook priority
    • unregister

      public void unregister()
      Unregister the hook.
    • run

      public void run()
      Shutdown handler. Query the service hook reference -if it is still valid the Service.stop() operation is invoked.
      Specified by:
      run in interface Runnable
    • shutdown

      protected boolean shutdown()
      Shutdown operation.

      Subclasses may extend it, but it is primarily made available for testing.

      Returns:
      true if the service was stopped and no exception was raised.