Search in sources :

Example 1 with LocalNodeManager

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();
}
Also used : ApplicationDiscovery(info.xiancloud.core.distribution.service_discovery.ApplicationDiscovery) IResAware(info.xiancloud.core.distribution.res.IResAware) ShutdownHook(info.xiancloud.core.init.shutdown.ShutdownHook) LocalNodeManager(info.xiancloud.core.distribution.LocalNodeManager) LinkedHashMap(java.util.LinkedHashMap) UnitDiscovery(info.xiancloud.core.distribution.service_discovery.UnitDiscovery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMqConsumerClient(info.xiancloud.core.mq.IMqConsumerClient) GroupDiscovery(info.xiancloud.core.distribution.service_discovery.GroupDiscovery) RpcServer(info.xiancloud.core.rpc.RpcServer) IMqPubClient(info.xiancloud.core.mq.IMqPubClient) IRegistry(info.xiancloud.core.distribution.IRegistry) RpcClient(info.xiancloud.core.rpc.RpcClient)

Aggregations

IRegistry (info.xiancloud.core.distribution.IRegistry)1 LocalNodeManager (info.xiancloud.core.distribution.LocalNodeManager)1 IResAware (info.xiancloud.core.distribution.res.IResAware)1 ApplicationDiscovery (info.xiancloud.core.distribution.service_discovery.ApplicationDiscovery)1 GroupDiscovery (info.xiancloud.core.distribution.service_discovery.GroupDiscovery)1 UnitDiscovery (info.xiancloud.core.distribution.service_discovery.UnitDiscovery)1 ShutdownHook (info.xiancloud.core.init.shutdown.ShutdownHook)1 IMqConsumerClient (info.xiancloud.core.mq.IMqConsumerClient)1 IMqPubClient (info.xiancloud.core.mq.IMqPubClient)1 RpcClient (info.xiancloud.core.rpc.RpcClient)1 RpcServer (info.xiancloud.core.rpc.RpcServer)1 LinkedHashMap (java.util.LinkedHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1