private void waitForDown() { while (process != null && process.isAlive()) { try { process.waitFor(); } catch (InterruptedException ignored) { // ignore, waiting for process to stop Thread.currentThread().interrupt(); } } }
@Override public void run() { try { while (process.isAlive()) { refreshState(); Thread.sleep(watcherDelayMs); } } catch (InterruptedException e) { // request to stop watching process. To avoid unexpected behaviors // the process is stopped. Thread.currentThread().interrupt(); stopForcibly(); } } }
void refreshState() { if (process.isAlive()) { if (!operational.get() && process.isOperational()) { operational.set(true); eventListeners.forEach(l -> l.onProcessEvent(processId, ProcessEventListener.Type.OPERATIONAL)); } if (process.askedForRestart()) { process.acknowledgeAskForRestart(); eventListeners.forEach(l -> l.onProcessEvent(processId, ProcessEventListener.Type.ASK_FOR_RESTART)); } } else { stopForcibly(); } }
/** * Sends kill signal and awaits termination. No guarantee that process is gracefully terminated (=shutdown hooks * executed). It depends on OS. */ public void stop(long timeout, TimeUnit timeoutUnit) { if (lifecycle.tryToMoveTo(Lifecycle.State.STOPPING)) { stopGracefully(timeout, timeoutUnit); if (process != null && process.isAlive()) { LOG.info("{} failed to stop in a timely fashion. Killing it.", processId.getKey()); } // enforce stop and clean-up even if process has been gracefully stopped stopForcibly(); } else { // already stopping or stopped waitForDown(); } }
private void waitForDown() { while (process != null && process.isAlive()) { try { process.waitFor(); } catch (InterruptedException ignored) { // ignore, waiting for process to stop Thread.currentThread().interrupt(); } } }
@Override public void run() { try { while (process.isAlive()) { refreshState(); Thread.sleep(watcherDelayMs); } } catch (InterruptedException e) { // request to stop watching process. To avoid unexpected behaviors // the process is stopped. Thread.currentThread().interrupt(); stopForcibly(); } } }
void refreshState() { if (process.isAlive()) { if (!operational.get() && process.isOperational()) { operational.set(true); eventListeners.forEach(l -> l.onProcessEvent(processId, ProcessEventListener.Type.OPERATIONAL)); } if (process.askedForRestart()) { process.acknowledgeAskForRestart(); eventListeners.forEach(l -> l.onProcessEvent(processId, ProcessEventListener.Type.ASK_FOR_RESTART)); } } else { stopForcibly(); } }
/** * Sends kill signal and awaits termination. No guarantee that process is gracefully terminated (=shutdown hooks * executed). It depends on OS. */ public void stop(long timeout, TimeUnit timeoutUnit) { if (lifecycle.tryToMoveTo(Lifecycle.State.STOPPING)) { stopGracefully(timeout, timeoutUnit); if (process != null && process.isAlive()) { LOG.info("{} failed to stop in a timely fashion. Killing it.", processId.getKey()); } // enforce stop and clean-up even if process has been gracefully stopped stopForcibly(); } else { // already stopping or stopped waitForDown(); } }