private synchronized void doUndeployChildren(ContextInternal undeployingContext, Handler<AsyncResult<Void>> completionHandler) { if (!children.isEmpty()) { final int size = children.size(); AtomicInteger childCount = new AtomicInteger(); boolean undeployedSome = false; for (Deployment childDeployment: new HashSet<>(children)) { undeployedSome = true; childDeployment.doUndeploy(undeployingContext, ar -> { children.remove(childDeployment); if (ar.failed()) { reportFailure(ar.cause(), undeployingContext, completionHandler); } else if (childCount.incrementAndGet() == size) { // All children undeployed completionHandler.handle(Future.succeededFuture()); } }); } if (!undeployedSome) { // It's possible that children became empty before iterating completionHandler.handle(Future.succeededFuture()); } } else { completionHandler.handle(Future.succeededFuture()); } }
private synchronized void doUndeployChildren(ContextInternal undeployingContext, Handler<AsyncResult<Void>> completionHandler) { if (!children.isEmpty()) { final int size = children.size(); AtomicInteger childCount = new AtomicInteger(); boolean undeployedSome = false; for (Deployment childDeployment: new HashSet<>(children)) { undeployedSome = true; childDeployment.doUndeploy(undeployingContext, ar -> { children.remove(childDeployment); if (ar.failed()) { reportFailure(ar.cause(), undeployingContext, completionHandler); } else if (childCount.incrementAndGet() == size) { // All children undeployed completionHandler.handle(Future.succeededFuture()); } }); } if (!undeployedSome) { // It's possible that children became empty before iterating completionHandler.handle(Future.succeededFuture()); } } else { completionHandler.handle(Future.succeededFuture()); } }