Example usage for io.netty.handler.codec LengthFieldBasedFrameDecoder LengthFieldBasedFrameDecoder

List of usage examples for io.netty.handler.codec LengthFieldBasedFrameDecoder LengthFieldBasedFrameDecoder

Introduction

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

Prototype

public LengthFieldBasedFrameDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength) 

Source Link

Document

Creates a new instance.

Usage

From source file:com.hzmsc.scada.Jmtis.server.PortUnificationServerHandler.java

License:Apache License

private void switchToJMAC(ChannelHandlerContext ctx) {
    ChannelPipeline pipeline = ctx.pipeline();
    pipeline.addLast(new LengthFieldBasedFrameDecoder(1024, 4, 4));
    pipeline.addLast(new JmtisDecoder());

    pipeline.addLast(new JmtisHeaderEncoder());
    pipeline.addLast(new JmtisBodyEncoder());

    pipeline.addLast(new JmtisServerHandler());
    pipeline.remove(this);
}

From source file:com.spotify.ffwd.protobuf.ProtobufLengthPrefixedProtocolServer.java

License:Apache License

@Override
public final ChannelInitializer<Channel> initializer() {
    return new ChannelInitializer<Channel>() {
        @Override/*from  w w w .j a  v  a  2 s.c o m*/
        protected void initChannel(Channel ch) throws Exception {
            ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(MAX_LENGTH, 0, 4), decoder, handler);
        }
    };
}

From source file:com.spotify.ffwd.riemann.RiemannTCPProtocolClient.java

License:Apache License

@Override
public ChannelInitializer<Channel> initializer() {
    return new ChannelInitializer<Channel>() {
        @Override/*from   w w  w . j a va2 s.  c om*/
        protected void initChannel(Channel ch) throws Exception {
            final LengthFieldBasedFrameDecoder lengthPrefix = new LengthFieldBasedFrameDecoder(MAX_LENGTH, 0,
                    4);
            ch.pipeline().addLast(lengthPrefix, receiver, sender);
        }
    };
}

From source file:de.jackwhite20.cascade.shared.pipeline.initialize.CascadeChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {

    ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    ch.pipeline().addLast(new PacketDecoder(protocol));
    ch.pipeline().addLast(new LengthFieldPrepender(4));
    ch.pipeline().addLast(new PacketEncoder(protocol));
    ch.pipeline().addLast(new CascadeSession(ch, protocol, sessionListener));
}

From source file:de.jackwhite20.japs.server.network.initialize.ClusterPublisherChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(Channel channel) throws Exception {

    try {//www  . j  a v a2  s .  com
        channel.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported
    }
    channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    channel.pipeline().addLast(new JSONObjectDecoder());
    channel.pipeline().addLast(new LengthFieldPrepender(4));
    channel.pipeline().addLast(new JSONObjectEncoder());
    channel.pipeline().addLast(clusterPublisher);
}

From source file:de.jackwhite20.japs.server.network.initialize.ServerChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(Channel channel) throws Exception {

    try {/* w  w w . j  ava 2  s  .  c o  m*/
        channel.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported
    }
    channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    channel.pipeline().addLast(new JSONObjectDecoder());
    channel.pipeline().addLast(new LengthFieldPrepender(4));
    channel.pipeline().addLast(new JSONObjectEncoder());
    channel.pipeline().addLast(new Connection(jaPSServer, channel));
}

From source file:de.jackwhite20.japs.shared.pipeline.initialize.ClientChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(Channel channel) throws Exception {

    try {/*ww w .jav a2  s.c om*/
        channel.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported
    }
    channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    channel.pipeline().addLast(new JSONObjectDecoder());
    channel.pipeline().addLast(new LengthFieldPrepender(4));
    channel.pipeline().addLast(new JSONObjectEncoder());
    channel.pipeline().addLast(nioSocketClient);
}

From source file:io.pravega.client.netty.impl.ConnectionFactoryImpl.java

License:Open Source License

