Example usage for io.netty.channel ChannelPipeline addLast

List of usage examples for io.netty.channel ChannelPipeline addLast

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline addLast.

Prototype

ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers);

Source Link

Document

Inserts ChannelHandler s at the last position of this pipeline.

Usage

From source file:HttpUploadClientIntializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }/*from ww  w.j a v  a  2s  .c  o m*/

    pipeline.addLast("codec", new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}

From source file:WorldClockClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
    p.addLast("protobufDecoder", new ProtobufDecoder(NetworkMessage.PackageInformation.getDefaultInstance()));

    p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
    p.addLast("protobufEncoder", new ProtobufEncoder());

    p.addLast("handler", new WorldClockClientHandler());
}

From source file:HttpUploadServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    if (HttpUploadServer.isSSL) {
        SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
        engine.setUseClientMode(false);/*from  www.  j  ava2 s.com*/
        pipeline.addLast("ssl", new SslHandler(engine));
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content
    // compression.
    pipeline.addLast("deflater", new HttpContentCompressor());

    pipeline.addLast("handler", new HttpUploadServerHandler());
}

From source file:WorldClockServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
    p.addLast("protobufDecoder", new ProtobufDecoder(NetworkMessage.PackageInformation.getDefaultInstance()));

    p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
    p.addLast("protobufEncoder", new ProtobufEncoder());

    p.addLast("handler", new WorldClockServerHandler());
}

From source file:NettyServer.java

License:Open Source License

void start() throws Exception {
    parentGroup = new NioEventLoopGroup(1);
    childGroup = new NioEventLoopGroup();

    ServerBootstrap bootstrap = new ServerBootstrap().group(parentGroup, childGroup)
            .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//from ww w.j  a v  a 2s . co m
                protected void initChannel(SocketChannel channel) throws Exception {
                    ChannelPipeline pipeline = channel.pipeline();

                    pipeline.addLast("lineFrame", new LineBasedFrameDecoder(256));
                    pipeline.addLast("decoder", new StringDecoder());
                    pipeline.addLast("encoder", new StringEncoder());

                    pipeline.addLast("handler", new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelActive(ChannelHandlerContext ctx) throws Exception {
                            Channel channel = ctx.channel();
                            channelActiveHandler.accept(channel);
                        }

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                            messageConsumer.accept(msg);
                        }
                    });
                }
            });
    channel = bootstrap.bind(port).channel();
    System.out.println("NettyServer started");
}

From source file:alluxio.worker.netty.PipelineHandler.java

License:Apache License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("nioChunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("frameDecoder", RPCMessage.createFrameDecoder());
    pipeline.addLast("RPCMessageDecoder", new RPCMessageDecoder());
    pipeline.addLast("RPCMessageEncoder", new RPCMessageEncoder());
    pipeline.addLast("dataServerHandler", mDataServerHandler);
}

From source file:appium.android.server.http.ServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("codec", new HttpServerCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
    pipeline.addLast("shaper", TrafficCounter.getShaper());
    pipeline.addLast("handler", new ServerHandler(handlers));
}

From source file:barry.ServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("logging", new LoggingHandler());

    // ???/*from   ww w. ja  v  a  2s  .  c  o  m*/
    //      pipelinene.addLast("decoder", new MsgDecoder());
    // ????byte
    //      pipeline.addLast("encoder", new MsgEncoder());

    pipeline.addLast(new StringDecoder());
    pipeline.addLast(new StringEncoder());

    // 
    pipeline.addLast(new IdleStateHandler(0, 0, 90, TimeUnit.SECONDS));

    // 
    pipeline.addLast("handler", serverHandler);
}

From source file:bean.lee.demo.netty.learn.http.file.HttpStaticFileServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    // Uncomment the following line if you want HTTPS
    // SSLEngine engine =
    // SecureChatSslContextFactory.getServerContext().createSSLEngine();
    // engine.setUseClientMode(false);
    // pipeline.addLast("ssl", new SslHandler(engine));

    pipeline.addLast("decoder", new HttpRequestDecoder());// ?
    pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());// ??
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    //?/*from w w w  .j av  a  2s.  c o  m*/
    pipeline.addLast("handler", new HttpStaticFileServerHandler(true));// Specify false if SSL.
}

From source file:bean.lee.demo.netty.learn.http.helloworld.HttpHelloWorldServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();

    // Uncomment the following line if you want HTTPS
    // SSLEngine engine =
    // SecureChatSslContextFactory.getServerContext().createSSLEngine();
    // engine.setUseClientMode(false);
    // p.addLast("ssl", new SslHandler(engine));

    p.addLast("codec", new HttpServerCodec());
    p.addLast("handler", new HttpHelloWorldServerHandler());
}