List of usage examples for io.netty.channel ChannelOption SO_BACKLOG
ChannelOption SO_BACKLOG
To view the source code for io.netty.channel ChannelOption SO_BACKLOG.
Click Source Link
From source file:org.tinygroup.nettyremote.impl.ServerImpl.java
License:GNU General Public License
protected void init(ServerBootstrap b) { b.channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100) .childHandler(new ChannelInitializer<SocketChannel>() { public void initChannel(SocketChannel ch) throws IOException { ch.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null))); ch.pipeline().addLast("MessageEncoder", new ObjectEncoder()); ch.pipeline().addLast(new ServerHandler()); }//from www . jav a 2 s . com }); }
From source file:org.vertx.java.core.net.impl.TCPSSLHelper.java
License:Open Source License
public void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay); if (tcpSendBufferSize != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, tcpSendBufferSize); }// w w w . j a v a 2s . c o m if (tcpReceiveBufferSize != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(tcpReceiveBufferSize)); } bootstrap.option(ChannelOption.SO_LINGER, soLinger); if (trafficClass != -1) { bootstrap.childOption(ChannelOption.IP_TOS, trafficClass); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, tcpKeepAlive); bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress); bootstrap.option(ChannelOption.SO_BACKLOG, acceptBackLog); }
From source file:org.virtue.network.Network.java
License:Open Source License
/** * Binds a pipeline to a port//from www . jav a 2 s . com */ public void bindNetwork() { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("decoder", new HandshakeDecoder()); pipeline.addLast("read-timeout", new ReadTimeoutHandler(15)); pipeline.addLast("channel-handler", new NetworkHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true); try { future = bootstrap.bind(Constants.SERVER_PORT).sync(); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("Bound Virtue on: " + future.channel().localAddress().toString()); }
From source file:org.wenxueliu.netty.client.ClientTest.java
License:Apache License
/** * Accepts incoming connections.// ww w . ja v a 2 s . c o m */ private void startAcceptingConnections() throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new CommunicationChannelInitializer()); b.option(ChannelOption.SO_BACKLOG, 128); b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.childOption(ChannelOption.SO_KEEPALIVE, true); b.bind(80).sync(); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EndpointManager.java
License:Open Source License
public boolean startListener(int port, String name, InboundProcessorParams params) { if (org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EventExecutorManager.getInstance() .isRegisteredExecutor(port)) { log.info("Netty Listener already started on port " + port); return true; }//from w ww .j a va 2 s . c o m InboundHttp2Configuration config = buildConfiguration(port, name, params); NettyThreadPoolConfiguration threadPoolConfig = new NettyThreadPoolConfiguration( config.getBossThreadPoolSize(), config.getWorkerThreadPoolSize()); if (config.isEnableServerPush()) { if (config.getDispatchSequence() == null || config.getErrorSequence() == null) { throw new SynapseException("dispatch.outflow.sequence and error.outflow.sequence " + "cannot be empty if server-push enabled"); } } InboundHttp2EventExecutor eventExecutor = new InboundHttp2EventExecutor(threadPoolConfig); org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EventExecutorManager.getInstance() .registerEventExecutor(port, eventExecutor); ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(eventExecutor.getBossGroupThreadPool(), eventExecutor.getWorkerGroupThreadPool()) .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new InboundHttp2ServerInitializer(null, config)); try { b.bind(config.getPort()).sync().channel(); log.info("Http2 Inbound started on Port : " + config.getPort()); return true; } catch (InterruptedException e) { log.error(e.getMessage(), e); return false; } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EndpointManager.java
License:Open Source License
public boolean startSSLListener(int port, String name, InboundProcessorParams params) { if (org.wso2.carbon.inbound.endpoint.protocol.websocket.management.WebsocketEventExecutorManager .getInstance().isRegisteredExecutor(port)) { log.info("Netty Listener already started on port " + port); return true; }/*from ww w . j a v a 2 s.c o m*/ InboundHttp2Configuration config = buildConfiguration(port, name, params); InboundWebsocketSSLConfiguration SslConfig = buildSSLConfiguration(params); if (config.isEnableServerPush()) { if (config.getDispatchSequence() == null || config.getErrorSequence() == null) { throw new SynapseException("dispatch.outflow.sequence and error.outflow.sequence " + "cannot be empty if server-push enabled"); } } NettyThreadPoolConfiguration threadPoolConfig = new NettyThreadPoolConfiguration( config.getBossThreadPoolSize(), config.getWorkerThreadPoolSize()); InboundHttp2EventExecutor eventExecutor = new InboundHttp2EventExecutor(threadPoolConfig); org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EventExecutorManager.getInstance() .registerEventExecutor(port, eventExecutor); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(eventExecutor.getBossGroupThreadPool(), eventExecutor.getWorkerGroupThreadPool()) .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new InboundHttp2ServerInitializer(getSSLContext(SslConfig), config)); b.bind(config.getPort()).sync().channel(); log.info("Http2-secure Inbound started on Port : " + config.getPort()); } catch (InterruptedException e) { log.error(e.getMessage(), e); } return true; }
From source file:org.wso2.carbon.transport.http.netty.listener.HTTPTransportListener.java
License:Open Source License
private void startTransport() { //Create Bootstrap Configuration from listener parameters ServerBootstrapConfiguration.createBootStrapConfiguration(transportProperties); ServerBootstrapConfiguration serverBootstrapConfiguration = ServerBootstrapConfiguration.getInstance(); //boss group is for accepting channels EventLoopGroup bossGroup = HTTPTransportContextHolder.getInstance().getBossGroup(); if (bossGroup == null) { bossGroup = new NioEventLoopGroup( bossGroupSize != 0 ? bossGroupSize : Runtime.getRuntime().availableProcessors()); HTTPTransportContextHolder.getInstance().setBossGroup(bossGroup); }/* w w w .j av a 2 s . c om*/ //worker group is for processing IO EventLoopGroup workerGroup = HTTPTransportContextHolder.getInstance().getWorkerGroup(); if (workerGroup == null) { workerGroup = new NioEventLoopGroup( workerGroupSize != 0 ? workerGroupSize : Runtime.getRuntime().availableProcessors() * 2); HTTPTransportContextHolder.getInstance().setWorkerGroup(workerGroup); } log.debug("Netty Boss group size " + bossGroup); log.debug("Netty Worker group Size" + workerGroup); bootstrap = new ServerBootstrap(); bootstrap.option(ChannelOption.SO_BACKLOG, serverBootstrapConfiguration.getSoBackLog()); log.debug("Netty Server Socket BACKLOG " + serverBootstrapConfiguration.getSoBackLog()); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class); addChannelInitializer(); bootstrap.childOption(ChannelOption.TCP_NODELAY, serverBootstrapConfiguration.isTcpNoDelay()); log.debug("Netty Server Socket TCP_NODELAY " + serverBootstrapConfiguration.isTcpNoDelay()); bootstrap.option(ChannelOption.SO_KEEPALIVE, serverBootstrapConfiguration.isKeepAlive()); log.debug("Netty Server Socket SO_KEEPALIVE " + serverBootstrapConfiguration.isKeepAlive()); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverBootstrapConfiguration.getConnectTimeOut()); log.debug( " Netty Server Socket CONNECT_TIMEOUT_MILLIS " + serverBootstrapConfiguration.getConnectTimeOut()); bootstrap.option(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); log.debug("Netty Server Socket SO_SNDBUF " + serverBootstrapConfiguration.getSendBufferSize()); bootstrap.option(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReciveBufferSize()); log.debug("Netty Server Socket SO_RCVBUF " + serverBootstrapConfiguration.getReciveBufferSize()); bootstrap.childOption(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReciveBufferSize()); log.debug("Netty Server Socket SO_RCVBUF " + serverBootstrapConfiguration.getReciveBufferSize()); bootstrap.childOption(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); log.debug("Netty Server Socket SO_SNDBUF " + serverBootstrapConfiguration.getSendBufferSize()); if (defaultListenerConfig.isBindOnStartup()) { bindInterface(defaultListenerConfig); } TransportListenerManager transportListenerManager = HTTPTransportContextHolder.getInstance().getManager(); if (transportListenerManager != null) { transportListenerManager.registerTransportListener(this); } }
From source file:org.wso2.carbon.transport.http.netty.listener.NettyListener.java
License:Open Source License
private void startTransport() { ServerBootstrapConfiguration.createBootStrapConfiguration(nettyConfig.getParameters()); ServerBootstrapConfiguration serverBootstrapConfiguration = ServerBootstrapConfiguration.getInstance(); bossGroup = new NioEventLoopGroup(nettyConfig.getBossThreadPoolSize()); workerGroup = new NioEventLoopGroup(nettyConfig.getWorkerThreadPoolSize()); bootstrap = new ServerBootstrap(); bootstrap.option(ChannelOption.SO_BACKLOG, serverBootstrapConfiguration.getSoBackLog()); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class); addChannelInitializer();//ww w . ja va 2 s. co m bootstrap.childOption(ChannelOption.TCP_NODELAY, serverBootstrapConfiguration.isTcpNoDelay()); bootstrap.option(ChannelOption.SO_KEEPALIVE, serverBootstrapConfiguration.isKeepAlive()); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverBootstrapConfiguration.getConnectTimeOut()); bootstrap.option(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); bootstrap.option(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReciveBufferSize()); bootstrap.childOption(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReciveBufferSize()); bootstrap.childOption(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); setupChannelInitializer(); try { bootstrap.bind(new InetSocketAddress(nettyConfig.getHost(), nettyConfig.getPort())).sync(); TransportListenerManager artifactDeployer = NettyTransportContextHolder.getInstance().getManager(); if (artifactDeployer != null) { artifactDeployer.registerTransportListener(id, this); } log.info("Netty Listener starting on port " + nettyConfig.getPort()); } catch (InterruptedException e) { log.error(e.getMessage(), e); } }
From source file:org.wso2.carbon.transport.http.netty.listener.ServerConnectorBootstrap.java
License:Open Source License
public void addSocketConfiguration(ServerBootstrapConfiguration serverBootstrapConfiguration) { // Set other serverBootstrap parameters serverBootstrap.option(ChannelOption.SO_BACKLOG, serverBootstrapConfiguration.getSoBackLog()); serverBootstrap.childOption(ChannelOption.TCP_NODELAY, serverBootstrapConfiguration.isTcpNoDelay()); serverBootstrap.option(ChannelOption.SO_KEEPALIVE, serverBootstrapConfiguration.isKeepAlive()); serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverBootstrapConfiguration.getConnectTimeOut()); serverBootstrap.option(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); serverBootstrap.option(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReceiveBufferSize()); serverBootstrap.childOption(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReceiveBufferSize()); serverBootstrap.childOption(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); log.debug("Netty Server Socket BACKLOG " + serverBootstrapConfiguration.getSoBackLog()); log.debug("Netty Server Socket TCP_NODELAY " + serverBootstrapConfiguration.isTcpNoDelay()); log.debug("Netty Server Socket SO_KEEPALIVE " + serverBootstrapConfiguration.isKeepAlive()); log.debug("Netty Server Socket CONNECT_TIMEOUT_MILLIS " + serverBootstrapConfiguration.getConnectTimeOut()); log.debug("Netty Server Socket SO_SNDBUF " + serverBootstrapConfiguration.getSendBufferSize()); log.debug("Netty Server Socket SO_RCVBUF " + serverBootstrapConfiguration.getReceiveBufferSize()); log.debug("Netty Server Socket SO_RCVBUF " + serverBootstrapConfiguration.getReceiveBufferSize()); log.debug("Netty Server Socket SO_SNDBUF " + serverBootstrapConfiguration.getSendBufferSize()); }
From source file:org.wso2.carbon.transport.http.netty.listener.ServerConnectorController.java
License:Open Source License
public void start() { Set<TransportProperty> transportPropertiesSet = transportsConfiguration.getTransportProperties(); Map<String, Object> transportProperties = new HashMap<>(); if (transportPropertiesSet != null && !transportPropertiesSet.isEmpty()) { transportProperties = transportPropertiesSet.stream() .collect(Collectors.toMap(TransportProperty::getName, TransportProperty::getValue)); }/* www. ja va 2 s . co m*/ // Create Bootstrap Configuration from listener parameters ServerBootstrapConfiguration.createBootStrapConfiguration(transportProperties); ServerBootstrapConfiguration serverBootstrapConfiguration = ServerBootstrapConfiguration.getInstance(); // Create Boss Group - boss group is for accepting channels EventLoopGroup bossGroup = HTTPTransportContextHolder.getInstance().getBossGroup(); if (bossGroup == null) { int bossGroupSize = Util.getIntProperty(transportProperties, Constants.SERVER_BOOTSTRAP_BOSS_GROUP_SIZE, Runtime.getRuntime().availableProcessors()); bossGroup = new NioEventLoopGroup(bossGroupSize); HTTPTransportContextHolder.getInstance().setBossGroup(bossGroup); } // Create Worker Group - worker group is for processing IO EventLoopGroup workerGroup = HTTPTransportContextHolder.getInstance().getWorkerGroup(); if (workerGroup == null) { int workerGroupSize = Util.getIntProperty(transportProperties, Constants.SERVER_BOOTSTRAP_WORKER_GROUP_SIZE, Runtime.getRuntime().availableProcessors() * 2); workerGroup = new NioEventLoopGroup(workerGroupSize); HTTPTransportContextHolder.getInstance().setWorkerGroup(workerGroup); } // Set Handler Executor HTTPTransportContextHolder.getInstance().setHandlerExecutor(new HandlerExecutor()); bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class); // Register Channel initializer handler = new HTTPServerChannelInitializer(); handler.setupConnectionManager(transportProperties); bootstrap.childHandler(handler); int bufferSize = Util.getIntProperty(transportProperties, Constants.OUTPUT_CONTENT_BUFFER_SIZE, 0); if (bufferSize != 0) { BufferFactory.createInstance(bufferSize); } // Set other bootstrap parameters bootstrap.option(ChannelOption.SO_BACKLOG, serverBootstrapConfiguration.getSoBackLog()); log.debug("Netty Server Socket BACKLOG " + serverBootstrapConfiguration.getSoBackLog()); bootstrap.childOption(ChannelOption.TCP_NODELAY, serverBootstrapConfiguration.isTcpNoDelay()); log.debug("Netty Server Socket TCP_NODELAY " + serverBootstrapConfiguration.isTcpNoDelay()); bootstrap.option(ChannelOption.SO_KEEPALIVE, serverBootstrapConfiguration.isKeepAlive()); log.debug("Netty Server Socket SO_KEEPALIVE " + serverBootstrapConfiguration.isKeepAlive()); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverBootstrapConfiguration.getConnectTimeOut()); log.debug( " Netty Server Socket CONNECT_TIMEOUT_MILLIS " + serverBootstrapConfiguration.getConnectTimeOut()); bootstrap.option(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); log.debug("Netty Server Socket SO_SNDBUF " + serverBootstrapConfiguration.getSendBufferSize()); bootstrap.option(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReceiveBufferSize()); log.debug("Netty Server Socket SO_RCVBUF " + serverBootstrapConfiguration.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.SO_RCVBUF, serverBootstrapConfiguration.getReceiveBufferSize()); log.debug("Netty Server Socket SO_RCVBUF " + serverBootstrapConfiguration.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.SO_SNDBUF, serverBootstrapConfiguration.getSendBufferSize()); log.debug("Netty Server Socket SO_SNDBUF " + serverBootstrapConfiguration.getSendBufferSize()); initialized = true; }