/** * Adds the user supplied function as a shutdown hook for cleanup. Also adds a function that sleeps for numSecs and then halts the * runtime to avoid any zombie process in case cleanup function hangs. */ public static void addShutdownHookWithDelayedForceKill(Runnable func, int numSecs) { final Thread sleepKill = new Thread(() -> { try { LOG.info("Halting after {} seconds", numSecs); Time.sleepSecs(numSecs); LOG.warn("Forcing Halt... {}", Utils.threadDump()); Runtime.getRuntime().halt(20); } catch (InterruptedException ie) { //Ignored/expected... } catch (Exception e) { LOG.warn("Exception in the ShutDownHook", e); } }); sleepKill.setDaemon(true); Thread wrappedFunc = new Thread(() -> { func.run(); sleepKill.interrupt(); }); Runtime.getRuntime().addShutdownHook(wrappedFunc); Runtime.getRuntime().addShutdownHook(sleepKill); }
Time.sleepSecs(3); return dynamicState.withState(MachineState.EMPTY);
LOG.info("WAITING... storm-id {}, {} <? {} {} {}", topoId, minReplicationCount, jarCount, codeCount, confCount); LOG.info("WAITING... {} <? {}", totalWaitTime, maxWaitTime); Time.sleepSecs(1); totalWaitTime++; if (!ConfigUtils.isLocalMode(topoConf)) {
@Override public void run() { try { Time.sleepSecs(1); Runtime.getRuntime().halt(20); } catch (Exception e) { LOG.warn("Exception in the ShutDownHook", e); } } };
public void run() { Object s; try { Callable fn = isFactory ? (Callable) afn.call() : afn; while ((s = fn.call()) instanceof Long) { Time.sleepSecs((Long) s); } } catch (Throwable t) { if (Utils.exceptionCauseIsInstanceOf( InterruptedException.class, t)) { LOG.info("Async loop interrupted!"); return; } LOG.error("Async loop died!", t); throw new RuntimeException(t); } } });