@Test public void testSetupShutdownHook() { when(config.getMultiLangDaemonConfiguration()).thenReturn(multiLangDaemonConfiguration); when(multiLangDaemonConfiguration.getShutdownGraceMillis()).thenReturn(1000L); doNothing().when(runtime).addShutdownHook(anyObject()); MultiLangDaemon.MultiLangRunner runner = new MultiLangDaemon.MultiLangRunner(scheduler); daemon.setupShutdownHook(runtime, runner, config); verify(multiLangDaemonConfiguration).getShutdownGraceMillis(); verify(runtime).addShutdownHook(anyObject()); }
void setupShutdownHook(final Runtime runtime, final MultiLangRunner runner, final MultiLangDaemonConfig config) { long shutdownGraceMillis = config.getMultiLangDaemonConfiguration().getShutdownGraceMillis(); runtime.addShutdownHook(new Thread(() -> { log.info("Process terminated, will initiate shutdown."); try { Future<Boolean> runnerFuture = runner.scheduler().startGracefulShutdown(); runnerFuture.get(shutdownGraceMillis, TimeUnit.MILLISECONDS); log.info("Process shutdown is complete."); } catch (InterruptedException | ExecutionException | TimeoutException e) { log.error("Encountered an error during shutdown.", e); } })); }
MultiLangDaemon { void setupShutdownHook(final Runtime runtime, final MultiLangRunner runner, final MultiLangDaemonConfig config) { long shutdownGraceMillis = config.getMultiLangDaemonConfiguration().getShutdownGraceMillis(); runtime.addShutdownHook(new Thread(() -> { log.info("Process terminated, will initiate shutdown."); try { Future<Boolean> runnerFuture = runner.scheduler().startGracefulShutdown(); runnerFuture.get(shutdownGraceMillis, TimeUnit.MILLISECONDS); log.info("Process shutdown is complete."); } catch (InterruptedException | ExecutionException | TimeoutException e) { log.error("Encountered an error during shutdown.", e); } })); } }
MultiLangDaemon { void setupShutdownHook(final Runtime runtime, final MultiLangRunner runner, final MultiLangDaemonConfig config) { long shutdownGraceMillis = config.getMultiLangDaemonConfiguration().getShutdownGraceMillis(); runtime.addShutdownHook(new Thread(() -> { log.info("Process terminated, will initiate shutdown."); try { Future<Boolean> runnerFuture = runner.scheduler().startGracefulShutdown(); runnerFuture.get(shutdownGraceMillis, TimeUnit.MILLISECONDS); log.info("Process shutdown is complete."); } catch (InterruptedException | ExecutionException | TimeoutException e) { log.error("Encountered an error during shutdown.", e); } })); }  }
MultiLangDaemon { void setupShutdownHook(final Runtime runtime, final MultiLangRunner runner, final MultiLangDaemonConfig config) { long shutdownGraceMillis = config.getMultiLangDaemonConfiguration().getShutdownGraceMillis(); runtime.addShutdownHook(new Thread(() -> { log.info("Process terminated, will initiate shutdown."); try { Future<Boolean> runnerFuture = runner.scheduler().startGracefulShutdown(); runnerFuture.get(shutdownGraceMillis, TimeUnit.MILLISECONDS); log.info("Process shutdown is complete."); } catch (InterruptedException | ExecutionException | TimeoutException e) { log.error("Encountered an error during shutdown.", e); } })); }  static void main(final String[] args); }
MultiLangDaemon { void setupShutdownHook(final Runtime runtime, final MultiLangRunner runner, final MultiLangDaemonConfig config) { long shutdownGraceMillis = config.getMultiLangDaemonConfiguration().getShutdownGraceMillis(); runtime.addShutdownHook(new Thread(() -> { log.info("Process terminated, will initiate shutdown."); try { Future<Boolean> runnerFuture = runner.scheduler().startGracefulShutdown(); runnerFuture.get(shutdownGraceMillis, TimeUnit.MILLISECONDS); log.info("Process shutdown is complete."); } catch (InterruptedException | ExecutionException | TimeoutException e) { log.error("Encountered an error during shutdown.", e); } })); }  static void main(final String[] args);  }