Example usage for io.netty.handler.codec.compression ZlibCodecFactory newZlibDecoder

List of usage examples for io.netty.handler.codec.compression ZlibCodecFactory newZlibDecoder

Introduction

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

Prototype

public static ZlibDecoder newZlibDecoder(byte[] dictionary) 

Source Link

Usage

From source file:com.flysoloing.learning.network.netty.factorial.FactorialClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc(), FactorialClient.HOST, FactorialClient.PORT));
    }//from  w w w  .  j a  v  a 2s  .c  om

    // Enable stream compression (you can remove these two if unnecessary)
    pipeline.addLast(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    pipeline.addLast(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));

    // Add the number codec first,
    pipeline.addLast(new BigIntegerDecoder());
    pipeline.addLast(new NumberEncoder());

    // and then business logic.
    pipeline.addLast(new FactorialClientHandler());
}

From source file:com.flysoloing.learning.network.netty.factorial.FactorialServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }//from  w  w w  .jav  a 2 s.c om

    // Enable stream compression (you can remove these two if unnecessary)
    pipeline.addLast(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    pipeline.addLast(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));

    // Add the number codec first,
    pipeline.addLast(new BigIntegerDecoder());
    pipeline.addLast(new NumberEncoder());

    // and then business logic.
    // Please note we create a handler for every new channel
    // because it has stateful properties.
    pipeline.addLast(new FactorialServerHandler());
}

From source file:com.flysoloing.learning.network.netty.portunification.PortUnificationServerHandler.java

License:Apache License

