use of org.apache.ratis.util.Daemon in project incubator-ratis by apache.
the class MiniRaftCluster method shutdown.
public void shutdown() {
LOG.info("************************************************************** ");
LOG.info("*** ");
LOG.info("*** Stopping " + JavaUtils.getClassSimpleName(getClass()));
LOG.info("*** ");
LOG.info("************************************************************** ");
LOG.info(printServers());
// TODO: classes like RaftLog may throw uncaught exception during shutdown (e.g. write after close)
ExitUtils.setTerminateOnUncaughtException(false);
final ExecutorService executor = Executors.newFixedThreadPool(servers.size(), Daemon::new);
getServers().forEach(proxy -> executor.submit(() -> JavaUtils.runAsUnchecked(proxy::close)));
try {
executor.shutdown();
// just wait for a few seconds
executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOG.warn("shutdown interrupted", e);
Thread.currentThread().interrupt();
}
Optional.ofNullable(timer.get()).ifPresent(Timer::cancel);
ExitUtils.assertNotTerminated();
LOG.info("{} shutdown completed", JavaUtils.getClassSimpleName(getClass()));
}
Aggregations