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,
        int lengthAdjustment, int initialBytesToStrip) 

Source Link

Document

Creates a new instance.

Usage

From source file:org.traccar.protocol.TzoneProtocol.java

License:Apache License

public TzoneProtocol() {
    addServer(new TrackerServer(false, getName()) {
        @Override/*from  w  w w .  java  2s .c o  m*/
        protected void addProtocolHandlers(PipelineBuilder pipeline) {
            pipeline.addLast(new LengthFieldBasedFrameDecoder(256, 2, 2, 2, 0));
            pipeline.addLast(new TzoneProtocolDecoder(TzoneProtocol.this));
        }
    });
}

From source file:org.traccar.protocol.WristbandProtocol.java

License:Apache License

public WristbandProtocol() {
    addServer(new TrackerServer(false, getName()) {
        @Override/*from w  w w.ja v  a 2 s .co  m*/
        protected void addProtocolHandlers(PipelineBuilder pipeline) {
            pipeline.addLast(new LengthFieldBasedFrameDecoder(1024, 3, 2, 3, 0));
            pipeline.addLast(new WristbandProtocolDecoder(WristbandProtocol.this));
        }
    });
}

From source file:org.vootoo.client.netty.SolrClientChannelPoolHandler.java

License:Apache License

protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("frame-decoder",
            new LengthFieldBasedFrameDecoder(handlerConfig.getMaxFrameLengthMB() * MB, 0, 4, 0, 4));
    pipeline.addLast("frame-encoder", new LengthFieldPrepender(4));

    pipeline.addLast("pb-decoder", new ProtobufDecoder(SolrProtocol.SolrResponse.getDefaultInstance()));
    pipeline.addLast("pb-encoder", new ProtobufEncoder());

    pipeline.addLast(SolrClientHandler.CLIENT_HANDLER_NAME,
            new SolrClientHandler(getResponsePromiseContainer()));
}

From source file:org.vootoo.server.netty.SolrServerChannelInitializer.java

License:Apache License

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("frame-decoder",
            new LengthFieldBasedFrameDecoder(handlerConfigs.getMaxFrameLength(), 0, 4, 0, 4));
    pipeline.addLast("frame-encoder", new LengthFieldPrepender(4));

    pipeline.addLast("pb-decoder", new ProtobufDecoder(SolrProtocol.SolrRequest.getDefaultInstance()));
    pipeline.addLast("pb-encoder", new ProtobufEncoder());

    pipeline.addLast(new SolrServerHandler(coreContainer, queryExecutor, updateExecutor));
}

From source file:pl.tcs.btppllib.CustomHandlers.java

public static LengthFieldBasedFrameDecoder getLengthFieldShortenDecoder() {
    return new LengthFieldBasedFrameDecoder(MAX_FRAME_LENGTH, 3, 1, 0, 4);
}

From source file:pl.tcs.btppllib.DeviceGetTimeTest.java

public static void main(String[] args) throws Exception {
    final String connectionStr = args[0];
    String[] connParams = connectionStr.split(":");

    String host = connParams[0];/*  w w  w  .j a  v a 2  s.co  m*/
    int port = Integer.parseInt(connParams[1]);
    log.info(String.format("***** Running test on host=%s and port=%d", host, port));

    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {
        Bootstrap b = new Bootstrap(); // (1)
        b.group(workerGroup); // (2)
        b.channel(NioSocketChannel.class); // (3)
        b.option(ChannelOption.SO_KEEPALIVE, true); // (4)
        b.option(ChannelOption.SO_TIMEOUT, 10000);
        //            b.option(ChannelOption.SO_REUSEADDR, true);
        b.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel c) throws Exception {
                ChannelPipeline pipeline = c.pipeline();
                pipeline.addLast("frameJoiner", new OcitMessageDecoder());
                pipeline.addLast("frameDecoder",
                        new LengthFieldBasedFrameDecoder(MAX_FRAME_LENGTH, 3, 1, 0, 4));
                //                    pipeline.addLast("frameJoiner", new OcitMessageDecoder());
                pipeline.addLast("timeHandler", new GetTimeTestHandler());
            }
        });

        ChannelFuture f = b.connect(host, port).sync(); // (5)

        Channel c = f.channel();
        c.writeAndFlush(buildGetTimeRequest()).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture f) throws Exception {
                if (f.isSuccess()) {
                    log.info("*** GetTime request sent with success!!!");
                } else {
                    log.error("*** ERROR when sending GetTime request");
                }
            }
        });

        //            c.closeFuture().sync();        

    } finally {
        //            workerGroup.shutdownGracefully();
    }
}

From source file:project1pbversion.cmpe275.sjsu.client.ClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();/*  w w  w  .  j  a  v  a  2 s. co  m*/

    p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
    //p.addLast(new ProtobufVarint32FrameDecoder());
    p.addLast(new ProtobufDecoder(ImagePB.Request.getDefaultInstance()));

    p.addLast("frameEncoder", new LengthFieldPrepender(4));
    //p.addLast(new ProtobufVarint32LengthFieldPrepender());
    p.addLast(new ProtobufEncoder());

    p.addLast(new ClientHandler());
}

From source file:project1pbversion.cmpe275.sjsu.master.backup.BackupMasterInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();//  w w w.jav  a2 s  .c  o m

    p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
    //p.addLast(new ProtobufVarint32FrameDecoder());
    //  p.addLast(new ProtobufDecoder(ImagePB.Heartbeat.getDefaultInstance()));
    p.addLast("protobufDecoder", new ProtobufDecoder(ImagePB.Heartbeat.getDefaultInstance()));
    p.addLast("frameEncoder", new LengthFieldPrepender(4));
    //p.addLast(new ProtobufVarint32LengthFieldPrepender());
    p.addLast(new ProtobufEncoder());

    p.addLast(new BackupMasterHandler());
}

From source file:project1pbversion.cmpe275.sjsu.othercluster.OtherClusterInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();//  ww w  . j ava 2 s .  com

    p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
    //p.addLast(new ProtobufVarint32FrameDecoder());
    p.addLast(new ProtobufDecoder(ImagePB.Request.getDefaultInstance()));

    p.addLast("frameEncoder", new LengthFieldPrepender(4));
    //p.addLast(new ProtobufVarint32LengthFieldPrepender());
    p.addLast(new ProtobufEncoder());

    p.addLast(new OtherClusterHandler());
}

From source file:uk.ac.lancs.stopcock.netty.OpenFlowChannelInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline pipeline = socketChannel.pipeline();

    /* Use Netty's prebuilt tools to handle frame separation on incoming data. */
    pipeline.addLast("lengthDecoder", new LengthFieldBasedFrameDecoder(OPENFLOW_MAXIMUM_FRAME, 2, 2, -4, 0));

    /* Process OpenFlow packets. */
    pipeline.addLast("openflowDecoder", new OpenFlowDecoder());
    pipeline.addLast("openflowEncoder", new OpenFlowEncoder());

    /* Idle Handler, prevent a hung switch or controller from disrupting traffic.  */
    pipeline.addLast("idleStateHandler", new IdleStateHandler(proxy.getIdleReadTimeout(),
            proxy.getIdleWriteTimeout(), 0, TimeUnit.MILLISECONDS));

    /* OpenFlow Processor. */
    if (downstream) {
        pipeline.addLast("messageHandler", new OpenFlowChannelInboundDownstreamHandler(proxy));
    } else {//  ww  w.j a  v a 2s .c  o m
        pipeline.addLast("messageHandler", new OpenFlowChannelInboundUpstreamHandler(proxy));
    }
}