@Override
public CompletableFuture<ClientConnection> establishConnection(PravegaNodeUri location, ReplyProcessor rp) {
    Preconditions.checkNotNull(location);
    Exceptions.checkNotClosed(closed.get(), this);
    final SslContext sslCtx;
    if (ssl) {/*from   w ww .j a  v a2  s  .c o m*/
        try {
            sslCtx = SslContextBuilder.forClient().trustManager(FingerprintTrustManagerFactory
                    .getInstance(FingerprintTrustManagerFactory.getDefaultAlgorithm())).build();
        } catch (SSLException | NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    } else {
        sslCtx = null;
    }
    AppendBatchSizeTracker batchSizeTracker = new AppendBatchSizeTrackerImpl();
    ClientConnectionInboundHandler handler = new ClientConnectionInboundHandler(location.getEndpoint(), rp,
            batchSizeTracker);
    Bootstrap b = new Bootstrap();
    b.group(group).channel(nio ? NioSocketChannel.class : EpollSocketChannel.class)
            .option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    if (sslCtx != null) {
                        p.addLast(sslCtx.newHandler(ch.alloc(), location.getEndpoint(), location.getPort()));
                    }
                    // p.addLast(new LoggingHandler(LogLevel.INFO));
                    p.addLast(new ExceptionLoggingHandler(location.getEndpoint()),
                            new CommandEncoder(batchSizeTracker),
                            new LengthFieldBasedFrameDecoder(WireCommands.MAX_WIRECOMMAND_SIZE, 4, 4),
                            new CommandDecoder(), handler);
                }
            });

    // Start the client.
    CompletableFuture<ClientConnection> result = new CompletableFuture<>();
    try {
        b.connect(location.getEndpoint(), location.getPort()).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) {
                if (future.isSuccess()) {
                    result.complete(handler);
                } else {
                    result.completeExceptionally(future.cause());
                }
            }
        });
    } catch (Exception e) {
        result.completeExceptionally(e);
    }
    return result;
}

From source file:io.pravega.segmentstore.server.host.handler.PravegaConnectionListener.java

License:Open Source License

public void startListening() {
    // Configure SSL.
    final SslContext sslCtx;
    if (ssl) {//  www  . j  av  a  2 s.co  m
        try {
            SelfSignedCertificate ssc = new SelfSignedCertificate();
            sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
        } catch (CertificateException | SSLException e) {
            throw new RuntimeException(e);
        }
    } else {
        sslCtx = null;
    }
    boolean nio = false;
    try {
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup();
    } catch (ExceptionInInitializerError | NoClassDefFoundError e) {
        nio = true;
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();
    }

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(nio ? NioServerSocketChannel.class : EpollServerSocketChannel.class)
            .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    if (sslCtx != null) {
                        p.addLast(sslCtx.newHandler(ch.alloc()));
                    }
                    ServerConnectionInboundHandler lsh = new ServerConnectionInboundHandler();
                    // p.addLast(new LoggingHandler(LogLevel.INFO));
                    p.addLast(new ExceptionLoggingHandler(ch.remoteAddress().toString()),
                            new CommandEncoder(null),
                            new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4), new CommandDecoder(),
                            new AppendDecoder(), lsh);
                    lsh.setRequestProcessor(new AppendProcessor(store, lsh,
                            new PravegaRequestProcessor(store, lsh, statsRecorder), statsRecorder));
                }
            });

    // Start the server.
    serverChannel = b.bind(host, port).awaitUninterruptibly().channel();
}

From source file:io.pravega.test.integration.AppendTest.java

License:Open Source License

static EmbeddedChannel createChannel(StreamSegmentStore store) {
    ServerConnectionInboundHandler lsh = new ServerConnectionInboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(new ExceptionLoggingHandler(""), new CommandEncoder(null),
            new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4), new CommandDecoder(),
            new AppendDecoder(), lsh);
    lsh.setRequestProcessor(new AppendProcessor(store, lsh, new PravegaRequestProcessor(store, lsh)));
    return channel;
}