Example usage for io.netty.handler.codec.marshalling MarshallingDecoder MarshallingDecoder

List of usage examples for io.netty.handler.codec.marshalling MarshallingDecoder MarshallingDecoder

Introduction

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

Prototype

public MarshallingDecoder(UnmarshallerProvider provider) 

Source Link

Document

Creates a new decoder whose maximum object size is 1048576 bytes.

Usage

From source file:github.com.cp149.netty.server.NettyappenderServer.java

License:Apache License

public void run() throws Exception {

    try {/*  www .  j  a v a2 s. c om*/
        bootstrap = new ServerBootstrap();
        final EventExecutorGroup executor = new DefaultEventExecutorGroup(4);

        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childOption(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.SO_RCVBUF, 65535).childOption(ChannelOption.SO_SNDBUF, 2048)
                .childOption(ChannelOption.SO_REUSEADDR, true) //reuse address
                .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(false))// heap buf 's better               
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        //                     ch.pipeline().addLast( new MarshallingEncoder(MarshallUtil.createProvider()));
                        //                     ch.pipeline().addLast(new CompatibleObjectDecoder());
                        //                     ch.pipeline().addLast(new ObjectEncoder(),
                        //                                  new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
                        ch.pipeline().addLast(new MarshallingDecoder(MarshallUtil.createUnProvider()));

                        ch.pipeline().addLast(executor, new NettyappenderServerHandler());
                        //
                    }
                });

        bootstrap.bind(port).sync();

    } finally {

    }
    // bootstrap = new ServerBootstrap(new
    // NioServerSocketChannelFactory(Executors.newFixedThreadPool(4),
    // Executors.newFixedThreadPool(4)));
    // final ExecutionHandler executionHandler = new ExecutionHandler(new
    // OrderedMemoryAwareThreadPoolExecutor(4, 1024 * 1024 * 300, 1024 *
    // 1024 * 300 * 2));
    // bootstrap.setOption("tcpNoDelay", true);
    // bootstrap.setOption("keepAlive", true);
    // // bootstrap.setOption("writeBufferHighWaterMark", 100 * 64 * 1024);
    // // bootstrap.setOption("sendBufferSize", 1048576);
    // bootstrap.setOption("receiveBufferSize", 1048576*10 );
    //
    // // Set up the pipeline factory.
    // bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    // public ChannelPipeline getPipeline() throws Exception {
    // return Channels.pipeline(executionHandler, new
    // MarshallingDecoder(createProvider(createMarshallerFactory(),
    // createMarshallingConfig())),
    // new NettyappenderServerHandler());
    // }
    // });

    // // Bind and start to accept incoming connections.
    // bootstrap.bind(new InetSocketAddress(port));
    //       LoggerFactory.getLogger(this.getClass()).info("start server at" +
    //             port);
}