/** * initialization per Storm configuration */ @SuppressWarnings("rawtypes") public void prepare(Map stormConf) { this.stormConf = stormConf; int maxWorkers = Utils.getInt(stormConf.get(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS)); ThreadFactory bossFactory = new NettyRenameThreadFactory(MetricDef.NETTY_CLI + "boss"); ThreadFactory workerFactory = new NettyRenameThreadFactory(MetricDef.NETTY_CLI + "worker"); if (maxWorkers > 0) { clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory), maxWorkers); } else { clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory)); } reconnector = new ReconnectRunnable(); new AsyncLoopThread(reconnector, true, Thread.MIN_PRIORITY, true); }
); final ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));
/** * Creates a NettyTransceiver, and attempts to connect to the given address. * @param addr the address to connect to. * @param connectTimeoutMillis maximum amount of time to wait for connection * establishment in milliseconds, or null to use * {@link #DEFAULT_CONNECTION_TIMEOUT_MILLIS}. * @throws IOException if an error occurs connecting to the given address. */ public NettyTransceiver(InetSocketAddress addr, Long connectTimeoutMillis) throws IOException { this(addr, new NioClientSocketChannelFactory( Executors.newCachedThreadPool(new NettyTransceiverThreadFactory( "Avro " + NettyTransceiver.class.getSimpleName() + " Boss")), Executors.newCachedThreadPool(new NettyTransceiverThreadFactory( "Avro " + NettyTransceiver.class.getSimpleName() + " I/O Worker"))), connectTimeoutMillis); }
public ServerInfoService() { pool = Executors.newCachedThreadPool(); factory = new NioClientSocketChannelFactory(pool, pool, 1, 1); bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new InfoRequestPipelineFactory()); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); }
logger.info("Callback pool created"); client = new HBaseClient(asyncClientConfig, new NioClientSocketChannelFactory(sinkCallbackPool, sinkCallbackPool));
this.channelFactory = new NioClientSocketChannelFactory(boss, worker);
socketChannelFactory = new NioClientSocketChannelFactory( bossExecutor, workerExecutor, maxIoWorkers); } else { socketChannelFactory = new NioClientSocketChannelFactory( bossExecutor, workerExecutor);
static interface ZooKeeperClientHandler<T> { T handle(ZooKeeperClient zkc) throws IOException; }
hibernationSettings.get().setHibernationAllowed(false); factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new TerasologyClientPipelineFactory(this));
/** * Initialize; cached threadpool is safe as it is releasing resources automatically if idle */ public synchronized void init() { channelFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); datagramChannelFactory = new NioDatagramChannelFactory( Executors.newCachedThreadPool()); timer = new HashedWheelTimer(); }
private static synchronized ClientSocketChannelFactory getFactory() { if (factory == null) { factory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor); } return factory; }
@Override protected ChannelFactory createChannelFactory() { if (executor == null) { executor = Executors.newCachedThreadPool(); instanceManagedExecutor = true; } ChannelFactory factory = new NioClientSocketChannelFactory(executor, executor); return factory; }
int numWorkers = config.getIoThreadMultiplier() * Runtime.getRuntime().availableProcessors(); LOGGER.trace("Number of application's worker threads is {}", numWorkers); socketChannelFactory = new NioClientSocketChannelFactory(e, config.executorService(), numWorkers); allowReleaseSocketChannelFactory = true;
/** * Initialize; cached threadpool is safe as it is releasing resources automatically if idle */ public synchronized void init() { channelFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); datagramChannelFactory = new NioDatagramChannelFactory( Executors.newCachedThreadPool()); timer = new HashedWheelTimer(); }
@Override public NioClientSocketChannelFactory get() { return new NioClientSocketChannelFactory(ManagedExecutors.getExecutor(), ManagedExecutors.getExecutor(), Runtime.getRuntime().availableProcessors()); } });
public static void main(String args[]) { // Client服务启动器 ClientBootstrap bootstrap = new ClientBootstrap( new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // 设置一个处理服务端消息和各种消息事件的类(Handler) bootstrap.setPipelineFactory(() -> Channels.pipeline(new HelloClientHandler())); // 连接到本地的8000端口的服务端 bootstrap.connect(new InetSocketAddress("127.0.0.1", 8000)); }
public void init() { // initialize the connection factory, such as we need create connection pools here. // Configure the client. bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Set up the pipeline factory. bootstrap.setPipelineFactory(new DorisClentNettyPipelineFactory()); bootstrap.setOption("connectTimeoutMillis", CONNECT_TIME_OUT_MILLIS); bootstrap.setOption("tcpNoDelay", true); }
public NettyTransport(SenderConfigurer config, ExecutorService executor) { client = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); client.setOption("connectTimeoutMillis", 10000); client.setOption("keepAlive", true); client.setPipelineFactory(new HttpClientPipelineFactory(true)); channels = new DefaultChannelGroup(); }
public TcpClient(final ChannelGroup channelGroup, final Executor executor) { this.channelGroup = channelGroup; channelFactory = new NioClientSocketChannelFactory(executor, executor); channelBufferFactory = new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN); bootstrap = new ClientBootstrap(channelFactory); bootstrap.setOption("bufferFactory", channelBufferFactory); setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_DURATION, DEFAULT_CONNECTION_TIMEOUT_UNIT); setKeepAlive(DEFAULT_KEEP_ALIVE); namedChannelHandlers = Lists.newArrayList(); }
private static ClientBootstrap getBootstrap(final Executor executor, final ClientOptions options) { final ChannelFactory factory = new NioClientSocketChannelFactory(executor, executor); final ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new ClientPipelineFactory(options)); bootstrap.setOption("tcpNoDelay" , true); bootstrap.setOption("keepAlive", true); return bootstrap; }