Example usage for io.netty.channel AbstractChannel pipeline

List of usage examples for io.netty.channel AbstractChannel pipeline

Introduction

In this page you can find the example usage for io.netty.channel AbstractChannel pipeline.

Prototype

DefaultChannelPipeline pipeline

To view the source code for io.netty.channel AbstractChannel pipeline.

Click Source Link

Usage

From source file:com.heliosapm.streams.onramp.UDPPipelineFactory.java

License:Apache License

/**
 * {@inheritDoc}//from  ww  w  .  j a  v  a 2s  .c  o m
 * @see io.netty.channel.ChannelInitializer#initChannel(io.netty.channel.Channel)
 */
@Override
protected void initChannel(final AbstractChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast("bytesDecoder", bytesDecoder);
    p.addLast("framer", new LineBasedFrameDecoder(1024, true, true));
    p.addLast("linehandler", new StringMetricHandler());
}

From source file:org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl.java

License:Open Source License

@Override
public ChannelFuture createClient(final InetSocketAddress address, final BmpSessionListenerFactory slf,
        final Optional<KeyMapping> keys) {

    final Bootstrap b = new Bootstrap();

    Preconditions.checkNotNull(address);

    if (Epoll.isAvailable()) {
        b.channel(EpollSocketChannel.class);
    } else {//from  w w  w  .  j  a v a  2  s.  c  om
        b.channel(NioSocketChannel.class);
    }
    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT);
    b.group(this.workerGroup);

    b.handler(new ChannelInitializer<AbstractChannel>() {
        @Override
        protected void initChannel(final AbstractChannel ch) throws Exception {
            ch.pipeline().addLast(BmpDispatcherImpl.this.hf.getDecoders());
            ch.pipeline().addLast(BmpDispatcherImpl.this.sessionFactory.getSession(ch, slf));
        }
    });

    b.remoteAddress(address);
    final ChannelFuture channelPromise = b.connect();
    channelPromise.addListener(new BmpDispatcherImpl.BootstrapListener(b, address));
    return channelPromise;
}