org.jboss.netty.channel.group.ChannelGroupFuture Java Examples

The following examples show how to use org.jboss.netty.channel.group.ChannelGroupFuture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemCacheDaemon.java    From fqueue with Apache License 2.0 6 votes vote down vote up
public void stop() {
	log.info("terminating daemon; closing all channels");

	ChannelGroupFuture future = allChannels.close();
	future.awaitUninterruptibly();
	if (!future.isCompleteSuccess()) {
		throw new RuntimeException("failure to complete closing all network channels");
	}
	log.info("channels closed, freeing cache storage");
	try {
		cache.close();
	} catch (IOException e) {
		throw new RuntimeException("exception while closing storage", e);
	}
	channelFactory.releaseExternalResources();

	running = false;
	log.info("successfully shut down");
}
 
Example #2
Source File: MemCacheDaemon.java    From fqueue with Apache License 2.0 6 votes vote down vote up
public void stop() {
	log.info("terminating daemon; closing all channels");

	ChannelGroupFuture future = allChannels.close();
	future.awaitUninterruptibly();
	if (!future.isCompleteSuccess()) {
		throw new RuntimeException("failure to complete closing all network channels");
	}
	log.info("channels closed, freeing cache storage");
	try {
		cache.close();
	} catch (IOException e) {
		throw new RuntimeException("exception while closing storage", e);
	}
	channelFactory.releaseExternalResources();

	running = false;
	log.info("successfully shut down");
}
 
Example #3
Source File: NettyServer.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shutdown server
 */
public void shutdownAll() {
    ChannelGroupFuture future = channelGroup.close();
    future.awaitUninterruptibly();
    loginToClientChannelFactory.releaseExternalResources();
    nioServer.shutdown();
}
 
Example #4
Source File: AirPlayServer.java    From Android-Airplay-Server with MIT License 5 votes vote down vote up
protected void onShutdown() {
	/* Close channels */
	final ChannelGroupFuture allChannelsClosed = channelGroup.close();

	/* Stop all mDNS responders */
	synchronized(jmDNSInstances) {
		for(final JmDNS jmDNS: jmDNSInstances) {
			try {
				jmDNS.unregisterAllServices();
				LOG.info("Unregistered all services on " + jmDNS.getInterface());
			}
			catch (final IOException e) {
				LOG.log(Level.WARNING, "Failed to unregister some services", e);
				
			}
		}
	}

	/* Wait for all channels to finish closing */
	allChannelsClosed.awaitUninterruptibly();
	
	/* Stop the ExecutorService */
	executorService.shutdown();

	/* Release the OrderedMemoryAwareThreadPoolExecutor */
	channelExecutionHandler.releaseExternalResources();
	isOn = false;
	
}
 
Example #5
Source File: HttpDataServer.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public void stop() {
  ChannelGroupFuture future = channelGroup.close();
  future.awaitUninterruptibly();
  factory.releaseExternalResources();

  LOG.info("HttpDataServer shutdown ("
      + this.bindAddr.getAddress().getHostAddress() + ":"
      + this.bindAddr.getPort() + ")");
}
 
Example #6
Source File: RpcServerBootstrap.java    From voyage with Apache License 2.0 4 votes vote down vote up
private void initHttpBootstrap(int myport) {
	logger.info("initHttpBootstrap...........");
	final ServerConfig serverConfig = new ServerConfig(myport);
	final ChannelGroup channelGroup = new DefaultChannelGroup(getClass().getName());
	bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
			//建议用ThreadPoolExecutor代替
			Executors.newCachedThreadPool(),
			Executors.newCachedThreadPool(), serverConfig.getThreadCnt()));
	//设置常见参数
	bootstrap.setOption("tcpNoDelay","true");//禁用nagle算法
	bootstrap.setOption("reuseAddress", "true");
	bootstrap.setOption("SO_RCVBUF",1024*128);
	bootstrap.setOption("SO_SNDBUF",1024*128);
	timer = new HashedWheelTimer();
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		public ChannelPipeline getPipeline() throws Exception {
			ChannelPipeline pipeline = Channels.pipeline();
			int readTimeout = serverConfig.getReadTimeout();
			if (readTimeout > 0) {
				pipeline.addLast("timeout", new ReadTimeoutHandler(timer, readTimeout, TimeUnit.MILLISECONDS));
			}
			pipeline.addLast("decoder", new RpcRequestDecode());
			pipeline.addLast("encoder", new RpcResponseEncode());
			pipeline.addLast("handler", new NettyRpcServerHandler(channelGroup));
			return pipeline;
		}
	});
	
	int port = serverConfig.getPort();
	if (!checkPortConfig(port)) {
		throw new IllegalStateException("port: " + port + " already in use!");
	}

	Channel channel = bootstrap.bind(new InetSocketAddress(port));
	channelGroup.add(channel);
	logger.info("voyage server started");

	waitForShutdownCommand();
	ChannelGroupFuture future = channelGroup.close();
	future.awaitUninterruptibly();
	bootstrap.releaseExternalResources();
	timer.stop();
	timer = null;

	logger.info("voyage server stoped");

}