List of usage examples for io.netty.channel EventLoopGroup shutdownGracefully
Future<?> shutdownGracefully();
From source file:com.ottogroup.bi.spqr.websocket.server.SPQRWebSocketServer.java
License:Apache License
/** * Initializes and executes the server components. Although the other {@link SPQRWebSocketServer#run(String)} * could do the same work this one allows better testing as the {@link InputStream} parameter allows * to inject a variable which may be controlled much better. In the case it would be necessary to * provide a reference to a temporary file which is controlled by the use case ... somehow too much work ;-) * This one is easier. //from ww w .j a v a2 s . c o m * @param configurationFileStream stream holding configuration file content * @throws IOException * @throws InterruptedException */ protected void run(final InputStream configurationFileStream) throws IOException, InterruptedException { /////////////////////////////////////////////////////////////////// // parse out configuration from provided input stream ObjectMapper jsonMapper = new ObjectMapper(); SPQRWebSocketServerConfiguration cfg = jsonMapper.readValue(configurationFileStream, SPQRWebSocketServerConfiguration.class); // /////////////////////////////////////////////////////////////////// PropertyConfigurator.configure(cfg.getLog4jConfigurationFile()); EventLoopGroup bossGroup = new NioEventLoopGroup(cfg.getBossEventGroupThreads()); EventLoopGroup workerGroup = new NioEventLoopGroup(cfg.getWorkerEventGroupThreads()); logger.info( "websocket server [port=" + cfg.getPort() + ", bossGroupThreads=" + cfg.getBossEventGroupThreads() + ", workerGroupThreads=" + cfg.getWorkerEventGroupThreads() + "]"); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SPQRWebSocketServerInitializer()); Channel channel = bootstrap.bind(cfg.getPort()).sync().channel(); channel.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.palace.seeds.net.netty.EchoClient.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try {//from ww w.ja v a 2 s. c om 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 { ChannelPipeline p = ch.pipeline(); p.addLast(new EchoClientHandler()); } }); // 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(); } }
From source file:com.papteco.client.netty.LoginClientBuilder.java
License:Apache License
public void validateUser() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {//w w w.j a va 2 s . c o 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 LoginClientHandler(username, password)); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("login_sym_port"))) .sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.papteco.client.netty.ObjectEchoBuilder.java
License:Apache License
public void runInitinal() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {/* w w w .j ava2 s . 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 InitinalClientHandler(username)); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port"))) .sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.papteco.client.netty.ObjectEchoBuilder.java
License:Apache License
public void runSelProjectEcho() throws InterruptedException { EventLoopGroup group = new NioEventLoopGroup(); try {//from w ww . j a 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 SelProjectClientHandler(inPrjCde, SharedBoard.LOGIN_USER)); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port"))) .sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.papteco.client.netty.ObjectEchoBuilder.java
License:Apache License
public void runDownFileEcho() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {/*w w w . ja v a 2 s. 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 DownFileClientHandler(qItem)); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port"))) .sync().channel().closeFuture().sync(); } catch (Throwable e) { e.printStackTrace(); } finally { group.shutdownGracefully(); } }
From source file:com.papteco.client.netty.ObjectEchoBuilder.java
License:Apache License
public void getMailsList() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {//from ww w . ja v a 2s . c o 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 LoadMailslistClientHandler(username)); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port"))) .sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.papteco.client.netty.ObjectEchoBuilder.java
License:Apache License
public void downMailFile() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {//from w w w . j a v a 2 s . c o 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 DownMailClientHandler(username, mailfile)); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port"))) .sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }
From source file:com.papteco.client.netty.OpenFileServerBuilder.java
License:Apache License
public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {/*from ww w . j av a2 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 OpenFileServerHandler()); } }); // Bind and start to accept incoming connections. b.bind(PortTranslater(envsetting.getProperty("open_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.client.netty.QuartzMailBackupBuilder.java
License:Apache License
public void runMailBackup() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try {//from w w w . j a va 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 QuartzMailBackupClientHandler()); } }); b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("email_bkp_port"))) .sync().channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } }