ShutdownHookManager { @InterfaceAudience.Private @VisibleForTesting static long getShutdownTimeout(Configuration conf) { long duration = conf.getTimeDuration( SERVICE_SHUTDOWN_TIMEOUT, SERVICE_SHUTDOWN_TIMEOUT_DEFAULT, TIME_UNIT_DEFAULT); if (duration < TIMEOUT_MINIMUM) { duration = TIMEOUT_MINIMUM; } return duration; } private  ShutdownHookManager(); @InterfaceAudience.Public static ShutdownHookManager get(); @InterfaceAudience.Public @InterfaceStability.Stable void addShutdownHook(Runnable shutdownHook, int priority); @InterfaceAudience.Public @InterfaceStability.Stable void addShutdownHook(Runnable shutdownHook, int priority, long timeout,
      TimeUnit unit); @InterfaceAudience.Public @InterfaceStability.Stable boolean removeShutdownHook(Runnable shutdownHook); @InterfaceAudience.Public @InterfaceStability.Stable boolean hasShutdownHook(Runnable shutdownHook); @InterfaceAudience.Public @InterfaceStability.Stable boolean isShutdownInProgress(); @InterfaceAudience.Public @InterfaceStability.Stable void clearShutdownHooks(); static final long TIMEOUT_MINIMUM; static final TimeUnit TIME_UNIT_DEFAULT; }
@Test public void testShutdownTimeoutConfiguration() throws Throwable { Configuration conf = new Configuration(); long shutdownTimeout = 5; conf.setTimeDuration(SERVICE_SHUTDOWN_TIMEOUT, shutdownTimeout, TimeUnit.SECONDS); assertEquals(SERVICE_SHUTDOWN_TIMEOUT, shutdownTimeout, ShutdownHookManager.getShutdownTimeout(conf)); }
@Test public void testShutdownTimeoutBadConfiguration() throws Throwable { Configuration conf = new Configuration(); long shutdownTimeout = 50; conf.setTimeDuration(SERVICE_SHUTDOWN_TIMEOUT, shutdownTimeout, TimeUnit.NANOSECONDS); assertEquals(SERVICE_SHUTDOWN_TIMEOUT, ShutdownHookManager.TIMEOUT_MINIMUM, ShutdownHookManager.getShutdownTimeout(conf)); }