Search in sources :

Example 6 with NioClientSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project jstorm by alibaba.

the class NettyContext method prepare.

/**
     * initialization per Storm configuration
     */
@SuppressWarnings("rawtypes")
public void prepare(Map storm_conf) {
    this.storm_conf = storm_conf;
    int maxWorkers = Utils.getInt(storm_conf.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);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread)

Example 7 with NioClientSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project camel by apache.

the class ClientModeTCPNettyServerBootstrapFactory method startServerBootstrap.

protected void startServerBootstrap() {
    // prefer using explicit configured thread pools
    BossPool bp = configuration.getBossPool();
    WorkerPool wp = configuration.getWorkerPool();
    if (bp == null) {
        // create new pool which we should shutdown when stopping as its not shared
        bossPool = new NettyClientBossPoolBuilder().withTimer(new HashedWheelTimer()).withBossCount(configuration.getBossCount()).withName("NettyClientTCPBoss").build();
        bp = bossPool;
    }
    if (wp == null) {
        // create new pool which we should shutdown when stopping as its not shared
        workerPool = new NettyWorkerPoolBuilder().withWorkerCount(configuration.getWorkerCount()).withName("NettyServerTCPWorker").build();
        wp = workerPool;
    }
    channelFactory = new NioClientSocketChannelFactory(bp, wp);
    serverBootstrap = new ClientBootstrap(channelFactory);
    serverBootstrap.setOption("keepAlive", configuration.isKeepAlive());
    serverBootstrap.setOption("tcpNoDelay", configuration.isTcpNoDelay());
    serverBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
    serverBootstrap.setOption("connectTimeoutMillis", configuration.getConnectTimeout());
    if (configuration.getBacklog() > 0) {
        serverBootstrap.setOption("backlog", configuration.getBacklog());
    }
    // set any additional netty options
    if (configuration.getOptions() != null) {
        for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
            serverBootstrap.setOption(entry.getKey(), entry.getValue());
        }
    }
    LOG.debug("Created ServerBootstrap {} with options: {}", serverBootstrap, serverBootstrap.getOptions());
    // set the pipeline factory, which creates the pipeline for each newly created channels
    serverBootstrap.setPipelineFactory(pipelineFactory);
    LOG.info("ServerBootstrap connecting to {}:{}", configuration.getHost(), configuration.getPort());
    ChannelFuture connectFuture = serverBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
    try {
        channel = openChannel(connectFuture);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) CamelException(org.apache.camel.CamelException) ConnectException(java.net.ConnectException) BossPool(org.jboss.netty.channel.socket.nio.BossPool) WorkerPool(org.jboss.netty.channel.socket.nio.WorkerPool) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) Map(java.util.Map)

Example 8 with NioClientSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project databus by linkedin.

the class TestHttpResponseProcessor method createChannelFuture.

static ChannelFuture createChannelFuture(final GenericHttpResponseHandler responseHandler, int port) {
    ClientBootstrap client = new ClientBootstrap(new NioClientSocketChannelFactory(BOSS_POOL, IO_POOL));
    client.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new LoggingHandler(InternalLogLevel.DEBUG), new HttpClientCodec(), new LoggingHandler(InternalLogLevel.DEBUG), responseHandler);
        }
    });
    final ChannelFuture connectFuture = client.connect(new InetSocketAddress("localhost", port));
    return connectFuture;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) DatabusException(com.linkedin.databus2.core.DatabusException) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 9 with NioClientSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project http-client by biasedbit.

the class DefaultHttpClient method init.

