Search in sources :

Example 1 with SnappyFramedDecoder

use of io.netty.handler.codec.compression.SnappyFramedDecoder in project jackrabbit-oak by apache.

the class StandbyClient method connect.

void connect(String host, int port) throws Exception {
    final SslContext sslContext;
    if (secure) {
        sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslContext = null;
    }
    Bootstrap b = new Bootstrap().group(group).channel(NioSocketChannel.class).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, readTimeoutMs).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_KEEPALIVE, true).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            if (sslContext != null) {
                p.addLast(sslContext.newHandler(ch.alloc()));
            }
            p.addLast(new ReadTimeoutHandler(readTimeoutMs, TimeUnit.MILLISECONDS));
            // Decoders
            p.addLast(new SnappyFramedDecoder(true));
            // Such a big max frame length is needed because blob
            // values are sent in one big message. In future
            // versions of the protocol, sending binaries in chunks
            // should be considered instead.
            p.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
            p.addLast(new ResponseDecoder());
            // Encoders
            p.addLast(new StringEncoder(CharsetUtil.UTF_8));
            p.addLast(new GetHeadRequestEncoder());
            p.addLast(new GetSegmentRequestEncoder());
            p.addLast(new GetBlobRequestEncoder());
            p.addLast(new GetReferencesRequestEncoder());
            // Handlers
            p.addLast(new GetHeadResponseHandler(headQueue));
            p.addLast(new GetSegmentResponseHandler(segmentQueue));
            p.addLast(new GetBlobResponseHandler(blobQueue));
            p.addLast(new GetReferencesResponseHandler(referencesQueue));
            // Exception handler
            p.addLast(new ExceptionHandler(clientId));
        }
    });
    channel = b.connect(host, port).sync().channel();
}
Also used : GetReferencesRequestEncoder(org.apache.jackrabbit.oak.segment.standby.codec.GetReferencesRequestEncoder) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) GetSegmentRequestEncoder(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequestEncoder) ChannelPipeline(io.netty.channel.ChannelPipeline) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) StringEncoder(io.netty.handler.codec.string.StringEncoder) ResponseDecoder(org.apache.jackrabbit.oak.segment.standby.codec.ResponseDecoder) GetBlobRequestEncoder(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequestEncoder) GetHeadRequestEncoder(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequestEncoder) Bootstrap(io.netty.bootstrap.Bootstrap) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) SnappyFramedDecoder(io.netty.handler.codec.compression.SnappyFramedDecoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)1 SnappyFramedDecoder (io.netty.handler.codec.compression.SnappyFramedDecoder)1 StringEncoder (io.netty.handler.codec.string.StringEncoder)1 SslContext (io.netty.handler.ssl.SslContext)1 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)1 GetBlobRequestEncoder (org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequestEncoder)1 GetHeadRequestEncoder (org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequestEncoder)1 GetReferencesRequestEncoder (org.apache.jackrabbit.oak.segment.standby.codec.GetReferencesRequestEncoder)1 GetSegmentRequestEncoder (org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequestEncoder)1 ResponseDecoder (org.apache.jackrabbit.oak.segment.standby.codec.ResponseDecoder)1