EventLoopGroup cacheNioServerLoops() { EventLoopGroup eventLoopGroup = serverLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = new NioEventLoopGroup(workerCount, threadFactory(this, "nio")); if (!serverLoops.compareAndSet(null, newEventLoopGroup)) { newEventLoopGroup.shutdownGracefully(); } eventLoopGroup = cacheNioServerLoops(); } return eventLoopGroup; }
EventLoopGroup cacheNioServerLoops() { EventLoopGroup eventLoopGroup = serverLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = new NioEventLoopGroup(workerCount, threadFactory(this, "nio")); if (!serverLoops.compareAndSet(null, newEventLoopGroup)) { newEventLoopGroup.shutdownGracefully(); } eventLoopGroup = cacheNioServerLoops(); } return eventLoopGroup; }
EventLoopGroup cacheNioClientLoops() { EventLoopGroup eventLoopGroup = clientLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = LoopResources.colocate(cacheNioServerLoops()); if (!clientLoops.compareAndSet(null, newEventLoopGroup)) { // Do not shutdown newEventLoopGroup as this will shutdown the server loops } eventLoopGroup = cacheNioClientLoops(); } return eventLoopGroup; }
EventLoopGroup cacheNioSelectLoops() { if (serverSelectLoops == serverLoops) { return cacheNioServerLoops(); } EventLoopGroup eventLoopGroup = serverSelectLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = new NioEventLoopGroup(selectCount, threadFactory(this, "select-nio")); if (!serverSelectLoops.compareAndSet(null, newEventLoopGroup)) { newEventLoopGroup.shutdownGracefully(); } eventLoopGroup = cacheNioSelectLoops(); } return eventLoopGroup; }
EventLoopGroup cacheNioClientLoops() { EventLoopGroup eventLoopGroup = clientLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = LoopResources.colocate(cacheNioServerLoops()); if (!clientLoops.compareAndSet(null, newEventLoopGroup)) { // Do not shutdown newEventLoopGroup as this will shutdown the server loops } eventLoopGroup = cacheNioClientLoops(); } return eventLoopGroup; }
EventLoopGroup cacheNioSelectLoops() { if (serverSelectLoops == serverLoops) { return cacheNioServerLoops(); } EventLoopGroup eventLoopGroup = serverSelectLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = new NioEventLoopGroup(selectCount, threadFactory(this, "select-nio")); if (!serverSelectLoops.compareAndSet(null, newEventLoopGroup)) { newEventLoopGroup.shutdownGracefully(); } eventLoopGroup = cacheNioSelectLoops(); } return eventLoopGroup; }
@Override public EventLoopGroup onServer(boolean useNative) { if (useNative && preferNative()) { return cacheNativeServerLoops(); } return cacheNioServerLoops(); }
@Override public EventLoopGroup onServer(boolean useNative) { if (useNative && preferNative()) { return cacheNativeServerLoops(); } return cacheNioServerLoops(); }