// HttpClient -----------------------------------------------------------------------------------------------------
@Override
public boolean init() {
    if (timeoutController == null) {
        // prefer lower resources consumption over precision
        timeoutController = new HashedWheelTimeoutController();
        timeoutController.init();
        internalTimeoutManager = true;
    }
    if (connectionFactory == null)
        connectionFactory = new DefaultConnectionFactory();
    if ((sslContextFactory == null) && isHttps())
        sslContextFactory = BogusSslContextFactory.getInstance();
    eventConsumerLatch = new CountDownLatch(1);
    eventQueue = new LinkedBlockingQueue<>();
    // TODO instead of fixed size thread pool, use a cached thread pool with size limit (limited growth cached pool)
    executor = Executors.newFixedThreadPool(maxHelperThreads, new NamedThreadFactory("httpHelpers"));
    Executor workerPool = Executors.newFixedThreadPool(maxIoWorkerThreads, new NamedThreadFactory("httpWorkers"));
    if (useNio) {
        // It's only going to create 1 thread, so no harm done here.
        Executor bossPool = Executors.newCachedThreadPool();
        channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
    } else {
        channelFactory = new OioClientSocketChannelFactory(workerPool);
    }
    channelGroup = new CleanupChannelGroup(toString());
    // Create a pipeline without the last handler (it will be added right before connecting).
    pipelineFactory = new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            if (useSsl) {
                SSLEngine engine = sslContextFactory.getClientContext().createSSLEngine();
                engine.setUseClientMode(true);
                pipeline.addLast("ssl", new SslHandler(engine));
            }
            pipeline.addLast("codec", new HttpClientCodec());
            if (autoDecompress)
                pipeline.addLast("decompressor", new HttpContentDecompressor());
            return pipeline;
        }
    };
    executor.execute(new Runnable() {

        @Override
        public void run() {
            eventHandlingLoop();
        }
    });
    return true;
}
Also used : NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) SSLEngine(javax.net.ssl.SSLEngine) HashedWheelTimeoutController(com.biasedbit.http.client.timeout.HashedWheelTimeoutController) SslHandler(org.jboss.netty.handler.ssl.SslHandler) OioClientSocketChannelFactory(org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory)

Example 10 with NioClientSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project cdap by caskdata.

the class NettyRouter method bootstrapClient.

private void bootstrapClient(final ChannelUpstreamHandler connectionTracker) {
    ExecutorService clientBossExecutor = createExecutorService(clientBossThreadPoolSize, "router-client-boss-thread-%d");
    ExecutorService clientWorkerExecutor = createExecutorService(clientWorkerThreadPoolSize, "router-client-worker-thread-%d");
    clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(new NioClientBossPool(clientBossExecutor, clientBossThreadPoolSize), new NioWorkerPool(clientWorkerExecutor, clientWorkerThreadPoolSize)));
    ChannelPipelineFactory pipelineFactory = new ClientChannelPipelineFactory(connectionTracker, connectionTimeout, timer);
    clientBootstrap.setPipelineFactory(pipelineFactory);
    clientBootstrap.setOption("bufferFactory", new DirectChannelBufferFactory());
}
Also used : NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioClientBossPool(org.jboss.netty.channel.socket.nio.NioClientBossPool) NioWorkerPool(org.jboss.netty.channel.socket.nio.NioWorkerPool) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) ExecutorService(java.util.concurrent.ExecutorService) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) DirectChannelBufferFactory(org.jboss.netty.buffer.DirectChannelBufferFactory)

Aggregations

NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)15 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)10 ChannelFuture (org.jboss.netty.channel.ChannelFuture)6 InetSocketAddress (java.net.InetSocketAddress)5 ThreadFactory (java.util.concurrent.ThreadFactory)3 NioClientBossPool (org.jboss.netty.channel.socket.nio.NioClientBossPool)3 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)3 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)3 ExecutorService (java.util.concurrent.ExecutorService)2 Channel (org.jboss.netty.channel.Channel)2 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)2 BossPool (org.jboss.netty.channel.socket.nio.BossPool)2 WorkerPool (org.jboss.netty.channel.socket.nio.WorkerPool)2 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1 HashedWheelTimeoutController (com.biasedbit.http.client.timeout.HashedWheelTimeoutController)1 Checkpoint (com.linkedin.databus.core.Checkpoint)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 PinpointThreadFactory (com.navercorp.pinpoint.common.util.PinpointThreadFactory)1 ConnectException (java.net.ConnectException)1 Map (java.util.Map)1