Example usage for io.netty.channel ChannelOption SO_RCVBUF

List of usage examples for io.netty.channel ChannelOption SO_RCVBUF

Introduction

In this page you can find the example usage for io.netty.channel ChannelOption SO_RCVBUF.

Prototype

ChannelOption SO_RCVBUF

To view the source code for io.netty.channel ChannelOption SO_RCVBUF.

Click Source Link

Usage

From source file:com.barchart.netty.server.base.AbstractStatefulServer.java

License:BSD License

@Override
protected ServerBootstrap bootstrap() {

    final ServerBootstrap bootstrap = new ServerBootstrap() //
            .group(defaultGroup, childGroup) //
            .channel(channelType) //
            .childHandler(new ServerChannelInitializer()) //
            .option(ChannelOption.SO_REUSEADDR, true) //
            .option(ChannelOption.SO_SNDBUF, 262144) //
            .option(ChannelOption.SO_RCVBUF, 262144) //
            .childOption(ChannelOption.SO_SNDBUF, 262144) //
            .childOption(ChannelOption.SO_RCVBUF, 262144);

    if (bootstrapInit != null) {
        bootstrapInit.initBootstrap(bootstrap);
    }//w  w  w . ja v  a  2 s.  c  o m

    return bootstrap;

}

From source file:com.barchart.netty.server.stream.MulticastTransceiver.java

License:BSD License

@Override
protected Bootstrap bootstrap() {

    final Bootstrap bootstrap = new Bootstrap() //
            .group(defaultGroup) //
            .channel(NioDatagramChannel.class) //
            .handler(new ServerChannelInitializer()) //
            .option(ChannelOption.SO_REUSEADDR, true) //
            .option(ChannelOption.IP_MULTICAST_TTL, 3) //
            .option(ChannelOption.SO_SNDBUF, 262144) //
            .option(ChannelOption.SO_RCVBUF, 262144);

    if (bootstrapInit != null) {
        bootstrapInit.initBootstrap(bootstrap);
    }//from   w  w w .jav a  2s .  c o m

    return bootstrap;

}

From source file:com.barchart.netty.server.stream.UnicastTransceiver.java

License:BSD License

@Override
protected Bootstrap bootstrap() {

    final Bootstrap bootstrap = new Bootstrap() //
            .group(defaultGroup) //
            .channel(NioDatagramChannel.class) //
            .handler(new ServerChannelInitializer()) //
            .remoteAddress(remote) //
            .option(ChannelOption.SO_REUSEADDR, true) //
            .option(ChannelOption.IP_MULTICAST_TTL, 3) //
            .option(ChannelOption.SO_SNDBUF, 262144) //
            .option(ChannelOption.SO_RCVBUF, 262144);

    if (bootstrapInit != null) {
        bootstrapInit.initBootstrap(bootstrap);
    }//from w ww .  j a v a 2  s  .  c  o m

    return bootstrap;

}

From source file:com.comphenix.protocol.compat.netty.independent.NettySocketAdapter.java

License:Open Source License

@Override
public synchronized int getReceiveBufferSize() throws SocketException {
    return ch.config().getOption(ChannelOption.SO_RCVBUF);
}

From source file:com.comphenix.protocol.compat.netty.independent.NettySocketAdapter.java

License:Open Source License

@Override
public synchronized void setReceiveBufferSize(int size) throws SocketException {
    ch.config().setOption(ChannelOption.SO_RCVBUF, size);
}

From source file:com.corundumstudio.socketio.SocketIOServer.java

License:Apache License

protected void applyConnectionOptions(ServerBootstrap bootstrap) {
    SocketConfig config = configCopy.getSocketConfig();
    bootstrap.childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay());
    if (config.getTcpSendBufferSize() != -1) {
        bootstrap.childOption(ChannelOption.SO_SNDBUF, config.getTcpSendBufferSize());
    }/*from w w w .j av a 2s  . c  o  m*/
    if (config.getTcpReceiveBufferSize() != -1) {
        bootstrap.childOption(ChannelOption.SO_RCVBUF, config.getTcpReceiveBufferSize());
        bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR,
                new FixedRecvByteBufAllocator(config.getTcpReceiveBufferSize()));
    }
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive());

    bootstrap.option(ChannelOption.SO_LINGER, config.getSoLinger());
    bootstrap.option(ChannelOption.SO_REUSEADDR, config.isReuseAddress());
    bootstrap.option(ChannelOption.SO_BACKLOG, config.getAcceptBackLog());
}

From source file:com.dinstone.jrpc.transport.netty4.NettyAcceptance.java

License:Apache License

@Override
public Acceptance bind() {
    bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("N4A-Boss"));
    workGroup = new NioEventLoopGroup(transportConfig.getNioProcessorCount(),
            new DefaultThreadFactory("N4A-Work"));

    ServerBootstrap boot = new ServerBootstrap().group(bossGroup, workGroup);
    boot.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override/*from w w  w  .  ja  v  a2 s  .  co  m*/
        public void initChannel(SocketChannel ch) throws Exception {
            TransportProtocolDecoder decoder = new TransportProtocolDecoder();
            decoder.setMaxObjectSize(transportConfig.getMaxSize());
            TransportProtocolEncoder encoder = new TransportProtocolEncoder();
            encoder.setMaxObjectSize(transportConfig.getMaxSize());
            ch.pipeline().addLast("TransportProtocolDecoder", decoder);
            ch.pipeline().addLast("TransportProtocolEncoder", encoder);

            int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
            ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(intervalSeconds * 2, 0, 0));
            ch.pipeline().addLast("NettyServerHandler", new NettyServerHandler());
        }
    });
    boot.option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_BACKLOG, 128);
    boot.childOption(ChannelOption.SO_RCVBUF, 16 * 1024).childOption(ChannelOption.SO_SNDBUF, 16 * 1024)
            .childOption(ChannelOption.TCP_NODELAY, true);

    try {
        boot.bind(serviceAddress).sync();

        int processorCount = transportConfig.getBusinessProcessorCount();
        if (processorCount > 0) {
            NamedThreadFactory threadFactory = new NamedThreadFactory("N4A-BusinessProcessor");
            executorService = Executors.newFixedThreadPool(processorCount, threadFactory);
        }
    } catch (Exception e) {
        throw new RuntimeException("can't bind service on " + serviceAddress, e);
    }
    LOG.info("netty acceptance bind on {}", serviceAddress);

    return this;
}

