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.ibm.crail.namenode.rpc.netty.NettyNameNode.java
License:Apache License
public void run(final RpcNameNodeService service) { /* here we run the incoming RPC service */ InetSocketAddress inetSocketAddress = CrailUtils.getNameNodeAddress(); LOG.info("Starting the NettyNamenode service at : " + inetSocketAddress); /* start the netty server */ EventLoopGroup acceptGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from www . jav a 2 s . c om*/ ServerBootstrap boot = new ServerBootstrap(); boot.group(acceptGroup, workerGroup); /* we use sockets */ boot.channel(NioServerSocketChannel.class); /* for new incoming connection */ boot.childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { LOG.info("A new connection has arrived from : " + ch.remoteAddress().toString()); /* incoming pipeline */ ch.pipeline().addLast("RequestDecoder", new RequestDecoder()); ch.pipeline().addLast("NNProcessor", new NamenodeProcessor(service)); /* outgoing pipeline */ ch.pipeline().addLast("ResponseEncoder", new ResponseEncoder()); } }); /* general optimization settings */ boot.option(ChannelOption.SO_BACKLOG, 1024); boot.childOption(ChannelOption.SO_KEEPALIVE, true); /* now we bind the server and start */ ChannelFuture f = boot.bind(inetSocketAddress.getAddress(), inetSocketAddress.getPort()).sync(); /* at this point we are binded and ready */ f.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { workerGroup.shutdownGracefully(); acceptGroup.shutdownGracefully(); LOG.info("Netty namenode at " + inetSocketAddress + " is shutdown"); } }
From source file:com.ict.dtube.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. j a va 2s . com public Thread newThread(Runnable r) { return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker) .channel(NioServerSocketChannel.class) // .option(ChannelOption.SO_BACKLOG, 1024) // .option(ChannelOption.SO_REUSEADDR, true) // .childOption(ChannelOption.TCP_NODELAY, true) // .childOption(ChannelOption.SO_SNDBUF, NettySystemConfig.SocketSndbufSize) // .childOption(ChannelOption.SO_RCVBUF, NettySystemConfig.SocketRcvbufSize) .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 (NettySystemConfig.NettyPooledByteBufAllocatorEnable) { // ???? 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.imaginarycode.minecraft.bungeejson.impl.httpserver.NettyBootstrap.java
License:Open Source License
public void initialize() { group = new NioEventLoopGroup(5, factory); int port = 7432; // CONFIG ServerBootstrap b = new ServerBootstrap(); b.group(group).channel(NioServerSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childHandler(new ChannelInitializer<SocketChannel>() { @Override// w w w.j a v a2s .c o m public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("messageCodec", new HttpServerCodec()); pipeline.addLast("messageHandler", new HttpServerHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); channelFuture = b.bind(port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { BungeeJSONPlugin.getPlugin().getLogger() .info("BungeeJSON server started on " + channelFuture.channel().localAddress()); } }); }
From source file:com.irh.material.basics.netty.chapter14_1.server.NettyServer.java
License:Apache License
public void bind() throws Exception { // ??NIO/*from ww w . j a v a 2 s. c o m*/ EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.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 IOException { ch.pipeline().addLast("decoder", new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast("encoder", new NettyMessageEncoder()); ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast("LoginAuthHandler", new LoginAuthRespHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); } }); // ??? bootstrap.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.jansegre.jwar.webapi.ApiServer.java
License:Open Source License
@Override public void start() { // Reference: http://netty.io/wiki/user-guide-for-4.x.html EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w w w. j a v a 2 s . com*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add the text line codec combination first, pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast("decoder", new StringDecoder()); pipeline.addLast("encoder", new StringEncoder()); // and then business logic. pipeline.addLast("handler", apiSocket); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); // Bind and start to accept incoming connections. ChannelFuture f = b.bind(apiPort).syncUninterruptibly(); log.info("ApiSocket started at port: {}", apiPort); // Also start parent super.start(); // Wait until the server socket is closed. f.channel().closeFuture().syncUninterruptibly(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
From source file:com.jason.netty.file.FileServer.java
License:Apache License
public void run(int port) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {// ww w. j a va2 s. com ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).childHandler(new ChannelInitializer<SocketChannel>() { /* * (non-Javadoc) * * @see * io.netty.channel.ChannelInitializer#initChannel(io * .netty.channel.Channel) */ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(1024), new StringDecoder(CharsetUtil.UTF_8), new FileServerHandler()); } }); ChannelFuture f = b.bind(port).sync(); System.out.println("Server start at port : " + port); f.channel().closeFuture().sync(); } finally { // ? bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.jjzhk.Chapter13.file.FileServer.java
License:Apache License
public void run(int port) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from ww w .j a v a 2s .com*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).childHandler(new ChannelInitializer<SocketChannel>() { /* * (non-Javadoc) * * @see * io.netty.channel.ChannelInitializer#initChannel(io * .netty.channel.Channel) */ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(1024), new StringDecoder(CharsetUtil.UTF_8), new FileServerHandler()); } }); ChannelFuture f = b.bind(port).sync(); System.out.println("Start file server at port : " + port); f.channel().closeFuture().sync(); } finally { // ? bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.jjzhk.Chapter14.netty.NettyServer.java
License:Apache License
public void bind() throws Exception { // ?NIO?/*from www . jav a 2 s . c o m*/ EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); 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 IOException { ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast(new NettyMessageEncoder()); ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast(new LoginAuthRespHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler()); } }); // ???? b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.kingmed.dp.lisclient.demo.DiscardServer.java
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w ww . j a v a 2 s . co m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new DiscardServerHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_KEEPALIVE, true); ChannelFuture f = b.bind(port).sync(); f.channel().closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
From source file:com.kixeye.kixmpp.p2p.node.NodeServer.java
License:Apache License
public void initialize(final String host, final int port, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MessageRegistry messageRegistry, final ChannelInboundHandlerAdapter channelListener) { ServerBootstrap boot = new ServerBootstrap(); boot.group(bossGroup, workerGroup);/*from w ww. j a v a 2s .co m*/ boot.channel(NioServerSocketChannel.class); boot.option(ChannelOption.SO_BACKLOG, 32); boot.childOption(ChannelOption.SO_KEEPALIVE, true); boot.childOption(ChannelOption.TCP_NODELAY, true); boot.childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); //p.addLast(new LoggingHandler()); // encoders p.addLast(new LengthFieldPrepender(4)); p.addLast(new ProtostuffEncoder(messageRegistry)); // decoders p.addLast(new LengthFieldBasedFrameDecoder(0x100000, 0, 4, 0, 4)); p.addLast(new ProtostuffDecoder(messageRegistry)); p.addLast(channelListener); } }); // start accepting connection try { logger.info("Starting NodeServer on [{}]...", port); if (host == null) { acceptChannel = boot.bind(port).sync().channel(); } else { acceptChannel = boot.bind(host, port).sync().channel(); } logger.info("NodeServer listening on [{}]...", port); } catch (InterruptedException e) { logger.error("Binding to port {} failed", port, e); } }