List of usage examples for io.netty.channel ChannelOption SO_RCVBUF
ChannelOption SO_RCVBUF
To view the source code for io.netty.channel ChannelOption SO_RCVBUF.
Click Source Link
From source file:darks.grid.network.GridMessageClient.java
License:Apache License
@Override public boolean initialize() { super.initialize(); try {// ww w.j av a 2 s. c om log.info("Initialize message client."); NetworkConfig config = GridRuntime.config().getNetworkConfig(); int workerNum = config.getClientWorkerThreadNumber(); workerGroup = new NioEventLoopGroup(workerNum, ThreadUtils.getThreadFactory()); bootstrap = new Bootstrap(); bootstrap.group(workerGroup).channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, config.isTcpNodelay()) .option(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive()) .option(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)) // .option(ChannelOption.SO_TIMEOUT, config.getRecvTimeout()) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout()) .option(ChannelOption.SO_SNDBUF, config.getTcpSendBufferSize()) .option(ChannelOption.SO_RCVBUF, config.getTcpRecvBufferSize()); bootstrap.handler(newChannelHandler()); return true; } catch (Exception e) { log.error(e.getMessage(), e); return false; } }
From source file:darks.grid.network.GridMessageServer.java
License:Apache License
@Override public boolean initialize() { try {//from w w w . j a v a2 s . co m NetworkConfig config = GridRuntime.config().getNetworkConfig(); int bossNum = Runtime.getRuntime().availableProcessors() * config.getServerBossThreadDelta(); int workerNum = config.getServerWorkerThreadNumber(); bossGroup = new NioEventLoopGroup(bossNum); workerGroup = new NioEventLoopGroup(workerNum); super.initialize(); bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, config.isTcpNodelay()) .option(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive()) .option(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)) // .option(ChannelOption.SO_TIMEOUT, config.getRecvTimeout()) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout()) .option(ChannelOption.SO_REUSEADDR, config.isTcpReuseAddr()) // .option(ChannelOption.SO_BACKLOG, config.getTcpBacklog()) .option(ChannelOption.SO_SNDBUF, config.getTcpSendBufferSize()) .option(ChannelOption.SO_RCVBUF, config.getTcpRecvBufferSize()) .childOption(ChannelOption.TCP_NODELAY, config.isTcpNodelay()) .childOption(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive()) .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)) .childOption(ChannelOption.SO_TIMEOUT, config.getRecvTimeout()) .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout()) .childOption(ChannelOption.SO_REUSEADDR, config.isTcpReuseAddr()) .childOption(ChannelOption.SO_BACKLOG, config.getTcpBacklog()) .childOption(ChannelOption.SO_SNDBUF, config.getTcpSendBufferSize()) .childOption(ChannelOption.SO_RCVBUF, config.getTcpRecvBufferSize()); bootstrap.childHandler(newChannelHandler()); return true; } catch (Exception e) { log.error(e.getMessage(), e); return false; } }
From source file:eu.xworlds.util.raknet.RaknetServer.java
License:Open Source License
/** * Hidden constructor.//w ww. j a v a 2 s.c o m * * @param addresses * the addresses to bind to. * @param serverListeners * the listeners. * @param recvBuffer * the recv buffer size. * @param sendBuffer * the send buffer size. * @param sGroup * the sender nio group. * @param rGroup * the receiver nio group. * @param sessionReadTimeout * the raknet session read timeout in milliseconds * @param pFactories * the factories to create additional raknet pipeline handlers * @param hFactories * the factories to register additional raknet message handlers * @param mFactories * the factories to register additional raknet message classes */ RaknetServer(InetSocketAddress[] addresses, RaknetServerListener[] serverListeners, int recvBuffer, int sendBuffer, NioEventLoopGroup sGroup, NioEventLoopGroup rGroup, int sessionReadTimeout, RaknetPipelineFactory[] pFactories, RaknetMessageFactory[] mFactories, RaknetHandlerFactory[] hFactories) { // this.addresses = addresses; this.serverListeners = serverListeners; this.recvBuffer = recvBuffer; this.sendBuffer = sendBuffer; this.senderGroup = sGroup; this.receiverGroup = rGroup; this.pipelineFactories = pFactories; this.handlerFactories = hFactories; this.messageFactories = mFactories; this.sessions = CacheBuilder.newBuilder().maximumSize(1000). // TODO read from builder expireAfterAccess(sessionReadTimeout, TimeUnit.MILLISECONDS) .removalListener(new SessionRemovalListener()).build(new SessionCacheLoader()); final Bootstrap b = new Bootstrap(); b.group(this.receiverGroup).channel(NioDatagramChannel.class) .option(ChannelOption.SO_REUSEADDR, Boolean.TRUE) .option(ChannelOption.SO_RCVBUF, Integer.valueOf(this.recvBuffer)) .option(ChannelOption.SO_SNDBUF, Integer.valueOf(this.sendBuffer)) .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(this.recvBuffer)) .handler(new RaknetInitializer()); for (final InetSocketAddress address : addresses) { this.listenFutures.add(b.bind(address).addListener(new BindListener())); } }
From source file:github.com.cp149.netty.server.NettyappenderServer.java
License:Apache License
public void run() throws Exception { try {/*w ww . j av a2 s .com*/ 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); }
From source file:io.advantageous.conekt.http.impl.HttpClientImpl.java
License:Open Source License
private void applyConnectionOptions(Bootstrap bootstrap) { bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }//from w w w . ja v a 2 s .co m if (options.getReceiveBufferSize() != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout()); bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); }
From source file:io.advantageous.conekt.http.impl.HttpServerImpl.java
License:Open Source License
private void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }// ww w . j av a 2s. c om if (options.getReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.childOption(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getAcceptBacklog() != -1) { bootstrap.option(ChannelOption.SO_BACKLOG, options.getAcceptBacklog()); } }
From source file:io.advantageous.conekt.net.impl.NetClientImpl.java
License:Open Source License
private void applyConnectionOptions(Bootstrap bootstrap) { bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }//from w w w . j ava 2 s. c o m if (options.getReceiveBufferSize() != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout()); bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); }
From source file:io.advantageous.conekt.net.impl.NetServerImpl.java
License:Open Source License
private void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }// www. ja v a 2 s .c om if (options.getReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.childOption(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getAcceptBacklog() != -1) { bootstrap.option(ChannelOption.SO_BACKLOG, options.getAcceptBacklog()); } }
From source file:io.atomix.catalyst.transport.netty.NettyClient.java
License:Apache License
@Override public CompletableFuture<Connection> connect(Address address) { Assert.notNull(address, "address"); ThreadContext context = ThreadContext.currentContextOrThrow(); CompletableFuture<Connection> future = new ComposableFuture<>(); LOGGER.info("Connecting to {}", address); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(transport.eventLoopGroup()).channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override//from www . java 2 s .c o m protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); if (transport.properties().sslEnabled()) { pipeline.addFirst( new SslHandler(new NettyTls(transport.properties()).initSslEngine(true))); } pipeline.addLast(FIELD_PREPENDER); pipeline.addLast(new LengthFieldBasedFrameDecoder(transport.properties().maxFrameSize(), 0, 4, 0, 4)); pipeline.addLast( new NettyHandler(connections, future::complete, context, transport.properties())); } }); bootstrap.option(ChannelOption.TCP_NODELAY, transport.properties().tcpNoDelay()); bootstrap.option(ChannelOption.SO_KEEPALIVE, transport.properties().tcpKeepAlive()); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, transport.properties().connectTimeout()); bootstrap.option(ChannelOption.ALLOCATOR, ALLOCATOR); if (transport.properties().sendBufferSize() != -1) { bootstrap.option(ChannelOption.SO_SNDBUF, transport.properties().sendBufferSize()); } if (transport.properties().receiveBufferSize() != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, transport.properties().receiveBufferSize()); } bootstrap.connect(address.socketAddress()).addListener(channelFuture -> { if (channelFuture.isSuccess()) { LOGGER.info("Connected to {}", address); } else { context.execute(() -> future.completeExceptionally(channelFuture.cause())); } }); return future; }
From source file:io.atomix.catalyst.transport.netty.NettyServer.java
License:Apache License
/** * Starts listening for the given member. *///from w w w .j a v a 2 s. co m private void listen(Address address, Consumer<Connection> listener, ThreadContext context) { channelGroup = new DefaultChannelGroup("catalyst-acceptor-channels", GlobalEventExecutor.INSTANCE); handler = new ServerHandler(connections, listener, context, transport.properties()); final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(transport.eventLoopGroup()).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); if (transport.properties().sslEnabled()) { pipeline.addFirst( new SslHandler(new NettyTls(transport.properties()).initSslEngine(false))); } pipeline.addLast(FIELD_PREPENDER); pipeline.addLast(new LengthFieldBasedFrameDecoder(transport.properties().maxFrameSize(), 0, 4, 0, 4)); pipeline.addLast(handler); } }).option(ChannelOption.SO_BACKLOG, transport.properties().acceptBacklog()) .option(ChannelOption.TCP_NODELAY, transport.properties().tcpNoDelay()) .option(ChannelOption.SO_REUSEADDR, transport.properties().reuseAddress()) .childOption(ChannelOption.ALLOCATOR, ALLOCATOR) .childOption(ChannelOption.SO_KEEPALIVE, transport.properties().tcpKeepAlive()); if (transport.properties().sendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, transport.properties().sendBufferSize()); } if (transport.properties().receiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, transport.properties().receiveBufferSize()); } LOGGER.info("Binding to {}", address); ChannelFuture bindFuture = bootstrap.bind(address.socketAddress()); bindFuture.addListener((ChannelFutureListener) channelFuture -> { if (channelFuture.isSuccess()) { listening = true; context.executor().execute(() -> { LOGGER.info("Listening at {}", bindFuture.channel().localAddress()); listenFuture.complete(null); }); } else { context.execute(() -> listenFuture.completeExceptionally(channelFuture.cause())); } }); channelGroup.add(bindFuture.channel()); }