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.wso2.carbon.transport.http.netty.util.server.HttpServer.java
License:Open Source License
/** * Start the HttpServer//from ww w. j ava 2 s. co m */ public void start() { bossGroup = new NioEventLoopGroup(this.bossGroupSize); workerGroup = new NioEventLoopGroup(this.workerGroupSize); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 100); b.childOption(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_KEEPALIVE, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(channelInitializer); ChannelFuture ch = b.bind(new InetSocketAddress(TestUtil.TEST_HOST, port)); ch.sync(); logger.info("HttpServer started on port " + port); } catch (InterruptedException e) { logger.error("HTTP Server cannot start on port " + port); } }
From source file:org.wso2.carbon.transport.http.netty.util.server.HttpsServer.java
License:Open Source License
/** * Start the HttpsServer/*from w w w. j a v a 2 s. c o m*/ */ public void start() { bossGroup = new NioEventLoopGroup(this.bossGroupSize); workerGroup = new NioEventLoopGroup(this.workerGroupSize); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 100); b.childOption(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_KEEPALIVE, true); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15000); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(ksName), ksPass); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, ctPass); sslContext = SSLContext.getInstance("TLS"); sslContext.init(kmf.getKeyManagers(), null, null); ((HTTPServerInitializer) channelInitializer).setSslContext(sslContext); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(channelInitializer); ChannelFuture ch = b.bind(new InetSocketAddress(TestUtil.TEST_HOST, port)); ch.sync(); logger.info("HttpServer started on port " + port); } catch (Exception e) { logger.error("HTTP Server cannot start on port " + port); } }
From source file:org.wso2.esb.integration.common.utils.servers.Http2Server.java
License:Open Source License
public void startServer() throws Exception { final SslContext sslCtx; if (SSL) {// ww w . ja v a 2 s . c om SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(provider) .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN, SelectorFailureBehavior.NO_ADVERTISE, SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1)) .build(); } else { sslCtx = null; } group = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new Http2ServerInitializer(sslCtx)); b.bind("127.0.0.5", PORT).sync().channel(); }
From source file:org.wso2.siddhi.extension.input.transport.http.server.HTTPServer.java
License:Open Source License
/** * Start the HTTPServer/*from ww w . jav a 2 s . c om*/ */ public void start() { bossGroup = new NioEventLoopGroup(this.bossGroupSize); workerGroup = new NioEventLoopGroup(this.workerGroupSize); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, backLog); b.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay); b.option(ChannelOption.SO_KEEPALIVE, isKeepAlive); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeOut); httpServerInitializer = new HTTPServerInitializer(); httpServerInitializer.setSslContext(sslContext); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(httpServerInitializer); ChannelFuture ch = b.bind(new InetSocketAddress(ServerUtil.TEST_HOST, port)).sync(); logger.info("HTTPServer starting on port " + port); if (ch.isSuccess()) { logger.info("HTTPServer started on port " + port); } } catch (InterruptedException e) { logger.error("HTTP Server cannot start on port " + port); } }
From source file:p2p_server.P2p_server.java
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); List<ChannelFuture> futures = new ArrayList<>(); SelfSignedCertificate ssc = new SelfSignedCertificate(); SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); try {/* ww w. j a va 2s . co m*/ ServerBootstrap appboot = new ServerBootstrap(); appboot.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 8192).childHandler(new AppChildChannelHandler(sslCtx)); appboot.option(ChannelOption.SO_REUSEADDR, true); appboot.option(ChannelOption.TCP_NODELAY, true); appboot.childOption(ChannelOption.SO_KEEPALIVE, true); appboot.childOption(ChannelOption.SO_RCVBUF, 512); appboot.childOption(ChannelOption.SO_SNDBUF, 512); ServerBootstrap devboot = new ServerBootstrap(); devboot.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 8192).childHandler(new DevChildChannelHandler(sslCtx)); devboot.option(ChannelOption.SO_REUSEADDR, true); devboot.option(ChannelOption.TCP_NODELAY, true); devboot.childOption(ChannelOption.SO_KEEPALIVE, true); devboot.childOption(ChannelOption.SO_RCVBUF, 512); devboot.childOption(ChannelOption.SO_SNDBUF, 512); //ChannelFuture f = boostrap.bind(port).sync(); futures.add(devboot.bind(5560)); futures.add(appboot.bind(5561)); for (ChannelFuture f : futures) { f.sync(); } for (ChannelFuture f : futures) { f.channel().closeFuture().sync(); } // ??? // f.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:ratpack.server.internal.DefaultRatpackServer.java
License:Apache License
protected Channel buildChannel(final ServerConfig serverConfig, final ChannelHandler handlerAdapter) throws InterruptedException { SslContext sslContext = serverConfig.getNettySslContext(); this.useSsl = sslContext != null; ServerBootstrap serverBootstrap = new ServerBootstrap(); serverConfig.getConnectTimeoutMillis().ifPresent(i -> { serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, i); serverBootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, i); });/*from ww w. j a v a 2 s . co m*/ serverConfig.getMaxMessagesPerRead().ifPresent(i -> { FixedRecvByteBufAllocator allocator = new FixedRecvByteBufAllocator(i); serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, allocator); serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, allocator); }); serverConfig.getReceiveBufferSize().ifPresent(i -> { serverBootstrap.option(ChannelOption.SO_RCVBUF, i); serverBootstrap.childOption(ChannelOption.SO_RCVBUF, i); }); serverConfig.getWriteSpinCount().ifPresent(i -> { serverBootstrap.option(ChannelOption.WRITE_SPIN_COUNT, i); serverBootstrap.childOption(ChannelOption.WRITE_SPIN_COUNT, i); }); serverConfig.getConnectQueueSize().ifPresent(i -> serverBootstrap.option(ChannelOption.SO_BACKLOG, i)); return serverBootstrap.group(execController.getEventLoopGroup()) .channel(ChannelImplDetector.getServerSocketChannelImpl()) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); new ConnectionIdleTimeout(pipeline, serverConfig.getIdleTimeout()); if (sslContext != null) { SSLEngine sslEngine = sslContext.newEngine(PooledByteBufAllocator.DEFAULT); pipeline.addLast("ssl", new SslHandler(sslEngine)); } pipeline.addLast("decoder", new HttpRequestDecoder(serverConfig.getMaxInitialLineLength(), serverConfig.getMaxHeaderSize(), serverConfig.getMaxChunkSize(), false)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("deflater", new IgnorableHttpContentCompressor()); pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("adapter", handlerAdapter); ch.config().setAutoRead(false); } }).bind(buildSocketAddress(serverConfig)).sync().channel(); }
From source file:ratpack.server.internal.NettyRatpackService.java
License:Apache License
@Override protected void startUp() throws Exception { Stopper stopper = new Stopper() { @Override/*from www . ja va 2s . c om*/ public void stop() { try { NettyRatpackService.this.stop(); } catch (Exception e) { throw uncheck(e); } } }; ServerBootstrap bootstrap = new ServerBootstrap(); group = new NioEventLoopGroup(launchConfig.getMainThreads(), new DefaultThreadFactory("ratpack-group", Thread.MAX_PRIORITY)); ChannelInitializer<SocketChannel> channelInitializer = channelInitializerTransformer.transform(stopper); bootstrap.group(group).channel(NioServerSocketChannel.class).childHandler(channelInitializer) .childOption(ChannelOption.ALLOCATOR, launchConfig.getBufferAllocator()) .childOption(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_BACKLOG, 1024) .option(ChannelOption.ALLOCATOR, launchConfig.getBufferAllocator()); try { channel = bootstrap.bind(buildSocketAddress()).sync().channel(); } catch (Exception e) { partialShutdown(); throw e; } boundAddress = (InetSocketAddress) channel.localAddress(); if (logger.isLoggable(Level.INFO)) { logger.info(String.format("Ratpack started for http://%s:%s", getBindHost(), getBindPort())); } }
From source file:reactor.io.net.impl.netty.tcp.NettyTcpServer.java
License:Apache License
protected NettyTcpServer(Environment env, Dispatcher dispatcher, InetSocketAddress listenAddress, final ServerSocketOptions options, final SslOptions sslOptions, Codec<Buffer, IN, OUT> codec) { super(env, dispatcher, listenAddress, options, sslOptions, codec); if (options instanceof NettyServerSocketOptions) { this.nettyOptions = (NettyServerSocketOptions) options; } else {//w w w.ja v a 2 s. c om this.nettyOptions = null; } int selectThreadCount = getDefaultEnvironment().getIntProperty("reactor.tcp.selectThreadCount", Environment.PROCESSORS / 2); int ioThreadCount = getDefaultEnvironment().getIntProperty("reactor.tcp.ioThreadCount", Environment.PROCESSORS); this.selectorGroup = new NioEventLoopGroup(selectThreadCount, new NamedDaemonThreadFactory("reactor-tcp-select")); if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { this.ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-tcp-io")); } this.bootstrap = new ServerBootstrap().group(selectorGroup, ioGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, options.backlog()) .option(ChannelOption.SO_RCVBUF, options.rcvbuf()).option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_REUSEADDR, options.reuseAddr()) .localAddress((null == listenAddress ? new InetSocketAddress(0) : listenAddress)) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.AUTO_READ, sslOptions != null); }
From source file:reactor.io.net.netty.tcp.NettyTcpServer.java
License:Apache License
protected NettyTcpServer(@Nonnull Environment env, @Nonnull EventBus reactor, @Nullable InetSocketAddress listenAddress, final ServerSocketOptions options, final SslOptions sslOptions, @Nullable Codec<Buffer, IN, OUT> codec, @Nonnull Collection<Consumer<NetChannel<IN, OUT>>> consumers) { super(env, reactor, listenAddress, options, sslOptions, codec, consumers); if (options instanceof NettyServerSocketOptions) { this.nettyOptions = (NettyServerSocketOptions) options; } else {//from w w w . ja va2 s . c o m this.nettyOptions = null; } int selectThreadCount = env.getProperty("reactor.tcp.selectThreadCount", Integer.class, Environment.PROCESSORS / 2); int ioThreadCount = env.getProperty("reactor.tcp.ioThreadCount", Integer.class, Environment.PROCESSORS); this.selectorGroup = new NioEventLoopGroup(selectThreadCount, new NamedDaemonThreadFactory("reactor-tcp-select")); if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { this.ioGroup = new NioEventLoopGroup(ioThreadCount, new NamedDaemonThreadFactory("reactor-tcp-io")); } this.bootstrap = new ServerBootstrap().group(selectorGroup, ioGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, options.backlog()) .option(ChannelOption.SO_RCVBUF, options.rcvbuf()).option(ChannelOption.SO_SNDBUF, options.sndbuf()) .option(ChannelOption.SO_REUSEADDR, options.reuseAddr()) .localAddress((null == listenAddress ? new InetSocketAddress(3000) : listenAddress)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel ch) throws Exception { SocketChannelConfig config = ch.config(); config.setReceiveBufferSize(options.rcvbuf()); config.setSendBufferSize(options.sndbuf()); config.setKeepAlive(options.keepAlive()); config.setReuseAddress(options.reuseAddr()); config.setSoLinger(options.linger()); config.setTcpNoDelay(options.tcpNoDelay()); if (log.isDebugEnabled()) { log.debug("CONNECT {}", ch); } if (null != sslOptions) { SSLEngine ssl = new SSLEngineSupplier(sslOptions, false).get(); if (log.isDebugEnabled()) { log.debug("SSL enabled using keystore {}", (null != sslOptions.keystoreFile() ? sslOptions.keystoreFile() : "<DEFAULT>")); } ch.pipeline().addLast(new SslHandler(ssl)); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (log.isDebugEnabled()) { log.debug("CLOSE {}", ch); } close(ch); } }); } }); }
From source file:reactor.ipc.netty.options.ServerOptions.java
License:Open Source License
static void defaultServerOptions(ServerBootstrap bootstrap) { bootstrap.localAddress(LOCALHOST_AUTO_PORT).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_BACKLOG, 1000) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.SO_RCVBUF, 1024 * 1024).childOption(ChannelOption.SO_SNDBUF, 1024 * 1024) .childOption(ChannelOption.AUTO_READ, false).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.SO_LINGER, 0).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000); }