Example usage for io.netty.handler.codec.compression SnappyFramedDecoder SnappyFramedDecoder

List of usage examples for io.netty.handler.codec.compression SnappyFramedDecoder SnappyFramedDecoder

Introduction

In this page you can find the example usage for io.netty.handler.codec.compression SnappyFramedDecoder SnappyFramedDecoder.

Prototype

SnappyFramedDecoder

Source Link

Usage

From source file:org.kobeyoung81.dummyhttpproxy.HexDumpProxyFrontendHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    final Channel inboundChannel = ctx.channel();

    // Start the connection attempt.
    Bootstrap b = new Bootstrap();
    b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass())
            .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false);

    ChannelFuture f = b.connect(remoteHost, remotePort);
    outboundChannel = f.channel();//from w  w  w .j  a  v  a2  s.com

    if ("local".equals(role)) {
        outboundChannel.pipeline().addLast(new SnappyFramedEncoder());
        outboundChannel.pipeline().addLast(new DummyHttpRequestEncoder());
        outboundChannel.pipeline().addFirst(new SnappyFramedDecoder());
        outboundChannel.pipeline().addFirst(new DummyHttpResponseDecoder());
    }

    f.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            if (future.isSuccess()) {
                // connection complete start to read first data
                inboundChannel.read();
            } else {
                // Close the connection if the connection attempt has
                // failed.
                inboundChannel.close();
            }
        }
    });
}

From source file:org.kobeyoung81.dummyhttpproxy.HexDumpProxyInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    if ("local".equals(role)) {
        ch.pipeline().addLast(new LoggingHandler(LogLevel.ERROR),
                new HexDumpProxyFrontendHandler(role, remoteHost, remotePort));
    } else {/*w  w w .  j  ava  2  s.  c  o  m*/
        ch.pipeline().addLast(new LoggingHandler(LogLevel.ERROR), new DummyHttpRequestDecoder(),
                new SnappyFramedDecoder(), new HexDumpProxyFrontendHandler(role, remoteHost, remotePort),
                new SnappyFramedEncoder(), new DummyHttpResponseEncoder());
    }
}

From source file:org.kobeyoung81.hexdumpproxy.HexDumpProxyFrontendHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    final Channel inboundChannel = ctx.channel();

    // Start the connection attempt.
    Bootstrap b = new Bootstrap();
    b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass())
            .handler(new HexDumpProxyBackendHandler(inboundChannel)).option(ChannelOption.AUTO_READ, false);

    ChannelFuture f = b.connect(remoteHost, remotePort);
    outboundChannel = f.channel();//from  w w w .  j a  v  a2 s.  c o m

    if ("local".equals(role)) {
        outboundChannel.pipeline().addLast(new SnappyFramedEncoder());
        outboundChannel.pipeline().addFirst(new SnappyFramedDecoder());
    }

    f.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            if (future.isSuccess()) {
                // connection complete start to read first data
                inboundChannel.read();
            } else {
                // Close the connection if the connection attempt has
                // failed.
                inboundChannel.close();
            }
        }
    });
}

From source file:org.kobeyoung81.hexdumpproxy.HexDumpProxyInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    if ("local".equals(role)) {
        ch.pipeline().addLast(/*w w  w .j a  v a 2s  . c  om*/
                //new LoggingHandler(LogLevel.ERROR),
                new HexDumpProxyFrontendHandler(role, remoteHost, remotePort));
    } else {
        ch.pipeline().addLast(
                //new LoggingHandler(LogLevel.ERROR),
                new SnappyFramedDecoder(), new HexDumpProxyFrontendHandler(role, remoteHost, remotePort),
                new SnappyFramedEncoder());
    }
}

From source file:se.sics.kompics.network.netty.NettyInitializer.java

License:Open Source License

/**
 * Initiate the Pipeline for the newly active connection.
 *///from w ww  .j ava  2 s.  c om
@Override
protected void initChannel(C ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    // IN
    pipeline.addLast("decompressor", new SnappyFramedDecoder());
    pipeline.addLast("decoder", new MessageDecoder());
    pipeline.addLast("handler", handler);
    //pipeline.addBefore("handler", "handlerLogger", new LoggingHandler("handlerLogger"));
    //pipeline.addBefore("handler", "decoder", new MessageDecoder());
    //pipeline.addBefore("decoder", "decoderLogger", new LoggingHandler("decoderLogger"));
    //pipeline.addBefore("decoderLogger", "deframer", new LengthFieldBasedFrameDecoder(65532, 0, 2)); //2^16 - 2bytes for the length header (snappy wants to more than 65536 bytes uncompressed)
    //pipeline.addBefore("deframer", "deframerLogger", new LoggingHandler("deframerLogger"));
    //pipeline.addBefore("decoder", "decompressor", new SnappyFramedDecoder());
    // OUT
    pipeline.addLast("compressor", new SnappyFramedEncoder());
    pipeline.addLast("encoder", new MessageEncoder());
    //pipeline.addAfter("encoder", "encoderLogger", new LoggingHandler("encoderLogger"));
    //pipeline.addAfter("encoderLogger", "framer", new LengthFieldPrepender(2));
    //pipeline.addAfter("framer", "framerLogger", new LoggingHandler("framerLogger"));
    //pipeline.addAfter("encoder", "compressor", new SnappyFramedEncoder());
}