Search in sources :

Example 1 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project hadoop by apache.

the class SimpleTcpClient method run.

public void run() {
    // Configure the client.
    ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), 1, 1);
    ClientBootstrap bootstrap = new ClientBootstrap(factory);
    // Set up the pipeline factory.
    bootstrap.setPipelineFactory(setPipelineFactory());
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", true);
    // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
    if (oneShot) {
        // 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 : ChannelFuture(org.jboss.netty.channel.ChannelFuture) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory)

Example 2 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project weave by continuuity.

the class SimpleKafkaClient method startUp.

@Override
protected void startUp() throws Exception {
    brokerCache.startAndWait();
    ThreadFactory threadFactory = Threads.createDaemonThreadFactory("kafka-client-netty-%d");
    NioClientBossPool bossPool = new NioClientBossPool(Executors.newSingleThreadExecutor(threadFactory), 1, new HashedWheelTimer(threadFactory), null);
    NioWorkerPool workerPool = new NioWorkerPool(Executors.newFixedThreadPool(4, threadFactory), 4);
    bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));
    bootstrap.setPipelineFactory(new KafkaChannelPipelineFactory());
    connectionPool = new ConnectionPool(bootstrap);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NioClientBossPool(org.jboss.netty.channel.socket.nio.NioClientBossPool) NioWorkerPool(org.jboss.netty.channel.socket.nio.NioWorkerPool) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer)

Example 3 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project dubbo by alibaba.

the class NettyClient method doOpen.

@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    bootstrap = new ClientBootstrap(channelFactory);
    // config
    // @see org.jboss.netty.channel.socket.SocketChannelConfig
    bootstrap.setOption("keepAlive", true);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("connectTimeoutMillis", getTimeout());
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
}
Also used : ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 4 with ClientBootstrap

use of org.jboss.netty.bootstrap.ClientBootstrap in project databus by linkedin.

the class DummyHttpRequestHandler method setupClient.

private void setupClient() {
    _clientBootstrap = new ClientBootstrap(new DefaultLocalClientChannelFactory());
    _clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline clientPipeline = pipeline();
            clientPipeline.addLast("client logger 1", new LoggingHandler("client logger 1", InternalLogLevel.DEBUG, true));
            clientPipeline.addLast("codec", new HttpClientCodec());
            clientPipeline.addLast("aggregator", new FooterAwareHttpChunkAggregator(1000000));
            _responseHandler = new SimpleHttpResponseHandler();
            clientPipeline.addLast("handler", _responseHandler);
            clientPipeline.addLast("client logger 5", new LoggingHandler("client logger 5", InternalLogLevel.DEBUG, true));
            return clientPipeline;
        }
    });
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) FooterAwareHttpChunkAggregator(com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator) DefaultLocalClientChannelFactory(org.jboss.netty.channel.local.DefaultLocalClientChannelFactory) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 5 with ClientBootstrap

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

the class DefaultPinpointClientFactory method reconnect.

public ChannelFuture reconnect(final SocketAddress remoteAddress) {
    if (remoteAddress == null) {
        throw new NullPointerException("remoteAddress");
    }
    ChannelPipeline pipeline;
    final ClientBootstrap bootstrap = this.bootstrap;
    try {
        pipeline = bootstrap.getPipelineFactory().getPipeline();
    } catch (Exception e) {
        throw new ChannelPipelineException("Failed to initialize a pipeline.", e);
    }
    PinpointClientHandler pinpointClientHandler = (DefaultPinpointClientHandler) pipeline.getLast();
    pinpointClientHandler.initReconnect();
    // Set the options.
    Channel ch = bootstrap.getFactory().newChannel(pipeline);
    boolean success = false;
    try {
        ch.getConfig().setOptions(bootstrap.getOptions());
        success = true;
    } finally {
        if (!success) {
            ch.close();
        }
    }
    // Connect.
    return ch.connect(remoteAddress);
}
Also used : ChannelPipelineException(org.jboss.netty.channel.ChannelPipelineException) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) Channel(org.jboss.netty.channel.Channel) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ChannelPipelineException(org.jboss.netty.channel.ChannelPipelineException)

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