private void enableGzip(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();/*from   w  w w . java 2s  .com*/
    p.addLast("gzipdeflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    p.addLast("gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
    p.addLast("unificationB", new PortUnificationServerHandler(sslCtx, detectSsl, false));
    p.remove(this);
}

From source file:com.googlecode.protobuf.pro.duplex.client.DuplexTcpClientPipelineFactory.java

License:Apache License

/**
 * After RPC handshake has taken place, remove the RPC handshake
 * {@link ClientConnectResponseHandler} and add a {@link RpcClientHandler}
 * and {@link RpcServerHandler} to complete the Netty client side Pipeline.
 * /*from   ww  w.  j a v  a 2s .c  o m*/
 * @param rpcClient
 * @return
 */
protected RpcClientHandler completePipeline(RpcClient rpcClient) {
    ChannelPipeline p = rpcClient.getChannel().pipeline();

    if (rpcClient.isCompression()) {
        p.addBefore(Handler.FRAME_DECODER, Handler.COMPRESSOR,
                ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
        p.addAfter(Handler.COMPRESSOR, Handler.DECOMPRESSOR, ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
    }

    TcpConnectionEventListener informer = new TcpConnectionEventListener() {
        @Override
        public void connectionClosed(RpcClientChannel client) {
            for (TcpConnectionEventListener listener : getListenersCopy()) {
                listener.connectionClosed(client);
            }
        }

        @Override
        public void connectionOpened(RpcClientChannel client) {
            for (TcpConnectionEventListener listener : getListenersCopy()) {
                listener.connectionOpened(client);
            }
        }
    };
    RpcClientHandler rpcClientHandler = new RpcClientHandler(rpcClient, informer);
    p.replace(Handler.CLIENT_CONNECT, Handler.RPC_CLIENT, rpcClientHandler);

    RpcServer rpcServer = new RpcServer(rpcClient, rpcServiceRegistry, rpcServerCallExecutor, logger);
    RpcServerHandler rpcServerHandler = new RpcServerHandler(rpcServer, rpcClientRegistry);
    p.addAfter(Handler.RPC_CLIENT, Handler.RPC_SERVER, rpcServerHandler);

    return rpcClientHandler;
}

From source file:com.googlecode.protobuf.pro.duplex.server.DuplexTcpServerPipelineFactory.java

License:Apache License

public RpcClientHandler completePipeline(RpcClient rpcClient) {
    ChannelPipeline p = rpcClient.getChannel().pipeline();

    if (rpcClient.isCompression()) {
        p.addBefore(Handler.FRAME_DECODER, Handler.COMPRESSOR,
                ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
        p.addAfter(Handler.COMPRESSOR, Handler.DECOMPRESSOR, ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
    }//from   w  w  w .  j av  a2  s  .c  o m

    TcpConnectionEventListener informer = new TcpConnectionEventListener() {
        @Override
        public void connectionClosed(RpcClientChannel client) {
            for (TcpConnectionEventListener listener : getListenersCopy()) {
                listener.connectionClosed(client);
            }
        }

        @Override
        public void connectionOpened(RpcClientChannel client) {
            for (TcpConnectionEventListener listener : getListenersCopy()) {
                listener.connectionOpened(client);
            }
        }
    };

    RpcClientHandler rpcClientHandler = new RpcClientHandler(rpcClient, informer);
    p.replace(Handler.SERVER_CONNECT, Handler.RPC_CLIENT, rpcClientHandler);

    RpcServer rpcServer = new RpcServer(rpcClient, getRpcServiceRegistry(), getRpcServerCallExecutor(),
            getLogger());
    RpcServerHandler rpcServerHandler = new RpcServerHandler(rpcServer, getRpcClientRegistry());
    p.addAfter(Handler.RPC_CLIENT, Handler.RPC_SERVER, rpcServerHandler);

    if (log.isDebugEnabled()) {
        log.debug("completed Pipeline to " + rpcClient.getPeerInfo());
    }
    return rpcClientHandler;
}

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

License:Apache License

private void enableGzip(final ChannelHandlerContext ctx) {
    final ChannelPipeline p = ctx.pipeline();
    try {/* w  w w.ja va2 s  .  c  o  m*/
        //         p.addAfter("connmgr", "gzipdeflater", new JZlibEncoder(ZlibWrapper.GZIP){
        //            // TODO
        //         });            
        p.addAfter("gzipdetector", "gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
        p.remove(this);
    } catch (Exception ex) {
        log.error("Failed to add gzip handlers", ex);
    }
}

From source file:com.heliosapm.tsdblite.handlers.ProtocolSwitch.java

License:Apache License

private void enableGzip(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();//from  www  . jav a  2s.  c  o m
    p.addLast("gzipdeflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    p.addLast("gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
    p.addLast("2ndPhaseSwitch", new ProtocolSwitch(false));
    p.remove(this);
    log.info("enabled gzip: [{}]", ctx.channel().id());
}

From source file:com.hop.hhxx.example.factorial.FactorialClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc(), io.netty.example.factorial.FactorialClient.HOST,
                io.netty.example.factorial.FactorialClient.PORT));
    }// w  w  w.  j  a  v  a  2 s .  c om

    // Enable stream compression (you can remove these two if unnecessary)
    pipeline.addLast(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    pipeline.addLast(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));

    // Add the number codec first,
    pipeline.addLast(new BigIntegerDecoder());
    pipeline.addLast(new NumberEncoder());

    // and then business logic.
    pipeline.addLast(new FactorialClientHandler());
}

From source file:com.hop.hhxx.example.factorial.FactorialServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/*  w ww. ja  va 2 s  . c  o  m*/

    // Enable stream compression (you can remove these two if unnecessary)
    pipeline.addLast(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    pipeline.addLast(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));

    // Add the number codec first,
    pipeline.addLast(new io.netty.example.factorial.BigIntegerDecoder());
    pipeline.addLast(new NumberEncoder());

    // and then business logic.
    // Please note we create a handler for every new channel
    // because it has stateful properties.
    pipeline.addLast(new FactorialServerHandler());
}

From source file:com.hxr.javatone.concurrency.netty.official.factorial.FactorialClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Enable stream compression (you can remove these two if unnecessary)
    pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));

    // Add the number codec first,
    pipeline.addLast("decoder", new BigIntegerDecoder());
    pipeline.addLast("encoder", new NumberEncoder());

    // and then business logic.
    pipeline.addLast("handler", new FactorialClientHandler(count));
}