Example usage for io.netty.channel.socket.oio OioSocketChannel pipeline

List of usage examples for io.netty.channel.socket.oio OioSocketChannel pipeline

Introduction

In this page you can find the example usage for io.netty.channel.socket.oio OioSocketChannel pipeline.

Prototype

ChannelPipeline pipeline();

Source Link

Document

Return the assigned ChannelPipeline .

Usage

From source file:us.aaronweiss.juicebot.Bot.java

License:Open Source License

/**
 * Constructs a new {@code Bot}./*from ww  w . j  a v a  2s . co  m*/
 *
 * @param username the username of the bot
 * @param simple   whether or not the bot should use the simple messaging API
 * @param useSSL   whether or not the bot should use SSL
 */
public Bot(String username, boolean simple, final boolean useSSL) {
    this.username = username;
    this.simple = simple;
    bootstrap = new Bootstrap();
    bootstrap.group(new OioEventLoopGroup());
    bootstrap.channel(OioSocketChannel.class);
    bootstrap.handler(new ChannelInitializer<OioSocketChannel>() {
        @Override
        protected void initChannel(OioSocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();

            // SSL Support
            if (useSSL) {
                SSLEngine engine = SSLContext.getDefault().createSSLEngine();
                engine.setUseClientMode(true);
                pipeline.addLast("ssl", new SslHandler(engine));
            }

            // Decoders
            pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1000));
            pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));

            // Encoder
            pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));

            // Handlers
            pipeline.addLast("botHandler", new ClientHandlerAdapter(Bot.this));
        }
    });
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
}