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:realityshard.container.ContainerFacade.java
License:Open Source License
/** * Init our factories and load the info about them into our map. */// w w w. j a v a 2 s. c o m private GameAppInfo produceInfoFromFactory(GameAppFactory factory) throws Exception { GameAppInfo result = new GameAppInfo(); result.Factory = factory; result.MetaContext = new MetaGameAppContext(factory.getName(), this); // register the metacontext with its own aggregator result.MetaContext.getEventAggregator().register(result.MetaContext); result.Boss = new NioEventLoopGroup(); result.Worker = new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(result.Boss, result.Worker).channel(NioServerSocketChannel.class) .childAttr(GameAppContextKey.KEY, result.MetaContext).childAttr(GameAppContextKey.IS_SET, false) .option(ChannelOption.SO_BACKLOG, 1000); result.NetworkChannel = (NioServerSocketChannel) factory.getServerChannel(bootstrap); return result; }
From source file:sailfish.remoting.DefaultServer.java
License:Apache License
private ServerBootstrap newServerBootstrap() { ServerBootstrap serverBoot = new ServerBootstrap(); serverBoot.channel(NettyPlatformIndependent.serverChannelClass()); // connections wait for accept serverBoot.option(ChannelOption.SO_BACKLOG, 1024); serverBoot.option(ChannelOption.SO_REUSEADDR, true); // replace by heart beat serverBoot.childOption(ChannelOption.SO_KEEPALIVE, false); serverBoot.childOption(ChannelOption.TCP_NODELAY, true); serverBoot.childOption(ChannelOption.SO_SNDBUF, 32 * 1024); serverBoot.childOption(ChannelOption.SO_RCVBUF, 32 * 1024); // temporary settings, need more tests serverBoot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)); serverBoot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); //default is true, reduce thread context switching serverBoot.childOption(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, true); return serverBoot; }
From source file:server.operation.OperationServer.java
License:Apache License
public void start() throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/*from w w w. j a v a 2 s .c o m*/ // ?? ? ?? ? ?. //?, ?? ? . //jvm ?? ?. (netty api ) //SelfSignedCertificate ssc = new SelfSignedCertificate(); //sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); //File cert = new File("./resource/cert/nene.crt"); //File privateKey= new File("./resource/cert/privatekey.pem"); //resources/cert ? ?? ? ?? . //? pkcs#8? . final File cert = ResourceUtils.getFile("classpath:/cert/nene.crt"); final File privateKey = ResourceUtils.getFile("classpath:/cert/nene.pem"); sslCtx = SslContextBuilder.forServer(cert, privateKey, "tkfkdgo123!").build(); System.out.println("ssl? ??. : " + SSL + ", port : " + PORT); } 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.DEBUG)) .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.DEBUG), //new StringEncoder(CharsetUtil.UTF_8), //new LineBasedFrameDecoder(8192), //new StringDecoder(CharsetUtil.UTF_8), new ChunkedWriteHandler(), new OperationServerHandler(applicationContext, eventPublisher)); } }); // 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:sh.lab.jcorrelat.App.java
License:Open Source License
public static void main(final String[] args) throws Exception { ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME)) .setLevel(CONF_LOG_LEVEL);/*from w w w . j a va2 s .c om*/ final EventLoopGroup bossGroup = new NioEventLoopGroup(); final EventLoopGroup workerGroup = new NioEventLoopGroup(); final MessagePersister persister = new MessagePersister(); final EventExecutorGroup correlatorGroup = new DefaultEventExecutorGroup(32); final MessageCorrelationHandler correlatorHandler = new MessageCorrelationHandler(persister); try { final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel channel) throws Exception { final ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast("framer", new LineBasedFrameDecoder(MessageDecoder.BUFFER_SIZE)); pipeline.addLast("decoder", new MessageDecoder()); pipeline.addLast(/*correlatorGroup,*/ "correlator", correlatorHandler); } }).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_BACKLOG, 8) .option(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true); final Channel channel = bootstrap.bind(CONF_BIND_HOST, CONF_BIND_PORT).sync().channel(); channel.closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
From source file:spark.network.netty.FileServer.java
License:Apache License
public FileServer(PathResolver pResolver, int port) { InetSocketAddress addr = new InetSocketAddress(port); // Configure the server. bootstrap = new ServerBootstrap(); bootstrap.group(new OioEventLoopGroup(), new OioEventLoopGroup()).channel(OioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).option(ChannelOption.SO_RCVBUF, 1500) .childHandler(new FileServerChannelInitializer(pResolver)); // Start the server. channelFuture = bootstrap.bind(addr); try {// w w w .j ava2 s . co m // Get the address we bound to. InetSocketAddress boundAddress = ((InetSocketAddress) channelFuture.sync().channel().localAddress()); this.port = boundAddress.getPort(); } catch (InterruptedException ie) { this.port = 0; } }
From source file:storm.falcon.echo.EchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { // ??/*from w ww. j av a2 s. com*/ EventLoopGroup bossGroup = new NioEventLoopGroup(1); // EventLoopGroup workerGroup = new NioEventLoopGroup(); try { // ??? ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) // .channel(NioServerSocketChannel.class) // NIO? .option(ChannelOption.SO_BACKLOG, 100) // TCP .handler(new LoggingHandler(LogLevel.INFO)) // .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); //p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new EchoServerHandler()); } }); // ?? ChannelFuture f = b.bind(PORT).sync(); // socket f.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:system.core.netty.nio.chapter4.frame.delimiter.EchoServer.java
License:Apache License
public void bind(int port) throws Exception { // ??NIO// w w w .j av a 2 s . c om EventLoopGroup bossGroup = new NioEventLoopGroup(); 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 { ByteBuf delimiter = Unpooled.copiedBuffer("$_".getBytes()); ch.pipeline().addLast(new DelimiterBasedFrameDecoder(300, delimiter)); ch.pipeline().addLast(new StringDecoder()); ch.pipeline().addLast(new EchoServerHandler()); } }); // ??? ChannelFuture f = b.bind(port).sync(); // ??? f.channel().closeFuture().sync(); } finally { // ? bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:tachyon.worker.netty.NettyDataServer.java
License:Apache License
private ServerBootstrap createBootstrap() { final ServerBootstrap boot = createBootstrapOfType( mTachyonConf.getEnum(Constants.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) mTachyonConf.getBytes(Constants.WORKER_NETTY_WATERMARK_HIGH)); boot.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_WATERMARK_LOW)); // more buffer settings on Netty socket option, one can tune them by specifying // properties, e.g.: // tachyon.worker.network.netty.backlog=50 // tachyon.worker.network.netty.buffer.send=64KB // tachyon.worker.network.netty.buffer.receive=64KB if (mTachyonConf.containsKey(Constants.WORKER_NETTY_BACKLOG)) { boot.option(ChannelOption.SO_BACKLOG, mTachyonConf.getInt(Constants.WORKER_NETTY_BACKLOG)); }/* ww w. ja va 2 s.c om*/ if (mTachyonConf.containsKey(Constants.WORKER_NETTY_SEND_BUFFER)) { boot.option(ChannelOption.SO_SNDBUF, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_SEND_BUFFER)); } if (mTachyonConf.containsKey(Constants.WORKER_NETTY_RECEIVE_BUFFER)) { boot.option(ChannelOption.SO_RCVBUF, (int) mTachyonConf.getBytes(Constants.WORKER_NETTY_RECEIVE_BUFFER)); } return boot; }
From source file:taichu.kafka.test.netty4.example.EchoServer.EchoServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {//from w w w . j a va 2 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) // .option(ChannelOption., 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:tk.jomp16.rcon.internal.RconServer.java
License:Open Source License
/** * Creates a new instance of RconServer/*from w ww .j av a 2s. c om*/ * * @param host the IP that the server will bind on * @param port the port that the server will bind on * @param rconPassword the password to authenticate the users * @param epoll if Netty server will run on epoll */ public RconServer(final String host, final int port, final String rconPassword, final boolean epoll) { this.host = host; this.port = port; this.rconPassword = rconPassword; if (this.rconPassword == null || this.rconPassword.isEmpty()) { log.error("Source RCON password not set!"); return; } this.rconEvents = new LinkedList<>(); this.bossGroup = epoll ? new EpollEventLoopGroup() : new NioEventLoopGroup(); this.workerGroup = epoll ? new EpollEventLoopGroup() : new NioEventLoopGroup(); this.serverBootstrap = new ServerBootstrap(); this.serverBootstrap.group(this.bossGroup, this.workerGroup) .channel(epoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) throws Exception { ch.pipeline().addLast(new RconNettyDecoder(), new RconNettyEncoder(), new RconNettyHandler(RconServer.this)); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT); this.canStartServer = true; }