Search in sources :

Example 6 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory 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 7 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory in project dubbo by alibaba.

the class NettyServer method doOpen.

@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();
            /*int idleTimeout = getIdleTimeout();
                if (idleTimeout > 10000) {
                    pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
                }*/
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 8 with ChannelPipelineFactory

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

use of org.jboss.netty.channel.ChannelPipelineFactory in project camel by apache.

the class DefaultNettySharedHttpServer method doStart.

protected void doStart() throws Exception {
    ObjectHelper.notNull(configuration, "setNettyServerBootstrapConfiguration() must be called with a NettyServerBootstrapConfiguration instance", this);
    // port must be set
    if (configuration.getPort() <= 0) {
        throw new IllegalArgumentException("Port must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
    }
    // hostname must be set
    if (ObjectHelper.isEmpty(configuration.getHost())) {
        throw new IllegalArgumentException("Host must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
    }
    LOG.debug("NettySharedHttpServer using configuration: {}", configuration);
    // force using tcp as the underlying transport
    configuration.setProtocol("tcp");
    channelFactory = new HttpServerMultiplexChannelHandler();
    channelFactory.init(configuration.getPort());
    ChannelPipelineFactory pipelineFactory = new HttpServerSharedPipelineFactory(configuration, channelFactory, classResolver);
    // thread factory and pattern
    String port = Matcher.quoteReplacement("" + configuration.getPort());
    String pattern = threadPattern;
    pattern = pattern.replaceFirst("#port#", port);
    ThreadFactory tf = new CamelThreadFactory(pattern, "NettySharedHttpServer", true);
    // create bootstrap factory and disable compatible check as its shared among the consumers
    bootstrapFactory = new HttpServerBootstrapFactory(channelFactory, false);
    bootstrapFactory.init(tf, configuration, pipelineFactory);
    ServiceHelper.startServices(channelFactory);
    if (startServer) {
        LOG.info("Starting NettySharedHttpServer on {}:{}", configuration.getHost(), configuration.getPort());
        ServiceHelper.startServices(bootstrapFactory);
    }
}
Also used : CamelThreadFactory(org.apache.camel.util.concurrent.CamelThreadFactory) CamelThreadFactory(org.apache.camel.util.concurrent.CamelThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) HttpServerMultiplexChannelHandler(org.apache.camel.component.netty.http.handlers.HttpServerMultiplexChannelHandler)

Example 10 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory in project camel by apache.

the class NettyUdpConnectedSendTest method createNettyUdpReceiver.

public void createNettyUdpReceiver() {
    bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory());
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline channelPipeline = Channels.pipeline();
            channelPipeline.addLast("StringDecoder", new StringDecoder(CharsetUtil.UTF_8));
            channelPipeline.addLast("ContentHandler", new ContentHandler());
            return channelPipeline;
        }
    });
}
Also used : NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) StringDecoder(org.jboss.netty.handler.codec.string.StringDecoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Aggregations

ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)31 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)29 InetSocketAddress (java.net.InetSocketAddress)12 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)11 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)10 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)7 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)7 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)6 HttpServerCodec (org.jboss.netty.handler.codec.http.HttpServerCodec)6 Log4JLoggerFactory (org.jboss.netty.logging.Log4JLoggerFactory)6 BeforeClass (org.testng.annotations.BeforeClass)6 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)5 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)5 IOException (java.io.IOException)5 ChannelFactory (org.jboss.netty.channel.ChannelFactory)5 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)4 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)4 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)4 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)4 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)3