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);
}
}
Aggregations