List of usage examples for io.netty.channel.nio NioEventLoopGroup NioEventLoopGroup
public NioEventLoopGroup()
From source file:com.hxr.javatone.nettyguide.d12.server.NettyServer.java
License:Apache License
public void bind() throws Exception { // ??NIO//w w w .j a v a2 s. c om 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.DEBUG)).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().channel().closeFuture().sync().channel(); System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT)); }
From source file:com.hzq.nio.websocket.WebSocketServer.java
License:Apache License
public void run(int port) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*w w w.j av a 2 s . c o m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("http-codec", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler()); pipeline.addLast("handler", new WebSocketServerHandler()); } }); Channel ch = b.bind(port).sync().channel(); System.out.println("Web socket server started at port " + port + '.'); System.out.println("Open your browser and navigate to http://localhost:" + port + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.ibm.crail.datanode.netty.client.NettyEndpointGroup.java
License:Apache License
public NettyEndpointGroup() { workerGroup = new NioEventLoopGroup(); boot = new Bootstrap(); boot.group(workerGroup);//from w ww .j a va 2 s . c o m boot.channel(NioSocketChannel.class); boot.option(ChannelOption.SO_KEEPALIVE, true); final NettyEndpointGroup thisGroup = this; boot.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { /* outgoing pipeline */ //ch.pipeline().addLast(new RdmaEncoderTx()); /* incoming pipeline */ ch.pipeline().addLast(new RdmaDecoderRx(), new IncomingResponseHandler(thisGroup)); } }); activeClients = new ArrayList<NettyEndpoint>(); slot = new AtomicLong(0); inFlightOps = new ConcurrentHashMap<Long, NettyIOResult>(); }
From source file:com.ibm.crail.datanode.netty.server.NettyServer.java
License:Apache License
public void run() { /* start the netty server */ EventLoopGroup acceptGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from ww w .ja va 2s . co m 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("TID: " + Thread.currentThread().getId() + " , a new client connection has arrived from : " + ch.remoteAddress().toString()); /* incoming pipeline */ ch.pipeline().addLast(new RdmaDecoderRx(), /* this makes full RDMA messages */ new IncomingRequestHandler(ch, dataNode)); /* outgoing pipeline */ //ch.pipeline().addLast(new RdmaEncoderTx()); } }); /* 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(this.inetSocketAddress.getAddress(), this.inetSocketAddress.getPort()) .sync(); LOG.info("Datanode binded to : " + this.inetSocketAddress); /* at this point we are binded and ready */ f.channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); } finally { workerGroup.shutdownGracefully(); acceptGroup.shutdownGracefully(); LOG.info("Datanode at " + this.inetSocketAddress + " is shutdown"); } }