/** * Create a new instance. * * @param bossExecutor * the {@link Executor} which will execute the boss threads * @param bossCount * the number of boss threads * @param workerExecutor * the {@link Executor} which will execute the I/O worker threads * @param workerCount * the maximum number of I/O worker threads */ public NioServerSocketChannelFactory( Executor bossExecutor, int bossCount, Executor workerExecutor, int workerCount) { this(bossExecutor, bossCount, new NioWorkerPool(workerExecutor, workerCount)); }
/** * Creates a new instance. * * @param bossExecutor * the {@link Executor} which will execute the boss thread * @param workerExecutor * the {@link Executor} which will execute the worker threads * @param bossCount * the maximum number of boss threads * @param workerCount * the maximum number of I/O worker threads */ public NioClientSocketChannelFactory( Executor bossExecutor, Executor workerExecutor, int bossCount, int workerCount) { this(bossExecutor, bossCount, new NioWorkerPool(workerExecutor, workerCount)); }
); final NioWorkerPool workerPool = new NioWorkerPool( Executors.newCachedThreadPool( new ThreadFactoryBuilder()
/** * Creates a new instance. * * @param bossExecutor * the {@link Executor} which will execute the boss thread * @param workerExecutor * the {@link Executor} which will execute the worker threads * @param bossCount * the maximum number of boss threads * @param workerCount * the maximum number of I/O worker threads */ public NioClientSocketChannelFactory( Executor bossExecutor, Executor workerExecutor, int bossCount, int workerCount) { this(bossExecutor, bossCount, new NioWorkerPool(workerExecutor, workerCount)); }
/** * Create a new instance. * * @param bossExecutor * the {@link Executor} which will execute the boss threads * @param bossCount * the number of boss threads * @param workerExecutor * the {@link Executor} which will execute the I/O worker threads * @param workerCount * the maximum number of I/O worker threads */ public NioServerSocketChannelFactory( Executor bossExecutor, int bossCount, Executor workerExecutor, int workerCount) { this(bossExecutor, bossCount, new NioWorkerPool(workerExecutor, workerCount)); }
public NioWorkerPool getWorkerPool() { //This is a correct implementation of double-checked locking idiom NioWorkerPool result = workerPool; if (result == null) { synchronized (this) { result = workerPool; if (result == null) { ExecutorService corePool = Executors.newFixedThreadPool(corePoolSize, new VertxThreadFactory("vert.x-core-thread-")); workerPool = result = new NioWorkerPool(corePool, corePoolSize); } } } return result; }
public NettyIoPool(String name, NettyIoPoolConfig config) { this.name = checkNotNull(name, "name is null"); checkNotNull(config, "config is null"); String prefix = "netty-client-" + name + "-io-"; this.hashedWheelTimer = new HashedWheelTimer(new ThreadFactoryBuilder().setNameFormat(prefix + "timer-%s").setDaemon(true).build()); // Give netty infinite thread "sources" for worker and boss. // Netty will name the threads and will size the pool appropriately this.bossExecutor = newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat(prefix + "boss-%s").setDaemon(true).build()); this.workerExecutor = newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat(prefix + "worker-%s").setDaemon(true).build()); this.bossPool = new NioClientBossPool(bossExecutor, config.getIoBossThreads(), hashedWheelTimer, ThreadNameDeterminer.CURRENT); this.workerPool = new NioWorkerPool(workerExecutor, config.getIoWorkerThreads(), ThreadNameDeterminer.CURRENT); }
/** * Creates a new worker pool. */ public WorkerPool build() { int count = workerCount > 0 ? workerCount : NettyHelper.DEFAULT_IO_THREADS; workerPool = new NioWorkerPool(Executors.newCachedThreadPool(), count, new CamelNettyThreadNameDeterminer(pattern, name)); return workerPool; } }
NioWorkerPool workerPool = new NioWorkerPool(Executors.newCachedThreadPool(), 20, new ThreadNameDeterminer() { @Override public String determineThreadName(String currentThreadName,String proposedThreadName) throws Exception {
public void start() { bossExecutor = nettyServerConfig.getBossExecutor(); int bossThreadCount = nettyServerConfig.getBossThreadCount(); ioWorkerExecutor = nettyServerConfig.getWorkerExecutor(); int ioWorkerThreadCount = nettyServerConfig.getWorkerThreadCount(); channelFactory = new NioServerSocketChannelFactory(new NioServerBossPool(bossExecutor, bossThreadCount, ThreadNameDeterminer.CURRENT), new NioWorkerPool(ioWorkerExecutor, ioWorkerThreadCount, ThreadNameDeterminer.CURRENT)); start(channelFactory); }
/** * Returns a {@link ServerBootstrap} instance for the named transport. */ @Override public synchronized ServerBootstrap newServerBootstrap() throws Exception { ServerSocketChannelFactory serverChannelFactory = this.serverChannelFactory; if (serverChannelFactory == null) { Executor bossExecutor = executorServiceFactory.newExecutorService("boss.server"); NioServerBossPool bossPool = new NioServerBossPool(bossExecutor, 1); Executor workerExecutor = executorServiceFactory.newExecutorService("worker.server"); NioWorkerPool workerPool = new NioWorkerPool(workerExecutor, 1); serverChannelFactory = new NioServerSocketChannelFactory(bossPool, workerPool); // unshared channelFactories.add(serverChannelFactory); } return new ServerBootstrap(serverChannelFactory) { @Override public ChannelFuture bindAsync(SocketAddress localAddress) { return super.bindAsync(toInetSocketAddress(localAddress)); } }; }
); final NioWorkerPool workerPool = new NioWorkerPool( Executors.newCachedThreadPool( new ThreadFactoryBuilder()
); final NioWorkerPool workerPool = new NioWorkerPool( Executors.newCachedThreadPool( new ThreadFactoryBuilder()
); final NioWorkerPool workerPool = new NioWorkerPool( Executors.newCachedThreadPool( new ThreadFactoryBuilder()
config.getInt("hbase.workers.size") : Runtime.getRuntime().availableProcessors() * 2; final NioWorkerPool worker_pool = new NioWorkerPool(executor, num_workers, new WorkerThreadNamer()); return new NioClientSocketChannelFactory(boss_pool, worker_pool);
); final NioWorkerPool workerPool = new NioWorkerPool( Executors.newCachedThreadPool( new ThreadFactoryBuilder()
/** * Returns a {@link ClientBootstrap} instance for the named transport. */ @Override public synchronized ClientBootstrap newClientBootstrap() throws Exception { ClientSocketChannelFactory clientChannelFactory = this.clientChannelFactory; if (clientChannelFactory == null) { Executor bossExecutor = executorServiceFactory.newExecutorService("boss.client"); NioClientBossPool bossPool = new NioClientBossPool(bossExecutor, 1); Executor workerExecutor = executorServiceFactory.newExecutorService("worker.client"); NioWorkerPool workerPool = new NioWorkerPool(workerExecutor, 1); clientChannelFactory = new NioClientSocketChannelFactory(bossPool, workerPool); // unshared channelFactories.add(clientChannelFactory); } return new ClientBootstrap(clientChannelFactory) { @Override public ChannelFuture connect(final SocketAddress localAddress, final SocketAddress remoteAddress) { final InetSocketAddress localChannelAddress = toInetSocketAddress((ChannelAddress) localAddress); final InetSocketAddress remoteChannelAddress = toInetSocketAddress((ChannelAddress) remoteAddress); return super.connect(localChannelAddress, remoteChannelAddress); } }; }
serverBossPool = new NioServerBossPool(ioExecutorService, 1); clientBossPool = new NioClientBossPool(ioExecutorService, 1); workerPool = new NioWorkerPool(ioExecutorService, 3);
public NiftyClient(NettyClientConfig nettyClientConfig) { this.nettyClientConfig = nettyClientConfig; this.timer = nettyClientConfig.getTimer(); this.bossExecutor = nettyClientConfig.getBossExecutor(); this.workerExecutor = nettyClientConfig.getWorkerExecutor(); this.defaultSocksProxyAddress = nettyClientConfig.getDefaultSocksProxyAddress(); int bossThreadCount = nettyClientConfig.getBossThreadCount(); int workerThreadCount = nettyClientConfig.getWorkerThreadCount(); NioWorkerPool workerPool = new NioWorkerPool(workerExecutor, workerThreadCount, ThreadNameDeterminer.CURRENT); NioClientBossPool bossPool = new NioClientBossPool(bossExecutor, bossThreadCount, timer, ThreadNameDeterminer.CURRENT); this.channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool); }
Executors.newCachedThreadPool(daemonThreadFactory(settings, TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX)), bossCount, new NioWorkerPool(Executors.newCachedThreadPool( daemonThreadFactory(settings, TRANSPORT_CLIENT_WORKER_THREAD_NAME_PREFIX)), workerCount), new HashedWheelTimer(daemonThreadFactory(settings, "transport_client_timer"))));