Search in sources :

Example 1 with GracefulShutdownAwareService

use of com.hazelcast.internal.services.GracefulShutdownAwareService in project hazelcast by hazelcast.

the class Node method callGracefulShutdownAwareServices.

private void callGracefulShutdownAwareServices(final int maxWaitSeconds) {
    ExecutorService executor = nodeEngine.getExecutionService().getExecutor(GRACEFUL_SHUTDOWN_EXECUTOR_NAME);
    Collection<GracefulShutdownAwareService> services = nodeEngine.getServices(GracefulShutdownAwareService.class);
    Collection<Future> futures = new ArrayList<Future>(services.size());
    for (final GracefulShutdownAwareService service : services) {
        Future future = executor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    boolean success = service.onShutdown(maxWaitSeconds, TimeUnit.SECONDS);
                    if (success) {
                        logger.fine("Graceful shutdown completed for " + service);
                    } else {
                        logger.warning("Graceful shutdown failed for " + service);
                    }
                } catch (Throwable e) {
                    logger.severe("Graceful shutdown failed for " + service, e);
                }
            }

            @Override
            public String toString() {
                return "Graceful shutdown task for service [" + service.toString() + "]";
            }
        });
        futures.add(future);
    }
    try {
        waitWithDeadline(futures, maxWaitSeconds, TimeUnit.SECONDS, FutureUtil.RETHROW_EVERYTHING);
    } catch (Exception e) {
        logger.warning(e);
    }
}
Also used : GracefulShutdownAwareService(com.hazelcast.internal.services.GracefulShutdownAwareService) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future)

Aggregations

GracefulShutdownAwareService (com.hazelcast.internal.services.GracefulShutdownAwareService)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1