List of usage examples for io.netty.channel.epoll EpollEventLoopGroup shutdownGracefully
@Override
public Future<?> shutdownGracefully()
From source file:net.NettyEngine4.ServerServiceImpl.java
License:Apache License
/** * jni native Epoll/* w w w . j a v a 2 s .co m*/ #NioEventLoopGroup EpollEventLoopGroup ---- EventLoopGroup ? #NioEventLoop EpollEventLoop #NioServerSocketChannel EpollServerSocketChannel #NioSocketChannel EpollSocketChannel ---- SocketChannel? ## RHEL/CentOS/Fedora: #sudo yum install autoconf automake libtool glibc-devel.i686 glibc-devel libgcc.i686 make ## Debian/Ubuntu: #sudo apt-get install autoconf automake libtool make gcc-multilib * @throws Exception */ @Override public void runNativeEpoll() throws Exception { EpollEventLoopGroup BossEventLoopGroup = new EpollEventLoopGroup(0x1, new PriorityThreadFactory("@+?", Thread.NORM_PRIORITY)); //mainReactor 1 EpollEventLoopGroup WorkerEventLoopGroup = new EpollEventLoopGroup( Runtime.getRuntime().availableProcessors() + 0x1, new PriorityThreadFactory("@+I/O", Thread.NORM_PRIORITY)); //subReactor ?cpu+1 ServerBootstrap serverBootstrap = new ServerBootstrap(); try { serverBootstrap.group(BossEventLoopGroup, WorkerEventLoopGroup).channel(EpollServerSocketChannel.class) .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.SO_REUSEADDR, true) //?? .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(false))// heap buf 's better .childOption(ChannelOption.SO_RCVBUF, 1048576).childOption(ChannelOption.SO_SNDBUF, 1048576) .childHandler(new ServerChannelInitializer());//used to serve the request for the {@link Channel}'s // Bind and start to accept incoming connections. ChannelFuture channelFuture = serverBootstrap .bind(new InetSocketAddress(Config.DEFAULT_VALUE.SERVER_VALUE.gameserverPort)).sync(); if (LOGGER.isDebugEnabled()) LOGGER.debug("server??:" + Config.DEFAULT_VALUE.SERVER_VALUE.gameserverPort); // Wait until the server socket is closed. // In this server, this does not happen, but you can do that to gracefully // shut down your server. channelFuture.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. BossEventLoopGroup.shutdownGracefully(); WorkerEventLoopGroup.shutdownGracefully(); } }