Class ServiceShutdownHook
java.lang.Object
org.apache.hadoop.service.launcher.ServiceShutdownHook
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidregister(int priority) Register the service for shutdown with Hadoop'sShutdownHookManager.voidrun()Shutdown handler.protected booleanshutdown()Shutdown operation.voidUnregister the hook.
-
Constructor Details
-
ServiceShutdownHook
Create an instance.- Parameters:
service- the service
-
-
Method Details
-
register
public void register(int priority) Register the service for shutdown with Hadoop'sShutdownHookManager.- 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 theService.stop()operation is invoked. -
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.
-