List of usage examples for io.netty.channel EventLoopGroup shutdownGracefully
Future<?> shutdownGracefully();
From source file:com.papteco.client.netty.ReleaseFileServerBuilder.java
License:Apache License
public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from w w w .ja va2s . com ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new NewObjectDecoder(ClassResolvers.cacheDisabled(null)), new ReleaseFileServerHandler()); } }); // Bind and start to accept incoming connections. b.bind(PortTranslater(envsetting.getProperty("rlse_file_port"))).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.papteco.web.netty.LoginServerBuilder.java
License:Apache License
public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {// w w w . ja va 2s . c om ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new NewObjectDecoder(ClassResolvers.cacheDisabled(null)), new LoginServerHandler()); } }); // Bind and start to accept incoming connections. b.bind(PortTranslater(envsetting.getProperty("login_sym_port"))).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.papteco.web.netty.NettyAppServerBuilder.java
License:Apache License
public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//w w w. j ava2 s .c om ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new NewObjectDecoder(ClassResolvers.cacheDisabled(null)), new NettyAppServerHandler(rootpath)); } }); // Bind and start to accept incoming connections. b.bind(PortTranslater(envsetting.getProperty("comm_nett_port"))).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.papteco.web.netty.OpenFileClientBuilder.java
License:Apache License
public Object call() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {/* ww w . j a v a 2s.co m*/ Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new NewObjectDecoder(ClassResolvers.cacheDisabled(null)), new OpenFileClientHandler(openfile, filepath, fileStructPath)); } }); // Start the connection attempt. b.connect(host, PortTranslater(envsetting.getProperty("open_file_port"))).sync().channel().closeFuture() .sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block throw e; } finally { group.shutdownGracefully(); } return "Success"; }
From source file:com.papteco.web.netty.QuartzMailBackupServerBuilder.java
License:Apache License
public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from w ww .ja va 2 s. c o m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new NewObjectDecoder(ClassResolvers.cacheDisabled(null)), new QuartzMailBackupServerHandler(envsetting.getProperty("rootpath"))); } }); // Bind and start to accept incoming connections. b.bind(PortTranslater(envsetting.getProperty("email_bkp_port"))).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.papteco.web.netty.ReleaseFileClientBuilder.java
License:Apache License
public Object call() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {/*from www . ja v a 2 s . c om*/ Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new NewObjectDecoder(ClassResolvers.cacheDisabled(null)), new ReleaseFileClientHandler(filepath, fileStructPath, fileid, taskid)); } }); // Start the connection attempt. b.connect(host, PortTranslater(envsetting.getProperty("rlse_file_port"))).sync().channel().closeFuture() .sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { group.shutdownGracefully(); } return "Success"; }
From source file:com.phei.netty.chapter10.fileServer.HttpFileServer.java
License:Apache License
public void run(final int port, final String url) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//www.j a va 2s . 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("http-decoder", new HttpRequestDecoder()); ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536)); ch.pipeline().addLast("http-encoder", new HttpResponseEncoder()); ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler()); ch.pipeline().addLast("fileServerHandler", new HttpFileServerHandler(url)); } }); ChannelFuture future = b.bind("192.168.1.167", port).sync(); System.out.println( "HTTP??? : " + "http://192.168.1.167:" + port + url); future.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.phei.netty.chapter10.xml.client.HttpXmlClient.java
License:Apache License
public void connect(int port) throws Exception { // ?NIO// w w w . jav a 2 s. c om EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("http-decoder", new HttpResponseDecoder()); ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536)); // XML? ch.pipeline().addLast("xml-decoder", new HttpXmlResponseDecoder(Order.class, true)); ch.pipeline().addLast("http-encoder", new HttpRequestEncoder()); ch.pipeline().addLast("xml-encoder", new HttpXmlRequestEncoder()); ch.pipeline().addLast("xmlClientHandler", new HttpXmlClientHandler()); } }); // ?? ChannelFuture f = b.connect(new InetSocketAddress(port)).sync(); // f.channel().closeFuture().sync(); } finally { // NIO group.shutdownGracefully(); } }
From source file:com.phei.netty.chapter3.basic.TimeServer.java
License:Apache License
public void bind(int port) throws Exception { // ??NIO/* w w w. j a va 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, 1024).childHandler(new ChildChannelHandler()); // ??? ChannelFuture f = b.bind(port).sync(); // ??? f.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.phei.netty.codec.msgpack.EchoClient.java
License:Apache License
public void run() throws Exception { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try {/*from www . j a va 2 s.c om*/ Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("msgpack decoder", new MsgpackDecoder()); ch.pipeline().addLast("msgpack encoder", new MsgpackEncoder()); ch.pipeline().addLast(new EchoClientHandler(sendNumber)); } }); // Start the client. ChannelFuture f = b.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { // Shut down the event loop to terminate all threads. group.shutdownGracefully(); } }