List of usage examples for io.netty.channel ChannelOption SO_SNDBUF
ChannelOption SO_SNDBUF
To view the source code for io.netty.channel ChannelOption SO_SNDBUF.
Click Source Link
From source file:com.mc.netty.server.NettyServer.java
License:Open Source License
private ServerBootstrap getDefaultServerBootstrap() { ServerBootstrap bootStrap = new ServerBootstrap(); bootStrap.group(bossGroup, workerGroup).option(ChannelOption.SO_BACKLOG, 1000) // ??? .option(ChannelOption.SO_SNDBUF, 32 * 1024).option(ChannelOption.SO_RCVBUF, 32 * 1024) .option(ChannelOption.TCP_NODELAY, true) // ??? .option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT) .channel(NioServerSocketChannel.class).childOption(ChannelOption.SO_KEEPALIVE, true); return bootStrap; }
From source file:com.mongodb.connection.netty.NettyStream.java
License:Apache License
@Override public void openAsync(final AsyncCompletionHandler<Void> handler) { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(workerGroup);/*from www. ja va 2 s .c o m*/ bootstrap.channel(NioSocketChannel.class); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, settings.getConnectTimeout(MILLISECONDS)); bootstrap.option(ChannelOption.TCP_NODELAY, true); bootstrap.option(ChannelOption.SO_KEEPALIVE, settings.isKeepAlive()); if (settings.getReceiveBufferSize() > 0) { bootstrap.option(ChannelOption.SO_RCVBUF, settings.getReceiveBufferSize()); } if (settings.getSendBufferSize() > 0) { bootstrap.option(ChannelOption.SO_SNDBUF, settings.getSendBufferSize()); } bootstrap.option(ChannelOption.ALLOCATOR, allocator); bootstrap.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel ch) throws Exception { if (sslSettings.isEnabled()) { SSLEngine engine = SSLContext.getDefault().createSSLEngine(address.getHost(), address.getPort()); engine.setUseClientMode(true); if (!sslSettings.isInvalidHostNameAllowed()) { engine.setSSLParameters(enableHostNameVerification(engine.getSSLParameters())); } ch.pipeline().addFirst("ssl", new SslHandler(engine, false)); } ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(settings.getReadTimeout(MILLISECONDS), MILLISECONDS)); ch.pipeline().addLast(new InboundBufferHandler()); } }); final ChannelFuture channelFuture = bootstrap.connect(address.getHost(), address.getPort()); channelFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { channel = channelFuture.channel(); handler.completed(null); } else { handler.failed(future.cause()); } } }); }
From source file:com.moshi.receptionist.remoting.netty.NettyRemotingClient.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyClientConfig.getClientWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override//from www . j a v a 2 s . c o m public Thread newThread(Runnable r) { return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet()); } }); Bootstrap handler = this.bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class)// // .option(ChannelOption.TCP_NODELAY, true) // .option(ChannelOption.SO_SNDBUF, NettySystemConfig.SocketSndbufSize) // .option(ChannelOption.SO_RCVBUF, NettySystemConfig.SocketRcvbufSize) // .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(// defaultEventExecutorGroup, // new NettyEncoder(), // new NettyDecoder(), // new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()), // new NettyConnetManageHandler(), // new NettyClientHandler()); } }); // ?1?? this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRemotingClient.this.scanResponseTable(); } catch (Exception e) { log.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); if (this.channelEventListener != null) { this.nettyEventExecuter.start(); } }
From source file:com.moshi.receptionist.remoting.netty.NettyRemotingServer.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyServerConfig.getServerWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override//from ww w .jav a 2 s. com public Thread newThread(Runnable r) { return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroup, new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) // .option(ChannelOption.SO_BACKLOG, 1024) // .option(ChannelOption.SO_REUSEADDR, true) // .childOption(ChannelOption.TCP_NODELAY, true) // .childOption(ChannelOption.SO_SNDBUF, NettySystemConfig.SocketSndbufSize) // .childOption(ChannelOption.SO_RCVBUF, NettySystemConfig.SocketRcvbufSize) .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( // defaultEventExecutorGroup, // new NettyEncoder(), // new NettyDecoder(), // new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), // new NettyConnetManageHandler(), // new NettyServerHandler()); } }); if (NettySystemConfig.NettyPooledByteBufAllocatorEnable) { // ???? childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)// ; } try { ChannelFuture sync = this.serverBootstrap.bind().sync(); InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress(); this.port = addr.getPort(); } catch (InterruptedException e1) { throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1); } if (this.channelEventListener != null) { this.nettyEventExecuter.start(); } // ?1?? this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRemotingServer.this.scanResponseTable(); } catch (Exception e) { log.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); }
From source file:com.mpush.client.gateway.GatewayClient.java
License:Apache License
@Override protected void initOptions(Bootstrap b) { super.initOptions(b); if (snd_buf.gateway_client > 0) b.option(ChannelOption.SO_SNDBUF, snd_buf.gateway_client); if (rcv_buf.gateway_client > 0) b.option(ChannelOption.SO_RCVBUF, rcv_buf.gateway_client); }
From source file:com.mpush.client.gateway.GatewayUDPConnector.java
License:Apache License
@Override protected void initOptions(Bootstrap b) { super.initOptions(b); b.option(ChannelOption.IP_MULTICAST_LOOP_DISABLED, true); b.option(ChannelOption.IP_MULTICAST_TTL, 255); if (snd_buf.gateway_client > 0) b.option(ChannelOption.SO_SNDBUF, snd_buf.gateway_client); if (rcv_buf.gateway_client > 0) b.option(ChannelOption.SO_RCVBUF, rcv_buf.gateway_client); }
From source file:com.mpush.core.server.ConnectionServer.java
License:Apache License
@Override protected void initOptions(ServerBootstrap b) { super.initOptions(b); b.option(ChannelOption.SO_BACKLOG, 1024); /**// ww w . ja va 2 s .com * TCP???? * NettyChannelOptionSO_SNDBUFSO_RCVBUF * ????????32K? */ if (snd_buf.connect_server > 0) b.childOption(ChannelOption.SO_SNDBUF, snd_buf.connect_server); if (rcv_buf.connect_server > 0) b.childOption(ChannelOption.SO_RCVBUF, rcv_buf.connect_server); /** * ?????????? * ??????????????? * ???????? * ???????? * ?????? * ???NettyChannelOutboundBuffer * buffernetty?channel write?buffer???????(?channelbuffer) * ??32(32?)32? * ?(?TCP??) * ??buffer???(?swap?linux killer) * ?channel?channel?active? * * ChannelOutboundBuffer???? * buffer??channelisWritable??false * buffer??isWritable??trueisWritablefalse???? * ???64K?32K??????? */ b.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(connect_server_low, connect_server_high)); }
From source file:com.mpush.core.server.GatewayServer.java
License:Apache License
@Override protected void initOptions(ServerBootstrap b) { super.initOptions(b); if (snd_buf.gateway_server > 0) b.childOption(ChannelOption.SO_SNDBUF, snd_buf.gateway_server); if (rcv_buf.gateway_server > 0) b.childOption(ChannelOption.SO_RCVBUF, rcv_buf.gateway_server); /**/*w w w . ja v a2s . c om*/ * ?????????? * ??????????????? * ???????? * ???????? * ?????? * ???NettyChannelOutboundBuffer * buffernetty?channel write?buffer???????(?channelbuffer) * ??32(32?)32? * ?(?TCP??) * ??buffer???(?swap?linux killer) * ?channel?channel?active? * * ChannelOutboundBuffer???? * buffer??channelisWritable??false * buffer??isWritable??trueisWritablefalse???? * ???64K?32K??????? */ if (gateway_server_low > 0 && gateway_server_high > 0) { b.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(gateway_server_low, gateway_server_high)); } }
From source file:com.mpush.core.server.GatewayUDPConnector.java
License:Apache License
@Override protected void initOptions(Bootstrap b) { super.initOptions(b); b.option(ChannelOption.IP_MULTICAST_LOOP_DISABLED, true);//?????IP???IP_MULTICAST_LOOP???? b.option(ChannelOption.IP_MULTICAST_TTL, 255);//IP_MULTICAST_TTL?TTL0255 //b.option(ChannelOption.IP_MULTICAST_IF, null);//IP_MULTICAST_IF???????,?addr?IP?INADDR_ANY??? //b.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(32 * 1024, 1024 * 1024)); if (snd_buf.gateway_server > 0) b.option(ChannelOption.SO_SNDBUF, snd_buf.gateway_server); if (rcv_buf.gateway_server > 0) b.option(ChannelOption.SO_RCVBUF, rcv_buf.gateway_server); }
From source file:com.mpush.core.server.WebSocketServer.java
License:Apache License
@Override protected void initOptions(ServerBootstrap b) { super.initOptions(b); b.option(ChannelOption.SO_BACKLOG, 1024); b.childOption(ChannelOption.SO_SNDBUF, 32 * 1024); b.childOption(ChannelOption.SO_RCVBUF, 32 * 1024); }