Refine search
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); }
callTimeoutPool = Executors.newCachedThreadPool( new TransceiverThreadFactory("Flume Avro RPC Client Call Invoker")); NioClientSocketChannelFactory socketChannelFactory = null; Executors.newCachedThreadPool(new TransceiverThreadFactory( "Avro " + NettyTransceiver.class.getSimpleName() + " Boss")); ExecutorService workerExecutor = Executors.newCachedThreadPool(new TransceiverThreadFactory( "Avro " + NettyTransceiver.class.getSimpleName() + " I/O Worker")); socketChannelFactory = new NioClientSocketChannelFactory( bossExecutor, workerExecutor, maxIoWorkers); } else { socketChannelFactory = new NioClientSocketChannelFactory( bossExecutor, workerExecutor); socketChannelFactory.releaseExternalResources();
/** * 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); }
/** * Create a server for this cluster. * @param cluster */ public GossipServer(GossipCluster cluster) { this.cluster = cluster; serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newFixedThreadPool(1), Executors.newFixedThreadPool(8))); serverBootstrap.setPipelineFactory(new GossipPipelineFactory(cluster,false)); clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newFixedThreadPool(1), Executors.newFixedThreadPool(8))); clientBootstrap.setPipelineFactory(new GossipPipelineFactory(cluster,true)); }
factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()), Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), tsoExecutorThreads); bootstrap = new ClientBootstrap(factory); fsmExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("tsofsm-%d").build()); fsm = new FsmImpl(fsmExecutor); fsm.setInitState(new DisconnectedState(fsm)); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("handler", new Handler(fsm)); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("reuseAddress", true);
/** * Connect to app master for status RPC report. */ private void initRPCClient() { this.rpcClient = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(), Executors.newSingleThreadExecutor())); // Set up the pipeline factory. this.rpcClient.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())), new ClientHandler()); } }); // Start the connection attempt. ChannelFuture future = this.rpcClient.connect(new InetSocketAddress(this.rpcHostName, this.rpcPort)); LOG.info("Connect to {}:{}", this.rpcHostName, this.rpcPort); this.rpcClientChannel = future.awaitUninterruptibly().getChannel(); }
/** * Creates peer boot strap. * * @return client bootstrap instance */ private ClientBootstrap createPeerBootStrap() { if (peerWorkerThreads == 0) { peerExecFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")), Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d"))); return new ClientBootstrap(peerExecFactory); } else { peerExecFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")), Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d")), peerWorkerThreads); return new ClientBootstrap(peerExecFactory); } }
@SuppressWarnings({"UnnecessaryBoxing"}) public Client(final NettyTransportProvider provider, final SocketAddress address, final UUID id) { this.provider = provider; factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(MyThreadFactory.instance), Executors.newCachedThreadPool(MyThreadFactory.instance)); final ClientBootstrap bootstrap = new ClientBootstrap(factory); final NettyHandler handler = new ClientHandler(this.provider, id); bootstrap.getPipeline().addLast("handler", handler); bootstrap.setOption("tcpNoDelay", Boolean.valueOf(true)); bootstrap.setOption("keepAlive", Boolean.valueOf(true)); channelFuture = bootstrap.connect(address); }
// Configure the client. ClientBootstrap bootstrap = new ClientBootstrap( new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); ChannelFuture future = null; while (true) { future = bootstrap.connect(new InetSocketAddress("127.0.0.1", 80)); future.awaitUninterruptibly(); if (future.isSuccess()) { break; } }
/** * Creates a new default SmppClient. * @param executor The executor that IO workers will be executed with. An * Executors.newCachedDaemonThreadPool() is recommended. The max threads * will never grow more than expectedSessions if NIO sockets are used. * @param expectedSessions The max number of concurrent sessions expected * to be active at any time. This number controls the max number of worker * threads that the underlying Netty library will use. If processing * occurs in a sessionHandler (a blocking op), be <b>VERY</b> careful * setting this to the correct number of concurrent sessions you expect. * @param monitorExecutor The scheduled executor that all sessions will share * to monitor themselves and expire requests. If null monitoring will * be disabled. */ public DefaultSmppClient(ExecutorService executors, int expectedSessions, ScheduledExecutorService monitorExecutor) { this.channels = new DefaultChannelGroup(); this.executors = executors; this.channelFactory = new NioClientSocketChannelFactory(this.executors, this.executors, expectedSessions); this.clientBootstrap = new ClientBootstrap(channelFactory); // we use the same default pipeline for all new channels - no need for a factory this.clientConnector = new SmppClientConnector(this.channels); this.clientBootstrap.getPipeline().addLast(SmppChannelConstants.PIPELINE_CLIENT_CONNECTOR_NAME, this.clientConnector); this.monitorExecutor = monitorExecutor; // a shared instance of a timer for session writeTimeout timing this.writeTimeoutTimer = new org.jboss.netty.util.HashedWheelTimer(); }
this.channelFactory = new NioClientSocketChannelFactory(boss, worker); this.bootstrap = new ClientBootstrap(this.channelFactory); this.bootstrap.setOption("tcpNoDelay", true); this.bootstrap.setOption("keepAlive", true); this.maxShutdownWaitTime = maxShutdownWaitTime; Runtime.getRuntime().addShutdownHook(new Thread()
private void reset() { Preconditions.checkState(!isConnected(), "Cannot reset while mail client is still connected (call disconnect() first)."); // Just to be on the safe side. if (mailClientHandler != null) { mailClientHandler.halt(); mailClientHandler.disconnected(); } this.mailClientHandler = new MailClientHandler(this, config); MailClientPipelineFactory pipelineFactory = new MailClientPipelineFactory(mailClientHandler, config); this.bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool)); this.bootstrap.setPipelineFactory(pipelineFactory); // Reset state (helps if this is a reconnect). this.currentFolder = null; this.sequence.set(0L); mailClientHandler.idleRequested.set(false); }
private static synchronized ClientSocketChannelFactory getFactory() { if (factory == null) { factory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor); } return factory; }
@Override public void run() { channelFactory.shutdown(); channelFactory.releaseExternalResources(); hashedWheelTimer.stop(); } });
@Override public void close() { factory.releaseExternalResources(); } }
/** * Deactivates OSPF controller. */ public void isisDeactivate() { peerExecFactory.shutdown(); }
/** * 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); }
factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()), Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), tsoExecutorThreads); bootstrap = new ClientBootstrap(factory); fsmExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("tsofsm-%d").build()); fsm = new StateMachine.FsmImpl(fsmExecutor); fsm.setInitState(new DisconnectedState(fsm)); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4)); pipeline.addLast("handler", new Handler(fsm)); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("reuseAddress", true);
/** * Connect to app master for status RPC report. */ private void initRPCClient() { this.rpcClient = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(), Executors.newSingleThreadExecutor())); // Set up the pipeline factory. this.rpcClient.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())), new ClientHandler()); } }); // Start the connection attempt. ChannelFuture future = this.rpcClient.connect(new InetSocketAddress(this.rpcHostName, this.rpcPort)); LOG.info("Connect to {}:{}", this.rpcHostName, this.rpcPort); this.rpcClientChannel = future.awaitUninterruptibly().getChannel(); }
/** * Creates peer boot strap. * * @return client bootstrap instance */ private ClientBootstrap createPeerBootStrap() { if (peerWorkerThreads == 0) { peerExecFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")), Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d"))); return new ClientBootstrap(peerExecFactory); } else { peerExecFactory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")), Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d")), peerWorkerThreads); return new ClientBootstrap(peerExecFactory); } }