/** * This method will configure a boss EventLoopGroup, a worker EventLoopGroup and a ServerChannel * for use by a server. It will try to use Epoll if it's available. * * @param bossThreads spawn in number of boss threads * @param bossNameFormat uses String to the boss thread names * @param workerThreads spawn int number of worker threads * @param workerNameFormat uses String to set the worker thread names * @return ClientChannelConfiguration */ public static ServerChannelConfiguration serverConfig( int bossThreads, String bossNameFormat, int workerThreads, String workerNameFormat) { EventLoopGroup bossGroup; EventLoopGroup workerGroup; Class<? extends ServerChannel> channelClass; if (Epoll.isAvailable()) { bossGroup = new EpollEventLoopGroup(bossThreads, threadFactory(bossNameFormat)); workerGroup = new EpollEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = EpollServerSocketChannel.class; } else { bossGroup = new NioEventLoopGroup(bossThreads, threadFactory(bossNameFormat)); workerGroup = new NioEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = NioServerSocketChannel.class; } return new ServerChannelConfiguration(bossGroup, workerGroup, channelClass); } }
/** * This method will configure a worker EventLoopGroup and a Channel for use by a client. It will * try to use Epoll if it's available. * * @param workerThreads spawn int number of worker threads * @param workerNameFormat uses String to set the worker thread names * @return ClientChannelConfiguration */ public static ClientChannelConfiguration clientConfig( int workerThreads, String workerNameFormat) { EventLoopGroup workerGroup; Class<? extends Channel> channelClass; if (Epoll.isAvailable()) { workerGroup = new EpollEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = EpollSocketChannel.class; } else { workerGroup = new NioEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = NioSocketChannel.class; } return new ClientChannelConfiguration(workerGroup, channelClass); }