From source file:com.dinstone.jrpc.transport.netty4.NettyConnector.java

License:Apache License

public NettyConnector(InetSocketAddress isa, final TransportConfig transportConfig) {
    workerGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("N4C-Work"));
    clientBoot = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class);
    clientBoot.option(ChannelOption.TCP_NODELAY, true);
    clientBoot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, transportConfig.getConnectTimeout());
    clientBoot.option(ChannelOption.SO_RCVBUF, 8 * 1024).option(ChannelOption.SO_SNDBUF, 8 * 1024);
    clientBoot.handler(new ChannelInitializer<SocketChannel>() {

        @Override/*from www.ja v a2 s . co m*/
        public void initChannel(SocketChannel ch) throws Exception {
            TransportProtocolDecoder decoder = new TransportProtocolDecoder();
            decoder.setMaxObjectSize(transportConfig.getMaxSize());
            TransportProtocolEncoder encoder = new TransportProtocolEncoder();
            encoder.setMaxObjectSize(transportConfig.getMaxSize());
            ch.pipeline().addLast("TransportProtocolDecoder", decoder);
            ch.pipeline().addLast("TransportProtocolEncoder", encoder);

            int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
            ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(0, intervalSeconds, 0));
            ch.pipeline().addLast("NettyClientHandler", new NettyClientHandler());
        }
    });

    clientBoot.remoteAddress(isa);
}

From source file:com.dinstone.jrpc.transport.netty5.NettyAcceptance.java

License:Apache License

@Override
public Acceptance bind() {
    bossGroup = new NioEventLoopGroup(1, new DefaultExecutorServiceFactory("N5A-Boss"));
    workGroup = new NioEventLoopGroup(transportConfig.getNioProcessorCount(),
            new DefaultExecutorServiceFactory("N5A-Work"));

    ServerBootstrap boot = new ServerBootstrap();
    boot.group(bossGroup, workGroup).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {

                @Override//from ww  w.j a v a  2s .  c om
                public void initChannel(SocketChannel ch) throws Exception {
                    TransportProtocolDecoder decoder = new TransportProtocolDecoder();
                    decoder.setMaxObjectSize(transportConfig.getMaxSize());
                    TransportProtocolEncoder encoder = new TransportProtocolEncoder();
                    encoder.setMaxObjectSize(transportConfig.getMaxSize());
                    ch.pipeline().addLast("TransportProtocolDecoder", decoder);
                    ch.pipeline().addLast("TransportProtocolEncoder", encoder);

                    int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
                    ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(intervalSeconds * 2, 0, 0));
                    ch.pipeline().addLast("NettyServerHandler", new NettyServerHandler());
                }
            });
    boot.option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_BACKLOG, 128);
    boot.childOption(ChannelOption.SO_RCVBUF, 16 * 1024).childOption(ChannelOption.SO_SNDBUF, 16 * 1024)
            .childOption(ChannelOption.TCP_NODELAY, true);

    try {
        boot.bind(serviceAddress).sync();

        int processorCount = transportConfig.getBusinessProcessorCount();
        if (processorCount > 0) {
            NamedThreadFactory threadFactory = new NamedThreadFactory("N5A-BusinssProcessor");
            executorService = Executors.newFixedThreadPool(processorCount, threadFactory);
        }
    } catch (Exception e) {
        throw new RuntimeException("can't bind service on " + serviceAddress, e);
    }
    LOG.info("netty5 acceptance bind on {}", serviceAddress);

    return this;
}

From source file:com.dinstone.jrpc.transport.netty5.NettyConnector.java

License:Apache License

public NettyConnector(InetSocketAddress isa, final TransportConfig transportConfig) {
    workerGroup = new NioEventLoopGroup(1, new DefaultExecutorServiceFactory("N5C-Work"));
    clientBoot = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class);
    clientBoot.option(ChannelOption.TCP_NODELAY, true);
    clientBoot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, transportConfig.getConnectTimeout());
    clientBoot.option(ChannelOption.SO_RCVBUF, 8 * 1024).option(ChannelOption.SO_SNDBUF, 8 * 1024);
    clientBoot.handler(new ChannelInitializer<SocketChannel>() {

        @Override/*from ww w.j  a v a2s .  c om*/
        public void initChannel(SocketChannel ch) throws Exception {
            TransportProtocolDecoder decoder = new TransportProtocolDecoder();
            decoder.setMaxObjectSize(transportConfig.getMaxSize());
            TransportProtocolEncoder encoder = new TransportProtocolEncoder();
            encoder.setMaxObjectSize(transportConfig.getMaxSize());
            ch.pipeline().addLast("TransportProtocolDecoder", decoder);
            ch.pipeline().addLast("TransportProtocolEncoder", encoder);

            int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
            ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(0, intervalSeconds, 0));
            ch.pipeline().addLast("NettyClientHandler", new NettyClientHandler());
        }
    });

    clientBoot.remoteAddress(isa);
}