@Override public boolean isShutdown() { return delegate.isShutdown(); }
@Override public boolean isRunning() { return !group.isShutdown(); }
@Override public boolean isShutdown() { return delegate.isShutdown(); }
/** * 如果是这个线程是最后一个使用者,直接删除 * * @param eventLoopGroup 线程池 * @return 是否被删除 */ private static boolean closeEventLoopGroupIfNoRef(EventLoopGroup eventLoopGroup) { if (eventLoopGroup != null && refCounter.get(eventLoopGroup).decrementAndGet() <= 0) { if (!eventLoopGroup.isShuttingDown() && !eventLoopGroup.isShutdown()) { eventLoopGroup.shutdownGracefully(); } refCounter.remove(eventLoopGroup); return true; } return false; }
/** * 如果是这个线程是最后一个使用者,直接删除 * * @param eventLoopGroup 线程池 * @return 是否被删除 */ private static boolean closeEventLoopGroupIfNoRef(EventLoopGroup eventLoopGroup) { if (eventLoopGroup != null && refCounter.get(eventLoopGroup).decrementAndGet() <= 0) { if (!eventLoopGroup.isShuttingDown() && !eventLoopGroup.isShutdown()) { eventLoopGroup.shutdownGracefully(); } refCounter.remove(eventLoopGroup); return true; } return false; }
/** * 获取客户端IO线程池 * * @return 客户端IO线程池 */ public synchronized static EventLoopGroup getClientIOEventLoopGroup() { if (clientIOEventLoopGroup != null && clientIOEventLoopGroup.isShutdown()) { clientIOEventLoopGroup = null; } if (clientIOEventLoopGroup == null) { int clientIoThreads = getIntValue(TRANSPORT_CLIENT_IO_THREADS); int threads = clientIoThreads > 0 ? clientIoThreads : // 用户配置 Math.max(4, SystemInfo.getCpuCores() + 1); // 默认cpu+1,至少4个 NamedThreadFactory threadName = new NamedThreadFactory("CLI-IO", true); boolean useEpoll = getBooleanValue(TRANSPORT_USE_EPOLL); clientIOEventLoopGroup = useEpoll ? new EpollEventLoopGroup(threads, threadName) : new NioEventLoopGroup(threads, threadName); refCounter.putIfAbsent(clientIOEventLoopGroup, new AtomicInteger(0)); // SelectStrategyFactory 未设置 } refCounter.get(clientIOEventLoopGroup).incrementAndGet(); return clientIOEventLoopGroup; }
/** * 关闭客户端IO线程池 */ public synchronized static void closeClientIOEventGroup() { if (clientIOEventLoopGroup != null) { AtomicInteger ref = refCounter.get(clientIOEventLoopGroup); if (ref.decrementAndGet() <= 0) { if (!clientIOEventLoopGroup.isShutdown() && !clientIOEventLoopGroup.isShuttingDown()) { clientIOEventLoopGroup.shutdownGracefully(); } refCounter.remove(clientIOEventLoopGroup); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Closing Client EventLoopGroup, ref : 0"); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Client EventLoopGroup still has ref : {}", ref.get()); } } } clientIOEventLoopGroup = null; }
/** * 获取客户端IO线程池 * * @return 客户端IO线程池 */ public synchronized static EventLoopGroup getClientIOEventLoopGroup() { if (clientIOEventLoopGroup != null && clientIOEventLoopGroup.isShutdown()) { clientIOEventLoopGroup = null; } if (clientIOEventLoopGroup == null) { int clientIoThreads = getIntValue(TRANSPORT_CLIENT_IO_THREADS); int threads = clientIoThreads > 0 ? clientIoThreads : // 用户配置 Math.max(4, SystemInfo.getCpuCores() + 1); // 默认cpu+1,至少4个 NamedThreadFactory threadName = new NamedThreadFactory("CLI-IO", true); boolean useEpoll = getBooleanValue(TRANSPORT_USE_EPOLL); clientIOEventLoopGroup = useEpoll ? new EpollEventLoopGroup(threads, threadName) : new NioEventLoopGroup(threads, threadName); refCounter.putIfAbsent(clientIOEventLoopGroup, new AtomicInteger(0)); // SelectStrategyFactory 未设置 } refCounter.get(clientIOEventLoopGroup).incrementAndGet(); return clientIOEventLoopGroup; }
/** * 关闭客户端IO线程池 */ public synchronized static void closeClientIOEventGroup() { if (clientIOEventLoopGroup != null) { AtomicInteger ref = refCounter.get(clientIOEventLoopGroup); if (ref.decrementAndGet() <= 0) { if (!clientIOEventLoopGroup.isShutdown() && !clientIOEventLoopGroup.isShuttingDown()) { clientIOEventLoopGroup.shutdownGracefully(); } refCounter.remove(clientIOEventLoopGroup); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Closing Client EventLoopGroup, ref : 0"); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Client EventLoopGroup still has ref : {}", ref.get()); } } } clientIOEventLoopGroup = null; }
@Override public boolean isShutdown() { return eventLoopGroup.isShutdown(); }
@Override public boolean isShutdown() { return delegate.isShutdown(); }
@Override public boolean isShutdown() { return delegate.isShutdown(); }
@Override public boolean isShutdown() { return eventLoopGroup.isShutdown(); }
@Override public boolean isShutdown() { return eventLoopGroup.isShutdown(); }
/** * 关闭客户端所有链接和资源 */ public static void stop() { if (group != null && !group.isShutdown()) { group.shutdownGracefully(); } } }
public static void shutdown() { CONSOLE_LOGGER.warn("initiating shutdown....."); leaderElector.stop(); if(!bossGroup.isShutdown()) { bossGroup.shutdownGracefully(); } if(!workerGroup.isShutdown()){ workerGroup.shutdownGracefully(); } CONSOLE_LOGGER.warn("shutdown successful.....exiting.."); System.exit(0); }
private static void shutdown(EventLoopGroup loopGroup) { if (loopGroup != null && !(loopGroup.isShutdown() || loopGroup.isShuttingDown())) { try { loopGroup.shutdownGracefully(); } catch (final Exception e) { logger.error("Error while closing", e); } } } }
public void waitUntilShutdown() { while (!eventLoopGroup.isShutdown() && !eventLoopGroup.isShuttingDown()) { try { Thread.sleep(1000); } catch (InterruptedException e) { try { close(); } catch (IOException e1) { } break; } } }
private void checkGroup() { if (group == null || group.isShuttingDown() || group.isShutdown()) { restart(); } }
private void checkGroup() { if (group == null || group.isShuttingDown() || group.isShutdown()) { restart(); } }