private void actualClose(final Context closeContext, final Handler<Void> done) { if (id != null) { vertx.sharedNetServers().remove(id); } for (DefaultNetSocket sock : socketMap.values()) { sock.internalClose(); } // We need to reset it since sock.internalClose() above can call into the close handlers of // sockets on the same thread // which can cause context id for the thread to change! Context.setContext(closeContext); ChannelGroupFuture fut = serverChannelGroup.close(); if (done != null) { fut.addListener( new ChannelGroupFutureListener() { public void operationComplete(ChannelGroupFuture channelGroupFuture) throws Exception { executeCloseDone(closeContext, done); } }); } }
private void stopConfiguration() throws Exception { if (configuration == null) { // abort received but script not prepared, therefore entire script failed if (progress == null) { progress = new ScriptProgress(newSequential(0, 0), ""); } RegionInfo scriptInfo = progress.getScriptInfo(); progress.addScriptFailure(scriptInfo); } else { // stopping the configuration will implicitly trigger the script complete listener // to handle incomplete script that is being aborted by canceling the finish future // clear out the pipelines for new connections to avoid impacting the observed script for (ServerBootstrapResolver serverResolver : configuration.getServerResolvers()) { ServerBootstrap server = serverResolver.resolve(); server.setPipelineFactory(pipelineFactory(pipeline(closeOnExceptionHandler))); } for (ClientBootstrapResolver clientResolver : configuration.getClientResolvers()) { ClientBootstrap client = clientResolver.resolve(); client.setPipelineFactory(pipelineFactory(pipeline(closeOnExceptionHandler))); } // remove each handler from the configuration pipelines // this will trigger failures for any handlers on a pipeline for an incomplete stream // including pipelines not yet associated with any channel for (ChannelPipeline pipeline : configuration.getClientAndServerPipelines()) { stopStream(pipeline); } // cancel any pending binds and connects for (ChannelFuture bindFuture : bindFutures) { bindFuture.cancel(); } for (ChannelFuture connectFuture : connectFutures) { connectFuture.cancel(); } // close server and client channels final ChannelGroupFuture closeFuture = serverChannels.close(); closeFuture.addListener( new ChannelGroupFutureListener() { @Override public void operationComplete(final ChannelGroupFuture future) { clientChannels.close(); } }); for (AutoCloseable resource : configuration.getResources()) { try { resource.close(); } catch (Exception e) { // ignore } } } }
@Override public final void addListener(final ChannelGroupFutureListener listener) { synchronized (conditionSetLock) { if (!conditionSetFlag) { listeners.put(listener, listener); return; } } if (condition) { backedChannelGroupFuture.addListener(listener); } else { try { listener.operationComplete(this); } catch (final Throwable t) { LOGGER.warn("Exception occured when executing ChannelGroupFutureListener", t); } } }
/** * Set the condition value. * * @param conditionSatisfied if the condition is satisfied. */ public final void setCondition(final boolean conditionSatisfied) { synchronized (conditionSetLock) { condition = conditionSatisfied; conditionSetFlag = true; if (condition) { for (final ChannelGroupFutureListener l : listeners.keySet()) { backedChannelGroupFuture.addListener(l); } listeners.clear(); } else { for (final ChannelGroupFutureListener l : listeners.keySet()) { try { l.operationComplete(this); } catch (final Throwable t) { LOGGER.warn("Exception occured when executing ChannelGroupFutureListener", t); } } } conditionSetLock.notifyAll(); } }