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:NettyHttpListner.java
License:Apache License
public void start() { System.out.println("Starting the server..."); System.out.println("Starting Inbound Http Listner on Port " + this.port); // Configure SSL. SslContext sslCtx = null;/*w w w . ja v a 2s . co m*/ if (SSL) { try { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); } catch (CertificateException ex) { Logger.getLogger(NettyHttpListner.class.getName()).log(Level.SEVERE, null, ex); } catch (SSLException ex) { Logger.getLogger(NettyHttpListner.class.getName()).log(Level.SEVERE, null, ex); } } commonEventLoopGroup = new NioEventLoopGroup(bossGroupSize); // bossGroup = new NioEventLoopGroup(bossGroupSize); // workerGroup = new NioEventLoopGroup(workerGroupSize); try { ServerBootstrap b = new ServerBootstrap(); // b.commonEventLoopGroup(bossGroup, workerGroup) b.group(commonEventLoopGroup).channel(NioServerSocketChannel.class) .childHandler( new NettyHttpTransportHandlerInitializer(HOST, HOST_PORT, maxConnectionsQueued, sslCtx)) .childOption(ChannelOption.AUTO_READ, false); b.option(ChannelOption.TCP_NODELAY, true); b.childOption(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_BACKLOG, maxConnectionsQueued); b.option(ChannelOption.SO_KEEPALIVE, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000); b.option(ChannelOption.SO_SNDBUF, 1048576); b.option(ChannelOption.SO_RCVBUF, 1048576); b.childOption(ChannelOption.SO_RCVBUF, 1048576); b.childOption(ChannelOption.SO_SNDBUF, 1048576); b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); Channel ch = null; try { ch = b.bind(port).sync().channel(); ch.closeFuture().sync(); System.out.println("Inbound Listner Started"); } catch (InterruptedException e) { System.out.println("Exception caught"); } } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:NettyHttpTransportSourceHandler.java
License:Apache License
/** * activating registered handler to accept events. * * @param ctx//from w w w. j a v a 2 s .c o m * @throws Exception */ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { final Channel inboundChannel = ctx.channel(); Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()).channel(ctx.channel().getClass()); b.handler(new NettyTargetHandlerInitilizer(inboundChannel)).option(ChannelOption.AUTO_READ, false); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000); b.option(ChannelOption.SO_SNDBUF, 1048576); b.option(ChannelOption.SO_RCVBUF, 1048576); ChannelFuture f = b.connect(NettyHttpListner.HOST, NettyHttpListner.HOST_PORT); outboundChannel = f.channel(); f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { // connection complete start to read first data inboundChannel.read(); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
From source file:alluxio.worker.netty.NettyDataServer.java
License:Apache License
private ServerBootstrap createBootstrap() { final ServerBootstrap boot = createBootstrapOfType( Configuration.getEnum(PropertyKey.WORKER_NETWORK_NETTY_CHANNEL, ChannelType.class)); // use pooled buffers boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); boot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // set write buffer // this is the default, but its recommended to set it in case of change in future netty. boot.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, (int) Configuration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_WATERMARK_HIGH)); boot.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, (int) Configuration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_WATERMARK_LOW)); // more buffer settings on Netty socket option, one can tune them by specifying // properties, e.g.: // alluxio.worker.network.netty.backlog=50 // alluxio.worker.network.netty.buffer.send=64KB // alluxio.worker.network.netty.buffer.receive=64KB if (Configuration.containsKey(PropertyKey.WORKER_NETWORK_NETTY_BACKLOG)) { boot.option(ChannelOption.SO_BACKLOG, Configuration.getInt(PropertyKey.WORKER_NETWORK_NETTY_BACKLOG)); }/*from w w w . ja va 2 s . co m*/ if (Configuration.containsKey(PropertyKey.WORKER_NETWORK_NETTY_BUFFER_SEND)) { boot.option(ChannelOption.SO_SNDBUF, (int) Configuration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_BUFFER_SEND)); } if (Configuration.containsKey(PropertyKey.WORKER_NETWORK_NETTY_BUFFER_RECEIVE)) { boot.option(ChannelOption.SO_RCVBUF, (int) Configuration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_BUFFER_RECEIVE)); } return boot; }
From source file:com.alibaba.rocketmq.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 w w w. ja v a 2 s . co m*/ public Thread newThread(Runnable r) { return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet()); } }); Bootstrap handler = this.bootstrap.group(this.eventLoopGroupWorker);// if (isLinux) { handler.channel(EpollSocketChannel.class); } else { handler.channel(NioSocketChannel.class); } // handler.option(ChannelOption.TCP_NODELAY, true) // .option(ChannelOption.SO_KEEPALIVE, false) // .option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()) // .option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()) // .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()); } }); 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.alibaba.rocketmq.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 w ww. ja v a 2s . c o m public Thread newThread(Runnable r) { return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker); if (isLinux) { childHandler.channel(EpollServerSocketChannel.class); } else { childHandler.channel(NioServerSocketChannel.class); } if (isLinux) { childHandler.option(EpollChannelOption.SO_REUSEPORT, true); } // childHandler.option(ChannelOption.SO_BACKLOG, 1024) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.SO_KEEPALIVE, false) // .childOption(ChannelOption.TCP_NODELAY, true) // .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()) // .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) // .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 (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) { // ???? 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.alibaba.rocketmq.remoting.netty.NettyUDPServer.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyServerConfig.getServerWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override//from www . j av a2 s. c om public Thread newThread(Runnable r) { return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet()); } }); Bootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroupWorker).channel(NioDatagramChannel.class) // .option(ChannelOption.SO_BACKLOG, 1024) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.SO_KEEPALIVE, false) // .option(ChannelOption.SO_BROADCAST, true) // .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()) // .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) // .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenUDPPort())) .handler(new ChannelInitializer<DatagramChannel>() { @Override public void initChannel(DatagramChannel ch) throws Exception { ch.pipeline().addLast( // defaultEventExecutorGroup, // new UDP2BufAdapt(), new NettyEncoder(), // // //new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()),// //new NettyConnetManageHandler(), // new NettyServerHandler()); } }); if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) { // ???? childHandler.option(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 { NettyUDPServer.this.scanResponseTable(); } catch (Exception e) { log.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); }
From source file:com.ancun.netty.httpserver.HttpServer.java
License:Apache License
private void setBootstrapOptions(ServerBootstrap bootstrap) { bootstrap.option(ChannelOption.SO_KEEPALIVE, useKeepAlive()); bootstrap.option(ChannelOption.SO_BACKLOG, 1024); bootstrap.option(ChannelOption.TCP_NODELAY, useTcpNoDelay()); bootstrap.option(ChannelOption.SO_KEEPALIVE, serverSettings.isKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, shouldReuseAddress()); bootstrap.option(ChannelOption.SO_LINGER, getSoLinger()); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectTimeoutMillis()); bootstrap.option(ChannelOption.SO_RCVBUF, getReceiveBufferSize()); bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE); bootstrap.childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)); bootstrap.childOption(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE); bootstrap.childOption(ChannelOption.SO_RCVBUF, getReceiveBufferSize()); bootstrap.childOption(ChannelOption.SO_REUSEADDR, shouldReuseAddress()); }
From source file:com.baidu.jprotobuf.pbrpc.transport.RpcClient.java
License:Apache License
public RpcClient(Class<? extends Channel> clientChannelClass, RpcClientOptions rpcClientOptions) { this.workerGroup = new NioEventLoopGroup(); this.group(workerGroup); this.channel(clientChannelClass); this.handler(new RpcClientPipelineinitializer(this)); this.rpcClientOptions = rpcClientOptions; this.option(ChannelOption.SO_REUSEADDR, rpcClientOptions.isReuseAddress()); this.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, rpcClientOptions.getConnectTimeout()); this.option(ChannelOption.SO_SNDBUF, rpcClientOptions.getSendBufferSize()); this.option(ChannelOption.SO_RCVBUF, rpcClientOptions.getSendBufferSize()); this.option(ChannelOption.SO_KEEPALIVE, rpcClientOptions.isKeepAlive()); this.option(ChannelOption.TCP_NODELAY, rpcClientOptions.getTcpNoDelay()); this.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, new DefaultMessageSizeEstimator(rpcClientOptions.getReceiveBufferSize())); // add count/* w w w.jav a 2 s . com*/ INSTANCE_COUNT.incrementAndGet(); }
From source file:com.baidu.jprotobuf.pbrpc.transport.RpcServer.java
License:Apache License
public RpcServer(Class<? extends ServerChannel> serverChannelClass, RpcServerOptions serverOptions, RpcServiceRegistry rpcServiceRegistry) { if (rpcServiceRegistry == null) { throw new RuntimeException("protperty 'rpcServiceRegistry ' is null."); }/*from w w w .j a v a 2 s. co m*/ if (serverOptions == null) { serverOptions = new RpcServerOptions(); } this.bossGroup = new NioEventLoopGroup(serverOptions.getAcceptorThreads()); this.workerGroup = new NioEventLoopGroup(serverOptions.getWorkThreads()); this.group(this.bossGroup, this.workerGroup); this.channel(serverChannelClass); this.option(ChannelOption.SO_BACKLOG, serverOptions.getBacklog()); this.childOption(ChannelOption.SO_KEEPALIVE, serverOptions.isKeepAlive()); this.childOption(ChannelOption.SO_REUSEADDR, true); this.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); this.childOption(ChannelOption.TCP_NODELAY, serverOptions.isTcpNoDelay()); this.childOption(ChannelOption.SO_LINGER, serverOptions.getSoLinger()); this.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverOptions.getConnectTimeout()); this.childOption(ChannelOption.SO_RCVBUF, serverOptions.getReceiveBufferSize()); this.childOption(ChannelOption.SO_SNDBUF, serverOptions.getSendBufferSize()); this.rpcServiceRegistry = rpcServiceRegistry; // do register meta service rpcServiceRegistry.doRegisterMetaService(); this.rpcServerOptions = serverOptions; this.rpcServerPipelineInitializer = new RpcServerPipelineInitializer(rpcServiceRegistry, rpcServerOptions); this.childHandler(rpcServerPipelineInitializer); }
From source file:com.barchart.http.server.HttpServer.java
License:BSD License
/** * Start the server with the configuration settings provided. *//*from w w w .j a va 2s .c o m*/ public ChannelFuture listen() { if (config == null) { throw new IllegalStateException("Server has not been configured"); } if (serverChannel != null) { throw new IllegalStateException("Server is already running."); } final ChannelFuture future = new ServerBootstrap() // .group(config.parentGroup(), config.childGroup()) // .channel(NioServerSocketChannel.class) // .localAddress(config.address()) // .childHandler(new HttpServerChannelInitializer()) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.SO_SNDBUF, 262144) // .option(ChannelOption.SO_RCVBUF, 262144) // .bind(); serverChannel = future.channel(); return future; }