Example usage for io.netty.channel ChannelDuplexHandler ChannelDuplexHandler

List of usage examples for io.netty.channel ChannelDuplexHandler ChannelDuplexHandler

Introduction

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

Prototype

ChannelDuplexHandler

Source Link

Usage

From source file:reactor.ipc.netty.channel.NettyOperations.java

License:Open Source License

@Override
public NettyOperations<INBOUND, OUTBOUND> onClose(final Runnable onClose) {
    channel.pipeline().addLast(new ChannelDuplexHandler() {
        @Override//from www. j  av  a 2s  .  c om
        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
            onClose.run();
            super.channelInactive(ctx);
        }
    });
    return this;
}

From source file:reactor.ipc.netty.NettyContextTest.java

License:Open Source License

@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {

    channel.pipeline().addLast(NettyPipeline.HttpDecoder, new HttpRequestDecoder())
            .addLast(NettyPipeline.HttpEncoder, new HttpResponseEncoder())
            .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
            .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
            });/* w  ww.j a va  2 s. c  o m*/
    ChannelHandler decoder = new LineBasedFrameDecoder(12);

    testContext.addHandlerLast("decoder", decoder).addHandlerFirst("decoder$extract",
            NettyPipeline.inboundHandler(ADD_EXTRACTOR));

    assertEquals(channel.pipeline().names(),
            Arrays.asList(NettyPipeline.HttpDecoder, NettyPipeline.HttpEncoder, NettyPipeline.HttpServerHandler,
                    "decoder$extract", "decoder", NettyPipeline.ReactiveBridge,
                    "DefaultChannelPipeline$TailContext#0"));
}

From source file:reactor.ipc.netty.NettyContextTest.java

License:Open Source License

@Test
public void addNonByteDecoderWhenFullReactorPipeline() throws Exception {

    channel.pipeline().addLast(NettyPipeline.HttpDecoder, new HttpRequestDecoder())
            .addLast(NettyPipeline.HttpEncoder, new HttpResponseEncoder())
            .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
            .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
            });/*from  w  w  w.j a v  a 2 s.  c  om*/
    ChannelHandler decoder = new ChannelHandlerAdapter() {
    };

    testContext.addHandlerLast("decoder", decoder);

    assertEquals(channel.pipeline().names(),
            Arrays.asList(NettyPipeline.HttpDecoder, NettyPipeline.HttpEncoder, NettyPipeline.HttpServerHandler,
                    "decoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}

From source file:reactor.ipc.netty.NettyContextTest.java

License:Open Source License

@Test
public void addSeveralByteDecodersWhenCodec() throws Exception {
    ChannelHandler decoder1 = new LineBasedFrameDecoder(12);
    ChannelHandler decoder2 = new LineBasedFrameDecoder(13);

    channel.pipeline().addLast(NettyPipeline.HttpDecoder, new HttpRequestDecoder())
            .addLast(NettyPipeline.HttpEncoder, new HttpResponseEncoder())
            .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
            .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
            });// w  w w .  ja  v  a2 s.c om

    testContext.addHandlerLast("decoder1$extract", NettyPipeline.inboundHandler(ADD_EXTRACTOR))
            .addHandlerLast("decoder1", decoder1)

            .addHandlerLast("decoder2$extract", NettyPipeline.inboundHandler(ADD_EXTRACTOR))
            .addHandlerLast("decoder2", decoder2);

    assertEquals(channel.pipeline().names(),
            Arrays.asList(NettyPipeline.HttpDecoder, NettyPipeline.HttpEncoder, NettyPipeline.HttpServerHandler,
                    "decoder1$extract", "decoder1", "decoder2$extract", "decoder2",
                    NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}

From source file:reactor.ipc.netty.NettyContextTest.java

License:Open Source License

@Test
public void addByteEncoderWhenFullReactorPipeline() throws Exception {

    channel.pipeline().addLast(NettyPipeline.HttpDecoder, new HttpRequestDecoder())
            .addLast(NettyPipeline.HttpEncoder, new HttpResponseEncoder())
            .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
            .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
            });/*from  w  w w  .  j av a 2s.c o  m*/
    ChannelHandler encoder = new LineBasedFrameDecoder(12);

    testContext.addHandlerFirst("encoder", encoder);

    assertEquals(channel.pipeline().names(),
            Arrays.asList(NettyPipeline.HttpDecoder, NettyPipeline.HttpEncoder, NettyPipeline.HttpServerHandler,
                    "encoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}

From source file:reactor.ipc.netty.NettyContextTest.java

License:Open Source License

@Test
public void addNonByteEncoderWhenFullReactorPipeline() throws Exception {

    channel.pipeline().addLast(NettyPipeline.HttpDecoder, new HttpRequestDecoder())
            .addLast(NettyPipeline.HttpEncoder, new HttpResponseEncoder())
            .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
            .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
            });/*from  ww  w .  j av a  2s .  c  o m*/
    ChannelHandler encoder = new ChannelHandlerAdapter() {
    };

    testContext.addHandlerFirst("encoder", encoder);

    assertEquals(channel.pipeline().names(),
            Arrays.asList(NettyPipeline.HttpDecoder, NettyPipeline.HttpEncoder, NettyPipeline.HttpServerHandler,
                    "encoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}

From source file:reactor.ipc.netty.NettyContextTest.java

License:Open Source License

@Test
public void addSeveralByteEncodersWhenCodec() throws Exception {
    ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
    ChannelHandler encoder2 = new LineBasedFrameDecoder(13);

    channel.pipeline().addLast(NettyPipeline.HttpDecoder, new HttpRequestDecoder())
            .addLast(NettyPipeline.HttpEncoder, new HttpResponseEncoder())
            .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
            .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
            });// w w  w . java2 s. c om

    testContext.addHandlerFirst("encoder1", encoder1).addHandlerFirst("encoder2", encoder2);

    assertEquals(channel.pipeline().names(),
            Arrays.asList(NettyPipeline.HttpDecoder, NettyPipeline.HttpEncoder, NettyPipeline.HttpServerHandler,
                    "encoder2", "encoder1", NettyPipeline.ReactiveBridge,
                    "DefaultChannelPipeline$TailContext#0"));
}