protected void stopServerBootstrap() { // close all channels LOG.info("ConnectionlessBootstrap disconnecting from {}:{}", configuration.getHost(), configuration.getPort()); LOG.trace("Closing {} channels", allChannels.size()); ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); // close server external resources if (datagramChannelFactory != null) { datagramChannelFactory.releaseExternalResources(); datagramChannelFactory = null; } // and then shutdown the thread pools if (workerPool != null) { workerPool.shutdown(); workerPool = null; } }
protected void stopServerBootstrap() { // close all channels LOG.info("ServerBootstrap unbinding from {}:{}", configuration.getHost(), configuration.getPort()); LOG.trace("Closing {} channels", allChannels.size()); ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); // close server external resources if (channelFactory != null) { channelFactory.releaseExternalResources(); channelFactory = null; } // and then shutdown the thread pools if (bossPool != null) { bossPool.shutdown(); bossPool = null; } if (workerPool != null) { workerPool.shutdown(); workerPool = null; } }
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"); }
private void sendServerClosedPacket() { logger.info("sendServerClosedPacket start"); final ChannelGroupFuture write = this.channelGroup.write(new ServerClosePacket()); write.awaitUninterruptibly(5000, TimeUnit.MILLISECONDS); if (logger.isWarnEnabled()) { write.addListener(new ChannelGroupFutureListener() { private final ChannelFutureListener listener = new WriteFailFutureListener(logger, "serverClosePacket write fail", "serverClosePacket write success"); @Override public void operationComplete(ChannelGroupFuture future) throws Exception { for (ChannelFuture channelFuture : future) { channelFuture.addListener(listener); } } }); } logger.info("sendServerClosedPacket end"); }
public static void main(String[] args) throws Exception { Executor executor = Executors.newCachedThreadPool(); ChannelFactory factory = new NioServerSocketChannelFactory(executor, executor); ServerBootstrap sb = new ServerBootstrap(factory); ClientSocketChannelFactory cf = new NioClientSocketChannelFactory(executor, executor); sb.setPipelineFactory(new ProxyPipelineFactory(cf, RtmpConfig.PROXY_REMOTE_HOST, RtmpConfig.PROXY_REMOTE_PORT)); InetSocketAddress socketAddress = new InetSocketAddress(RtmpConfig.PROXY_PORT); sb.bind(socketAddress); logger.info("proxy server started, listening on {}", socketAddress); Thread monitor = new StopMonitor(RtmpConfig.PROXY_STOP_PORT); monitor.start(); monitor.join(); ChannelGroupFuture future = ALL_CHANNELS.close(); logger.info("closing channels"); future.awaitUninterruptibly(); logger.info("releasing resources"); factory.releaseExternalResources(); logger.info("server stopped"); }
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; }
@Override public void stopServer() { if (channelGroup != null) { ChannelGroupFuture future = channelGroup.close(); future.awaitUninterruptibly(); } if (bootstrap != null) { bootstrap.getFactory().releaseExternalResources(); } if (timer != null) { timer.stop(); } }
public void destroy() throws Exception { ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); if (!future.isCompleteSuccess()) { throw new RuntimeException("failure to complete closing all network channels"); } try { cache.close(); } catch (IOException e) { throw new RuntimeException("exception while closing storage", e); } channelFactory.releaseExternalResources(); logger.info("memcached destroyed"); }
protected void onShutdown() { /* Close channels */ final ChannelGroupFuture allChannelsClosed = channelGroup.close(); /* Stop all mDNS responders */ synchronized(jmDNSInstances) { for(final JmDNS jmDNS: jmDNSInstances) { try { jmDNS.unregisterAllServices(); LogManager.i("Unregistered all services on " + jmDNS.getInterface()); } catch (final IOException e) { LogManager.e("Level.WARNING Failed to unregister some services " +Log.getStackTraceString(e)); } } } /* Wait for all channels to finish closing */ allChannelsClosed.awaitUninterruptibly(); /* Stop the ExecutorService */ executorService.shutdown(); /* Release the OrderedMemoryAwareThreadPoolExecutor */ channelExecutionHandler.releaseExternalResources(); }
private void sendPing() { logger.debug("sendPing"); final TimerTask pintTask = new TimerTask() { @Override public void run(Timeout timeout) throws Exception { if (timeout.isCancelled()) { newPingTimeout(this); return; } final ChannelGroupFuture write = channelGroup.write(PingPacket.PING_PACKET); if (logger.isWarnEnabled()) { write.addListener(new ChannelGroupFutureListener() { private final ChannelFutureListener listener = new WriteFailFutureListener(logger, "ping write fail", "ping write success"); @Override public void operationComplete(ChannelGroupFuture future) throws Exception { if (logger.isWarnEnabled()) { for (ChannelFuture channelFuture : future) { channelFuture.addListener(listener); } } } }); } newPingTimeout(this); } }; newPingTimeout(pintTask); }
public void stop() { ChannelGroupFuture future = channelGroup.close(); future.awaitUninterruptibly(); factory.releaseExternalResources(); LOG.info("HttpDataServer shutdown (" + this.bindAddr.getAddress().getHostAddress() + ":" + this.bindAddr.getPort() + ")"); }
@Override public void stop() { System.out.println("Shutting down"); ChannelGroupFuture shutdown = _allChannels.disconnect(); shutdown.awaitUninterruptibly(); _bootstrap.releaseExternalResources(); _executionHandler.releaseExternalResources(); }
public void stop() { try { final ChannelGroupFuture closeFuture = myAllOpenChannels.close(); closeFuture.awaitUninterruptibly(); } finally { myChannelFactory.releaseExternalResources(); } }
public static void main(String[] args) throws Exception { final ChannelFactory factory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); final ServerBootstrap bootstrap = new ServerBootstrap(factory); bootstrap.setPipelineFactory(new ServerPipelineFactory()); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); final InetSocketAddress socketAddress = new InetSocketAddress(RtmpConfig.SERVER_PORT); bootstrap.bind(socketAddress); logger.info("server started, listening on: {}", socketAddress); final Thread monitor = new StopMonitor(RtmpConfig.SERVER_STOP_PORT); monitor.start(); monitor.join(); TIMER.stop(); final ChannelGroupFuture future = CHANNELS.close(); logger.info("closing channels"); future.awaitUninterruptibly(); logger.info("releasing resources"); factory.releaseExternalResources(); logger.info("server stopped"); }
/** * stop * * Implement this {@link org.shanbo.feluca.common.Server} method */ public void postStop() throws Exception { ChannelGroupFuture closeFuture = allChannels.close(); closeFuture.awaitUninterruptibly(); if (channelFactory != null) channelFactory.releaseExternalResources(); }
public void closeChannels() { LOGGER.info("Closing {} open channels.", size()); channels.close().addListener(new ChannelGroupFutureListener() { @Override public void operationComplete(ChannelGroupFuture future) { LOGGER.info("Closed all channels."); } }); }
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"); }
public void stop() { ChannelGroupFuture future = getChannelGroup().close(); future.awaitUninterruptibly(); }
@Override protected void serverShutdown() { ChannelGroupFuture channelGroupFuture = CHANNEL_GROUP.close(); channelGroupFuture.awaitUninterruptibly(); }
@Override protected void doStop() throws Exception { LOG.debug("Stopping producer at address: {}", configuration.getAddress()); // close all channels LOG.trace("Closing {} channels", allChannels.size()); ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); // release the external resource here and we keep the timer open // and then shutdown the thread pools if (bossPool != null) { bossPool.shutdown(); bossPool = null; } if (workerPool != null) { if (workerPool instanceof ExternalResourceReleasable) { // this will first invoke workerPool#shutdown() internally (e.g. org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool) ((ExternalResourceReleasable) workerPool).releaseExternalResources(); } else { workerPool.shutdown(); } workerPool = null; } if (pool != null) { if (LOG.isDebugEnabled()) { LOG.debug("Stopping producer with channel pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle()); } pool.close(); pool = null; } if (channelFactory != null) { // this will first invoke channelFactory#shutdown() internally (see it's javadoc) channelFactory.releaseExternalResources(); channelFactory = null; } if (datagramChannelFactory != null) { // this will first invoke datagramChannelFactory#shutdown() internally (see it's javadoc) datagramChannelFactory.releaseExternalResources(); datagramChannelFactory = null; } super.doStop(); }
/** * Stop server */ public void stop() { ChannelGroupFuture future = getChannelGroup().close(); future.awaitUninterruptibly(); }
public void stopListening() { final ChannelGroupFuture closeFuture = myAllOpenChannels.close(); closeFuture.awaitUninterruptibly(); }
public void shutdownOVSDBServer() { ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); sfactory.releaseExternalResources(); }
public void shutdown() { ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); factory.releaseExternalResources(); logger.info("Server shutdown"); }
public ChannelGroupFuture closeChannels() { return channels.close(); }
public void stop() { ChannelGroupFuture f = channels.close(); f.awaitUninterruptibly(); factory.releaseExternalResources(); }
/** * Wait for {@link ChannelGroupFuture} to finish, while periodically * reporting progress. * * @param future ChannelGroupFuture * @param progressable Progressable for reporting progress (Job context) */ public static void awaitChannelGroupFuture(ChannelGroupFuture future, Progressable progressable) { waitForever(new ChannelGroupFutureWaitable(future), progressable); }
/** * Constructor * * @param future ChannelGroupFuture which we want to wait for */ public ChannelGroupFutureWaitable(ChannelGroupFuture future) { this.future = future; }