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:com.streamsets.pipeline.stage.origin.tcp.TCPConsumingServer.java
License:Apache License
@Override protected AbstractBootstrap bootstrap(boolean enableEpoll) { if (enableEpoll) { enableDirectBuffers();/*from ww w. j ava 2 s .c o m*/ // boss group simply opens channels and hands processing off to the child EpollEventLoopGroup bossGroup = new EpollEventLoopGroup(NUM_BOSS_THREADS); EventLoopGroup workerGroup = new EpollEventLoopGroup(numThreads); groups.add(bossGroup); groups.add(workerGroup); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(EpollServerSocketChannel.class) .childHandler(this.channelInitializer) .option(ChannelOption.SO_BACKLOG, SOCKET_MAX_INBOUND_CONNECTION_QUEUE_DEPTH) .childOption(ChannelOption.SO_KEEPALIVE, SOCKET_KEEPALIVE); return b; } else { disableDirectBuffers(); EventLoopGroup bossGroup = new NioEventLoopGroup(NUM_BOSS_THREADS); EventLoopGroup workerGroup = new NioEventLoopGroup(numThreads); groups.add(bossGroup); groups.add(workerGroup); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(this.channelInitializer) .option(ChannelOption.SO_BACKLOG, SOCKET_MAX_INBOUND_CONNECTION_QUEUE_DEPTH) .childOption(ChannelOption.SO_KEEPALIVE, SOCKET_KEEPALIVE); return b; } }
From source file:com.study.hc.net.netty.EchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the server. // EventLoopGroup accept NioEventLoop EventLoopGroup bossGroup = new NioEventLoopGroup(1); // EventLoopGroup I/O EventLoopGroup workerGroup2 = new NioEventLoopGroup(1); try {//from www .ja v a 2 s. c om // ?? ServerBootstrap b = new ServerBootstrap(); // ???reactor??? b.group(bossGroup, workerGroup2).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.DEBUG)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new EchoServerHandler()); } }); // bind?? ChannelFuture f = b.bind(PORT).sync(); // ?? f.channel().closeFuture().sync(); } finally { // bossGroup.shutdownGracefully(); workerGroup2.shutdownGracefully(); } }
From source file:com.system.distribute.server.FileServer.java
License:Apache License
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from w ww . j av a2s . c om ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(8192), new StringDecoder(CharsetUtil.UTF_8), new FileHandler()); } }); // Start the server. ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.tencent.mars.proxy.ProxyServer.java
License:Open Source License
public void start() throws Exception { try {/*w ww .j a v a 2 s . c o m*/ serverBootstrap = new ServerBootstrap(); serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(channelHandler).option(ChannelOption.SO_BACKLOG, 128) .childOption(ChannelOption.SO_KEEPALIVE, true); ChannelFuture channelFuture = serverBootstrap.bind(port).sync(); channelFuture.channel().closeFuture().sync(); } catch (Exception e) { } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
From source file:com.test.zp.netty.EchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. // final SslContext sslCtx; // if (SSL) { // SelfSignedCertificate ssc = new SelfSignedCertificate(); // sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); // } else { // sslCtx = null; // }// w w w. j av a2 s . c o m // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); // if (sslCtx != null) { // p.addLast(sslCtx.newHandler(ch.alloc())); // } //p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new EchoServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(PORT).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.titilink.camel.rest.server.CamelServer.java
License:LGPL
private static void run(int port, boolean supportSSL) { LOGGER.info("CamelServer run({}, {})", port, supportSSL); EventLoopGroup bossGroup = new NioEventLoopGroup(DEFAULT_BOSS_NIO_EVENT_NUM); BOSS_GROUP_LIST.add(bossGroup);//from w w w . j a va 2 s . c om EventLoopGroup workerGroup = new NioEventLoopGroup(DEFAULT_NIO_EVENT_NUM); WORKER_GROUP_LIST.add(workerGroup); String host = AdapterRestletUtil.getProperty(SERVER_REST_IP, LOCAL_HOST); HttpConnector httpConnector = new RestletConnector(host, port, supportSSL); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new HttpServerInitializer(supportSSL, httpConnector)); b.childOption(ChannelOption.SO_KEEPALIVE, true); b.childOption(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.SO_BACKLOG, DEFAULT_SO_BACKLOG); Channel ch = b.bind(new InetSocketAddress(host, port)).sync().channel(); CHANNEL_LIST.add(ch); ch.closeFuture().sync(); } catch (InterruptedException e) { LOGGER.error("InterruptedException while start server."); } catch (Throwable t) { LOGGER.error("CamelServer run throws error."); } finally { LOGGER.info("CamelServer run() : shutdown"); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.tongbanjie.tarzan.rpc.netty.NettyRpcServer.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 a2 s . co m*/ public Thread newThread(Runnable r) { return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector) .channel(NioServerSocketChannel.class) // .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 NettyConnectManageHandler(), // 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.nettyEventExecutor.start(); } this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRpcServer.this.scanResponseTable(); } catch (Exception e) { LOGGER.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); LOGGER.info("Rpc server [port:{}] start success", port); }
From source file:com.topsec.bdc.platform.api.test.echo.EchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/*from www. ja v a2 s. co m*/ SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } //p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new EchoServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(PORT).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.topsec.bdc.platform.api.test.file.FileServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/*ww w.ja v a 2s . c o m*/ SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(8192), new StringDecoder(CharsetUtil.UTF_8), new ChunkedWriteHandler(), new FileServerHandler()); } }); // Start the server. ChannelFuture f = b.bind(PORT).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.topsec.bdc.platform.api.test.http.helloworld.HttpHelloWorldServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {//from ww w . ja va 2 s. c om SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpHelloWorldServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }