use of info.xiancloud.core.distribution.LocalNodeManager in project xian by happyyangyuan.
the class ShutdownStrategy method executeShutdownHooks.
private static boolean executeShutdownHooks() {
final AtomicBoolean success = new AtomicBoolean(true);
Map<String, Runnable> allShutdowns = new LinkedHashMap<String, Runnable>() {
/*必须使用有序map */
{
put(ReadySignal.class.getSimpleName() + ".destroy", ReadySignal.singleton::destroy);
if (ApplicationDiscovery.singleton != null)
put(ApplicationDiscovery.class.getSimpleName() + ".unregister", ApplicationDiscovery.singleton::selfUnregister);
if (GroupDiscovery.singleton != null)
put(GroupDiscovery.class.getSimpleName() + ".unregister", GroupDiscovery.singleton::selfUnregister);
if (UnitDiscovery.singleton != null)
put(UnitDiscovery.class.getSimpleName() + ".unregister", UnitDiscovery.singleton::selfUnregister);
for (ShutdownHook hook : shutdowns) {
put(hook.getClass().getSimpleName(), hook::shutdown);
}
put(ThreadPoolManager.class.getSimpleName() + ".destroy", () -> ThreadPoolManager.destroy(9 * 1000));
LOG.debug("注意顺序:业务线程池销毁完毕代表池内任务线程都已执行完毕,这样方可以继续后续销毁rpc程序。");
if (RpcClient.singleton != null)
put(RpcClient.class.getSimpleName() + ".destroy", RpcClient.singleton::destroy);
if (RpcServer.singleton != null)
put(RpcServer.class.getSimpleName() + ".destroy", RpcServer.singleton::destroy);
put(LocalNodeManager.class.getSimpleName() + ".destroy", LocalNodeManager::destroy);
if (IMqPubClient.singleton != null)
put(IMqPubClient.singleton.getClass().getSimpleName() + ".destroy", IMqPubClient.singleton::destroy);
if (IMqConsumerClient.singleton != null && IMqConsumerClient.singleton != IMqPubClient.singleton)
put(IMqConsumerClient.singleton.getClass().getSimpleName() + ".destroy", IMqConsumerClient.singleton::destroy);
if (UnitDiscovery.singleton != null)
put(UnitDiscovery.class.getSimpleName() + ".destroy", UnitDiscovery.singleton::destroy);
if (GroupDiscovery.singleton != null)
put(GroupDiscovery.class.getSimpleName() + ".destroy", GroupDiscovery.singleton::destroy);
if (ApplicationDiscovery.singleton != null)
put(ApplicationDiscovery.class.getSimpleName() + ".destroy", ApplicationDiscovery.singleton::destroy);
if (IResAware.singleton != null)
put(IResAware.class.getSimpleName() + ".destroy", IResAware.singleton::destroy);
if (IRegistry.singleton != null)
put(IRegistry.class.getSimpleName() + ".destroy", IRegistry.singleton::destroy);
}
};
allShutdowns.forEach((name, runnable) -> {
if (!execWithTimeout(10 * 1000, name, runnable)) {
success.set(false);
}
});
return success.get();
}
Aggregations