Search in sources :

Example 6 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project weave by continuuity.

the class TrackerService method startUp.

@Override
protected void startUp() throws Exception {
    Executor bossThreads = Executors.newFixedThreadPool(NUM_BOSS_THREADS, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("boss-thread").build());
    Executor workerThreads = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("worker-thread#%d").build());
    ChannelFactory factory = new NioServerSocketChannelFactory(bossThreads, workerThreads);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpChunkAggregator(MAX_INPUT_SIZE));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("compressor", new HttpContentCompressor());
            pipeline.addLast("handler", new ReportHandler(resourceReport));
            return pipeline;
        }
    });
    Channel channel = bootstrap.bind(new InetSocketAddress(host, 0));
    bindAddress = (InetSocketAddress) channel.getLocalAddress();
    url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).resolve(TrackerService.PATH).toURL();
    channelGroup.add(channel);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) Executor(java.util.concurrent.Executor) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 7 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project opentsdb by OpenTSDB.

the class PipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    final ChannelPipeline pipeline = pipeline();
    pipeline.addLast("connmgr", connmgr);
    pipeline.addLast("detect", HTTP_OR_RPC);
    return pipeline;
}
Also used : ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 8 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project MSEC by Tencent.

the class NettyClientPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = pipeline();
    pipeline.addLast("decoder", decoder);
    pipeline.addLast("encoder", encoder);
    pipeline.addLast("handler", handler);
    return pipeline;
}
Also used : ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 9 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project canal by alibaba.

the class CanalServerWithNetty method start.

public void start() {
    super.start();
    if (!embeddedServer.isStart()) {
        embeddedServer.start();
    }
    this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    // 构造对应的pipeline
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipelines = Channels.pipeline();
            pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
            pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler());
            pipelines.addLast(ClientAuthenticationHandler.class.getName(), new ClientAuthenticationHandler(embeddedServer));
            SessionHandler sessionHandler = new SessionHandler(embeddedServer);
            pipelines.addLast(SessionHandler.class.getName(), sessionHandler);
            return pipelines;
        }
    });
    // 启动
    if (StringUtils.isNotEmpty(ip)) {
        this.serverChannel = bootstrap.bind(new InetSocketAddress(this.ip, this.port));
    } else {
        this.serverChannel = bootstrap.bind(new InetSocketAddress(this.port));
    }
}
Also used : SessionHandler(com.alibaba.otter.canal.server.netty.handler.SessionHandler) ClientAuthenticationHandler(com.alibaba.otter.canal.server.netty.handler.ClientAuthenticationHandler) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HandshakeInitializationHandler(com.alibaba.otter.canal.server.netty.handler.HandshakeInitializationHandler) InetSocketAddress(java.net.InetSocketAddress) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) FixedHeaderFrameDecoder(com.alibaba.otter.canal.server.netty.handler.FixedHeaderFrameDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 10 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline 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)

Aggregations

ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)105 InetSocketAddress (java.net.InetSocketAddress)32 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)29 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)24 Channel (org.jboss.netty.channel.Channel)23 SocketAddress (java.net.SocketAddress)20 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)17 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)16 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)15 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)15 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)15 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)13 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)13 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)13 Checkpoint (com.linkedin.databus.core.Checkpoint)12 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)12 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)11 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)11 Test (org.testng.annotations.Test)11 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)10