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(ChannelHandler... handlers);

Source Link

Document

Inserts ChannelHandler s at the last position of this pipeline.

Usage

From source file:com.alltobid.quotabid.BidClientInitializer.java

License:Apache License

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

    p.addLast(BidClient.globalTrafficShapingHandler);

    p.addLast(new FixedLengthFrameDecoder(100));

    p.addLast(stringDecoder);//from   w ww  .  j  a v  a  2  s  . c o  m

    p.addLast(loggingHandler);

    p.addLast(BidClient.bidClientHandler);
}

From source file:com.alltobid.quotabid.BidServerInitializer.java

License:Apache License

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

    p.addLast(new IdleStateHandler(20, 0, 0));

    p.addLast(loggingHandler);/*from ww w.  j  a v  a 2  s . com*/
    p.addLast(SocketServer.globalTrafficShapingHandler);

    p.addLast(stringEncoder);

    p.addLast(SocketServer.bidServerHandler);
}

From source file:com.android.tools.idea.diagnostics.crash.LocalTestServer.java

License:Apache License

public void start() throws Exception {
    ServerBootstrap b = new ServerBootstrap();
    myEventLoopGroup = new OioEventLoopGroup();
    b.group(myEventLoopGroup).channel(OioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override/*w  ww . j a  v a2s  . c o m*/
                protected void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    p.addLast(new HttpServerCodec());
                    // Note: Netty's decompressor uses jcraft jzlib, which is not exported as a library
                    // p.addLast(new HttpContentDecompressor());
                    p.addLast(new HttpObjectAggregator(32 * 1024)); // big enough to collect a full thread dump
                    p.addLast(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
                            ctx.flush();
                        }

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                            if (!(msg instanceof FullHttpRequest)) {
                                return;
                            }

                            FullHttpResponse response = myResponseSupplier.apply((FullHttpRequest) msg);
                            response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
                            response.headers().set(HttpHeaderNames.CONTENT_LENGTH,
                                    response.content().readableBytes());
                            ctx.write(response).addListener(ChannelFutureListener.CLOSE);
                        }

                        @Override
                        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
                                throws Exception {
                            ctx.write(cause.toString()).addListener(ChannelFutureListener.CLOSE);
                        }
                    });
                }
            });

    myChannel = b.bind(myPort).sync().channel();
}

From source file:com.artigile.homestats.HomeStatsServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }//from w  ww.  j  av a2s .  co m
    p.addLast(new HttpServerCodec());
    p.addLast(homeStatsHandler);
}

From source file:com.bala.learning.learning.netty.HttpServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }//from  www  .j  ava2  s . c o m
    p.addLast(new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    //p.addLast(new HttpObjectAggregator(1048576));
    p.addLast(new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    //p.addLast(new HttpContentCompressor());
    p.addLast(new HttpServerHandler());
}

From source file:com.barchart.netty.client.facets.AuthenticationFacet.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    if (pipeline.get(CapabilitiesRequest.class) == null)
        pipeline.addLast(new CapabilitiesRequest());

    authenticator = builder.build();//w  ww  .  j  av  a  2 s. c  om
    authenticator.authStateChanges().subscribe(stateRelay);

    pipeline.addLast(authenticator);

}

From source file:com.barchart.netty.client.facets.KeepaliveFacet.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    synchronized (this) {

        if (interval > 0) {
            // Timed ping initiator
            pingHandler = new PingHandler(interval, unit);
            pipeline.addLast(pingHandler);
        } else {//from   w  w  w .  j ava 2  s. c  om
            // Response-only handler
            pingHandler = new PingHandler();
            pipeline.addLast(pingHandler);
        }

    }

}

From source file:com.barchart.netty.client.facets.SecureFacet.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    switch (security) {

    case REFUSE:/*from w  w w . ja  va 2 s.c om*/
        handler = null;
        break;

    case REQUIRE:
        handler = new SecureFlowHandler(true);
        break;

    case OPTIONAL:
    default:
        handler = new SecureFlowHandler(false);

    }

    if (handler != null) {

        if (pipeline.get(CapabilitiesRequest.class) == null)
            pipeline.addLast(new CapabilitiesRequest());

        pipeline.addLast(handler);

    }

}

From source file:com.barchart.netty.server.http.HttpServer.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    pipeline.addLast(new HttpResponseEncoder());

    if (chunked) {
        pipeline.addLast(new ChunkedWriteHandler());
    }//from ww w . j  a v  a  2s. c o  m

    if (clientTracker != null) {
        pipeline.addLast(clientTracker);
    }

    pipeline.addLast( //
            new HttpRequestDecoder(), //
            new HttpObjectAggregator(maxRequestSize), //
            channelHandler);

}

From source file:com.barchart.netty.server.pipeline.SecurePipelineInitializer.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {
    initializer.initPipeline(pipeline);//from w ww . j  a  va 2  s  .  c o m
    pipeline.addLast(new StartTLSHandler());
}