private ThrowingConsumer<io.vertx.rxjava.core.Vertx> closeRx1Vertx() { return vertx -> { CountDownLatch latch = new CountDownLatch(1); AtomicReference<Throwable> errorBox = new AtomicReference<>(); vertx.close(ar -> { if (ar.failed()) { errorBox.set(ar.cause()); } latch.countDown(); }); if (!latch.await(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT)) { throw new TimeoutException("Closing the Vertx context timed out"); } Throwable throwable = errorBox.get(); if (throwable != null) { if (throwable instanceof Exception) { throw (Exception) throwable; } else { throw new VertxException(throwable); } } }; }
/** * Like {@link io.vertx.rxjava.core.Vertx#close} but the completionHandler will be called when the close is complete * @return * @deprecated use {@link #rxClose} instead */ @Deprecated() public Observable<Void> closeObservable() { io.vertx.rx.java.ObservableFuture<Void> completionHandler = io.vertx.rx.java.RxHelper.observableFuture(); close(completionHandler.toHandler()); return completionHandler; }
/** * Like {@link io.vertx.rxjava.core.Vertx#close} but the completionHandler will be called when the close is complete * @return */ public Single<Void> rxClose() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { close(fut); })); }
/** * Like {@link io.vertx.rxjava.core.Vertx#close} but the completionHandler will be called when the close is complete * @return */ public Single<Void> rxClose() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { close(fut); })); }
@Override public void destroy() throws Exception { Set<String> deploymentIds = vertx.deploymentIDs(); boolean hasDeployedVerticles = !deploymentIds.isEmpty(); if (hasDeployedVerticles) { CountDownLatch countDownLatch = new CountDownLatch(deploymentIds.size()); deploymentIds.forEach(id -> vertx.rxUndeploy(id) .doOnSuccess(foo -> countDownLatch.countDown()) .doOnError(e -> { log.error("", e); countDownLatch.countDown(); }) .subscribe()); countDownLatch.await(); } vertx.close(); } }