@Override public void run() { try { process.waitFor(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // stop watching process } stopForcibly(); } }
@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(); } }
@Test public void stopForcibly_stops_the_process_without_graceful_request_for_stop() { SQProcess underTest = SQProcess.builder(A_PROCESS_ID).build(); try (TestProcess testProcess = new TestProcess()) { underTest.start(() -> testProcess); underTest.stopForcibly(); assertThat(underTest.getState()).isEqualTo(Lifecycle.State.STOPPED); assertThat(testProcess.askedForStop).isFalse(); assertThat(testProcess.destroyedForcibly).isTrue(); // second execution of stopForcibly does nothing. It's still stopped. underTest.stopForcibly(); assertThat(underTest.getState()).isEqualTo(Lifecycle.State.STOPPED); } }
@Override public void run() { try { process.waitFor(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // stop watching process } stopForcibly(); } }
@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(); } }