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.gdut.Netty_testing.dongjun.server.ElectricControlServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }//from w w  w  .  j a va 2 s. com

    p.addLast(new Decoder());
    p.addLast(new Encoder());
    p.addLast(new ElectricControlServerHandler());
    //      p.addLast(new ElectricControlServerOutBoundHandler());
}

From source file:com.gdut.Netty_testing.time_server.server.TimeServer.java

License:Apache License

/**
 * //from w ww . jav  a  2 s .  co m
 * @Title: main
 * @Description: TODO
 * @param @param args
 * @param @throws Exception
 * @return void
 * @throws
 */
public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        if (sslCtx != null) {
                            p.addLast(sslCtx.newHandler(ch.alloc()));
                        }
                        p.addLast(new LoggingHandler(LogLevel.INFO), new TimeEncoder(),
                                new TimeServerHandler());
                        // new TimeEncoder(),
                    }
                });

        // Start the server.
        ChannelFuture f = b.bind(PORT).sync();
        f.addListener(new GenericFutureListener<Future<? super Void>>() {

            public void operationComplete(Future<? super Void> future) throws Exception {
                // TODO Auto-generated method stub
                System.out.println("success " + future.isSuccess());
            }
        });

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.github.jonbonazza.puni.core.HttpInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslContext != null)
        pipeline.addLast(sslContext.newHandler(ch.alloc()));

    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new RequestHandler(muxer));
}

From source file:com.github.jrialland.ajpclient.impl.Conversation.java

License:Apache License

public boolean execute(final Channel channel) throws Exception {
    final ChannelPipeline pipeline = channel.pipeline();
    if (getLog().isTraceEnabled() && pipeline.get(OutgoingFramesLogger.class) == null) {
        pipeline.addLast(new OutgoingFramesLogger());
    }// ww w .  ja v a 2 s . c om
    if (pipeline.get(AjpMessagesHandler.class) == null) {
        pipeline.addLast(new AjpMessagesHandler());
    }
    beforeUse(channel);
    final boolean r = __doWithChannel(channel);
    beforeRelease(channel);
    return r;
}

From source file:com.github.milenkovicm.kafka.connection.ControlKafkaBroker.java

License:Apache License

@Override
protected ChannelInitializer<SocketChannel> pipeline() {
    return new ChannelInitializer<SocketChannel>() {
        @Override/*from   w w w  . j  a  v  a  2  s.  co m*/
        public void initChannel(SocketChannel channel) throws Exception {
            final ChannelPipeline pipeline = channel.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 0, 4, 0, 4));
            if (properties.get(ProducerProperties.NETTY_DEBUG_PIPELINE)) {
                pipeline.addLast(new LoggingHandler());
            }
            pipeline.addLast(new MetadataHandler(properties));
            pipeline.addLast(new TerminalHandler());
        }
    };
}

From source file:com.github.milenkovicm.kafka.connection.DataKafkaBroker.java

License:Apache License

@Override
protected ChannelInitializer<SocketChannel> pipeline() {
    return new ChannelInitializer<SocketChannel>() {
        @Override//from   w  w  w  .j  a  v  a2s .c om
        public void initChannel(SocketChannel channel) throws Exception {
            final ChannelPipeline pipeline = channel.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(metricHandler);

            if (properties.get(ProducerProperties.NETTY_DEBUG_PIPELINE)) {
                pipeline.addLast(new LoggingHandler());
            }

            if (properties.get(ProducerProperties.NETTY_HANDLER_COMPOSITE)) {
                pipeline.addLast(new CompositeProducerHandler(topicName, properties));
            } else {
                pipeline.addLast(new CopyProducerHandler(topicName, properties));
            }
            pipeline.addLast(new TerminalHandler());
        }
    };
}

From source file:com.github.mrstampy.gameboot.otp.netty.client.ClearClientInitializer.java

License:Open Source License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new LengthFieldPrepender(4));
    pipeline.addLast(new ObjectEncoder());
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
    pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast(clientHandler);/* w  w  w  .  j av  a 2s.  c  o m*/
}

From source file:com.github.mrstampy.gameboot.otp.netty.client.EncryptedClientInitializer.java

License:Open Source License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new SslHandler(createSslEngine()));
    pipeline.addLast(new LengthFieldPrepender(2));
    pipeline.addLast(new ObjectEncoder());
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
    pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast(clientHandler);/*from w  ww. j a  v  a2s  .co  m*/
}

From source file:com.github.mrstampy.gameboot.otp.netty.server.ClearServerInitializer.java

License:Open Source License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new LengthFieldPrepender(4));
    pipeline.addLast(new ObjectEncoder());
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
    pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast(utils.getBean(OtpClearNettyHandler.class));
}

From source file:com.github.mrstampy.gameboot.otp.netty.server.EncryptedServerInitializer.java

License:Open Source License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new SslHandler(createSslEngine()));
    pipeline.addLast(new LengthFieldPrepender(2));
    pipeline.addLast(new ObjectEncoder());
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
    pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast(utils.getBean(OtpEncryptedNettyHandler.class));
}