Search in sources :

Example 6 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project pinpoint by naver.

the class DefaultPinpointClientFactory method createBootStrap.

private ClientBootstrap createBootStrap(int bossCount, int workerCount, Timer timer) {
    // profiler, collector,
    logger.debug("createBootStrap boss:{}, worker:{}", bossCount, workerCount);
    NioClientSocketChannelFactory nioClientSocketChannelFactory = createChannelFactory(bossCount, workerCount, timer);
    return new ClientBootstrap(nioClientSocketChannelFactory);
}
Also used : NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap)

Example 7 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project neo4j by neo4j.

the class NetworkSender method start.

@Override
public void start() throws Throwable {
    channels = new DefaultChannelGroup();
    // Start client bootstrap
    clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(daemon("Cluster client boss", monitor)), Executors.newFixedThreadPool(2, daemon("Cluster client worker", monitor)), 2));
    clientBootstrap.setOption("tcpNoDelay", true);
    clientBootstrap.setPipelineFactory(new NetworkNodePipelineFactory());
    msgLog.debug("Started NetworkSender for " + toString(config));
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap)

Example 8 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap 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 9 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap 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 10 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project yyl_example by Relucent.

the class NettyClient method main.

public static void main(String[] args) {
    ClientBootstrap bootstrap = new ClientBootstrap(new //
    NioClientSocketChannelFactory(//
    Executors.newCachedThreadPool(), //
    Executors.newCachedThreadPool()));
    // Set up the default event pipeline.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new StringDecoder(), new StringEncoder(), new ClientHandler());
        }
    });
    // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 8000));
    // Wait until the connection is closed or the connection attempt fails.
    future.getChannel().getCloseFuture().awaitUninterruptibly();
    // Shut down thread pools to exit.
    bootstrap.releaseExternalResources();
}
Also used : StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) ChannelFuture(org.jboss.netty.channel.ChannelFuture) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress) StringDecoder(org.jboss.netty.handler.codec.string.StringDecoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)24 InetSocketAddress (java.net.InetSocketAddress)10 ChannelFuture (org.jboss.netty.channel.ChannelFuture)10 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)10 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)7 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)7 Channel (org.jboss.netty.channel.Channel)4 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Map (java.util.Map)2 NioClientBossPool (org.jboss.netty.channel.socket.nio.NioClientBossPool)2 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)2 HttpClientCodec (org.jboss.netty.handler.codec.http.HttpClientCodec)2 HttpRequestEncoder (org.jboss.netty.handler.codec.http.HttpRequestEncoder)2 HttpResponseDecoder (org.jboss.netty.handler.codec.http.HttpResponseDecoder)2 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)2 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)2 Checkpoint (com.linkedin.databus.core.Checkpoint)1 FooterAwareHttpChunkAggregator (com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator)1 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)1