/** * This method will configure a worker EventLoopGroup and a Channel for use by a client. It will * try to use the correct SocketChannel for the provided workerGroup. * * @param workerGroup uses EventLoopGroup in the ClientChannelConfiguration * @return ClientChannelConfiguration */ public static ClientChannelConfiguration clientConfig(EventLoopGroup workerGroup) { EventLoopGroup parent = workerGroup; if (parent instanceof EventLoop) { parent = ((EventLoop) workerGroup).parent(); } Class<? extends Channel> channelClass; if (parent instanceof EpollEventLoopGroup) { channelClass = EpollSocketChannel.class; } else if (parent instanceof NioEventLoopGroup) { channelClass = NioSocketChannel.class; } else { throw new RuntimeException("Unsupported EventLoopGroup " + workerGroup.getClass()); } return new ClientChannelConfiguration(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); }
private ClientConnectionManager subjectFactory(boolean shouldSucceed) { ClientChannelConfiguration channelConfiguration = new ClientChannelConfiguration(new NioEventLoopGroup(), NioSocketChannel.class); File configFile; if (shouldSucceed) { configFile = new File("src/test/resources/ClientConnectionManagerTestSucceed.conf"); } else { configFile = new File("src/test/resources/ClientConnectionManagerTestFail.conf"); } Config config = ConfigFactory.parseFile(configFile); ClientConfig clientConfig = ClientConfig.from(config); ClientState clientState = new ClientState(channelConfiguration, clientConfig); ClientChannelInitializer clientChannelInit = new ClientChannelInitializer(clientState, () -> new HollowChannelHandler(), null); return new ClientConnectionManager(clientState, clientChannelInit); }