Search in sources :

Example 1 with Daemon

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()));
}
Also used : Daemon(org.apache.ratis.util.Daemon) Timer(java.util.Timer) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

Timer (java.util.Timer)1 ExecutorService (java.util.concurrent.ExecutorService)1 Daemon (org.apache.ratis.util.Daemon)1