private void doUndeploy(String name, final Handler<Void> doneHandler) { CountingCompletionHandler count = new CountingCompletionHandler(vertx); doUndeploy(name, count); if (doneHandler != null) { count.setHandler(doneHandler); } }
private void doUndeploy(String name, final CountingCompletionHandler parentCount) { if (name == null) { throw new NullPointerException("deployment id is null"); } final Deployment deployment = deployments.remove(name); final CountingCompletionHandler count = new CountingCompletionHandler(vertx); parentCount.incRequired(); // Depth first - undeploy children first for (String childDeployment : deployment.childDeployments) { doUndeploy(childDeployment, count); } if (!deployment.verticles.isEmpty()) { for (final VerticleHolder holder : deployment.verticles) { count.incRequired(); holder.context.execute( new Runnable() { public void run() { try { holder.verticle.stop(); } catch (Throwable t) { vertx.reportException(t); } LoggerFactory.removeLogger(holder.loggerName); holder.context.runCloseHooks(); holder.context.close(); count.complete(); } }); } } if (deployment.parentDeploymentName != null) { Deployment parent = deployments.get(deployment.parentDeploymentName); if (parent != null) { parent.childDeployments.remove(name); } } count.setHandler( new SimpleHandler() { protected void handle() { deployment.moduleReference.decRef(); parentCount.complete(); } }); }
public synchronized void undeployAll(final Handler<Void> doneHandler) { final CountingCompletionHandler count = new CountingCompletionHandler(vertx); if (!deployments.isEmpty()) { // We do it this way since undeploy is itself recursive - we don't want // to attempt to undeploy the same verticle twice if it's a child of // another while (!deployments.isEmpty()) { String name = deployments.keySet().iterator().next(); count.incRequired(); undeploy( name, new SimpleHandler() { public void handle() { count.complete(); } }); } } count.setHandler(doneHandler); }