/** * Unregister the hook. */ public synchronized void unregister() { try { ShutdownHookManager.get().removeShutdownHook(this); } catch (IllegalStateException e) { LOG.info("Failed to unregister shutdown hook: {}", e, e); } }
/** * Register the service for shutdown with Hadoop's * {@link ShutdownHookManager}. * @param priority shutdown hook priority */ public synchronized void register(int priority) { unregister(); ShutdownHookManager.get().addShutdownHook(this, priority); }
/** * Adds a shutdown hook that tries to call {@link Closeable#close()} on the given argument * at JVM shutdown. This integrates with Hadoop's {@link ShutdownHookManager} in order to * better interact with Spark's usage of the same. * * @param closeable thing to close */ public static void closeAtShutdown(Closeable closeable) { if (SHUTDOWN_HOOK.addCloseable(closeable)) { try { // Spark uses SHUTDOWN_HOOK_PRIORITY + 30; this tries to execute earlier ShutdownHookManager.get().addShutdownHook(SHUTDOWN_HOOK, FileSystem.SHUTDOWN_HOOK_PRIORITY + 40); } catch (IllegalStateException ise) { log.warn("Can't close {} at shutdown since shutdown is in progress", closeable); } } }
ShutdownHookManager.get().addShutdownHook(FINALIZER, SHUTDOWN_HOOK_PRIORITY);
ShutdownHookManager.get().addShutdownHook( new Runnable() { @Override
if (ShutdownHookManager.get().isShutdownInProgress()) { LOG.error("Thread {} threw an error during shutdown: {}.", thread.toString(),
static JobHistoryServer launchJobHistoryServer(String[] args) { Thread. setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); StringUtils.startupShutdownMessage(JobHistoryServer.class, args, LOG); JobHistoryServer jobHistoryServer = null; try { jobHistoryServer = new JobHistoryServer(); ShutdownHookManager.get().addShutdownHook( new CompositeServiceShutdownHook(jobHistoryServer), SHUTDOWN_HOOK_PRIORITY); YarnConfiguration conf = new YarnConfiguration(new JobConf()); new GenericOptionsParser(conf, args); jobHistoryServer.init(conf); jobHistoryServer.start(); } catch (Throwable t) { LOG.fatal("Error starting JobHistoryServer", t); ExitUtil.terminate(-1, "Error starting JobHistoryServer"); } return jobHistoryServer; }
shutdownHookMgr = ShutdownHookManager.get();
static void startupShutdownMessage(Class<?> clazz, String[] args, final LogAdapter LOG) { final String hostname = NetUtils.getHostname(); final String classname = clazz.getSimpleName(); LOG.info(createStartupShutdownMessage(classname, hostname, args)); if (SystemUtils.IS_OS_UNIX) { try { SignalLogger.INSTANCE.register(LOG); } catch (Throwable t) { LOG.warn("failed to register any UNIX signal loggers: ", t); } } ShutdownHookManager.get().addShutdownHook( new Runnable() { @Override public void run() { LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{ "Shutting down " + classname + " at " + hostname})); } }, SHUTDOWN_HOOK_PRIORITY); }
void shutdown(BlockListAsLongs blocksListToPersist) { saveReplicas(blocksListToPersist); saveDfsUsed(); dfsUsedSaved = true; // Remove the shutdown hook to avoid any memory leak if (shutdownHook != null) { ShutdownHookManager.get().removeShutdownHook(shutdownHook); } if (dfsUsage instanceof CachingGetSpaceUsed) { IOUtils.cleanupWithLogger(LOG, ((CachingGetSpaceUsed) dfsUsage)); } }
private static void enableTracing(String hostname, String service, String spanReceivers, String zookeepers, long timeout, String zkPath, Map<String,String> properties) { Configuration conf = new Configuration(false); conf.set(Property.TRACE_SPAN_RECEIVERS.toString(), spanReceivers); // remaining properties will be parsed through an HTraceConfiguration by SpanReceivers setProperty(conf, TRACER_ZK_HOST, zookeepers); setProperty(conf, TRACER_ZK_TIMEOUT, (int) timeout); setProperty(conf, TRACER_ZK_PATH, zkPath); for (Entry<String,String> property : properties.entrySet()) { setProperty(conf, property.getKey().substring(Property.TRACE_SPAN_RECEIVER_PREFIX.getKey().length()), property.getValue()); } if (hostname != null) { setProperty(conf, TRACE_HOST_PROPERTY, hostname); } if (service != null) { setProperty(conf, TRACE_SERVICE_PROPERTY, service); } org.apache.htrace.Trace.setProcessId(service); ShutdownHookManager.get().addShutdownHook(() -> { Trace.off(); closeReceivers(); }, 0); loadSpanReceivers(conf); }
ShutdownHookManager.get().addShutdownHook(shutdownHook, SHUTDOWN_HOOK_PRIORITY);
/** * Add shutdown hook that runs before the FileSystem cache shutdown happens. * * @param hook code to execute during shutdown * @param priority Priority over the FileSystem.SHUTDOWN_HOOK_PRIORITY */ public static void addShutdownHookWithPriority(Runnable hook, int priority) { ShutdownHookManager.get().addShutdownHook(hook, FileSystem.SHUTDOWN_HOOK_PRIORITY + priority); } }
public synchronized void unregister() { if (hook != null) { try { ShutdownHookManager.get().removeShutdownHook(hook); } catch (IllegalStateException e) { LOG.info("Failed to unregister shutdown hook: {}", e, e); } hook = null; } }
@Override public synchronized void delete() throws IOException { stopped = true; if (ShutdownHookManager.get().isShutdownInProgress()) return; String fileName = masterName.replaceAll(":", "_"); fs.delete(new Path(activePath, fileName), false); fs.delete(new Path(activePath, HAConstants.ACTIVE_LOCK_FILE), false); fs.delete(new Path(backupPath, fileName), false); }
@Override public synchronized void delete() throws IOException { stopped = true; if (ShutdownHookManager.get().isShutdownInProgress()) return; String fileName = masterName.replaceAll(":", "_"); fs.delete(new Path(activePath, fileName), false); fs.delete(new Path(activePath, HAConstants.ACTIVE_LOCK_FILE), false); fs.delete(new Path(backupPath, fileName), false); }
public synchronized void unregister() { if (hook != null) { try { ShutdownHookManager.get().removeShutdownHook(hook); } catch (IllegalStateException e) { LOG.info("Failed to unregister shutdown hook: {}", e, e); } hook = null; } }
public void register(int priority) { unregister(); hook = this; ShutdownHookManager.get().addShutdownHook(hook, priority); }
public void register(int priority) { unregister(); hook = this; ShutdownHookManager.get().addShutdownHook(hook, priority); }