/** * Map the result of a future to {@code null}.<p> * * This is a conveniency for {@code future.map((T) null)} or {@code future.map((Void) null)}.<p> * * When this future succeeds, {@code null} will complete the future returned by this method call.<p> * * When this future fails, the failure will be propagated to the returned future. * * @return the mapped future */ @Override default <V> Future<V> mapEmpty() { return (Future<V>) AsyncResult.super.mapEmpty(); }
/** * Internal method that closes all servers when Vert.x is closing */ public void closeAll(Handler<AsyncResult<Void>> handler) { List<HttpHandlers> list = httpHandlerMgr.handlers(); List<Future> futures = list.stream() .<Future<Void>>map(handlers -> Future.future(handlers.server::close)) .collect(Collectors.toList()); CompositeFuture fut = CompositeFuture.all(futures); fut.setHandler(ar -> handler.handle(ar.mapEmpty())); }
/** * Internal method that closes all servers when Vert.x is closing */ public void closeAll(Handler<AsyncResult<Void>> handler) { List<Handlers> list = handlerManager.handlers(); List<Future> futures = list.stream() .<Future<Void>>map(handlers -> Future.future(handlers.server::close)) .collect(Collectors.toList()); CompositeFuture fut = CompositeFuture.all(futures); fut.setHandler(ar -> handler.handle(ar.mapEmpty())); }
@Test public void testAsyncResultMapEmpty() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map = res.mapEmpty(); f.complete("foobar"); assertNull(null, map.result()); assertNull(map.cause()); }
/** * Map the result of a future to {@code null}.<p> * * This is a conveniency for {@code future.map((T) null)} or {@code future.map((Void) null)}.<p> * * When this future succeeds, {@code null} will complete the future returned by this method call.<p> * * When this future fails, the failure will be propagated to the returned future. * * @return the mapped future */ @Override default <V> Future<V> mapEmpty() { return (Future<V>) AsyncResult.super.mapEmpty(); }
/** * Internal method that closes all servers when Vert.x is closing */ public void closeAll(Handler<AsyncResult<Void>> handler) { List<HttpHandlers> list = httpHandlerMgr.handlers(); List<Future> futures = list.stream() .<Future<Void>>map(handlers -> Future.future(handlers.server::close)) .collect(Collectors.toList()); CompositeFuture fut = CompositeFuture.all(futures); fut.setHandler(ar -> handler.handle(ar.mapEmpty())); }
/** * Internal method that closes all servers when Vert.x is closing */ public void closeAll(Handler<AsyncResult<Void>> handler) { List<Handlers> list = handlerManager.handlers(); List<Future> futures = list.stream() .<Future<Void>>map(handlers -> Future.future(handlers.server::close)) .collect(Collectors.toList()); CompositeFuture fut = CompositeFuture.all(futures); fut.setHandler(ar -> handler.handle(ar.mapEmpty())); }
@Test public void testAsyncResultMapEmpty() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map = res.mapEmpty(); f.complete("foobar"); assertNull(null, map.result()); assertNull(map.cause()); }
@Override public void commit(Handler<AsyncResult<Void>> completionHandler) { this.stream.commit(completionHandler != null ? ar -> completionHandler.handle(ar.mapEmpty()) : null); }
@Override public void proxy(Handler<AsyncResult<Void>> completionHandler) { send(ar -> { if (ar.succeeded()) { ProxyResponse resp = ar.result(); resp.send(completionHandler); } else { completionHandler.handle(ar.mapEmpty()); } }); }
public void rollback(Handler<AsyncResult<Void>> handler) { schedule(doQuery("ROLLBACK", ar -> { disposeHandler.handle(null); if (handler != null) { handler.handle(ar.mapEmpty()); } })); }
public void rollback(Handler<AsyncResult<Void>> handler) { schedule(doQuery("ROLLBACK", ar -> { disposeHandler.handle(null); if (handler != null) { handler.handle(ar.mapEmpty()); } })); }
public void listen(int port, String host, Handler<AsyncResult<Void>> completionHandler) { server.listen(port, host, ar -> completionHandler.handle(ar.mapEmpty())); }
@Override public void start(Future<Void> future) throws Exception { Router router = Router.router(vertx); router.get().handler(rc -> rc.response().end("OK")); router.post().handler(BodyHandler.create()); router.post().handler(this::handle); vertx.createHttpServer() .requestHandler(router::accept) .listen(config().getInteger("port", 8080), ar -> future.handle(ar.mapEmpty())); }
.send(ar -> { if (ar.failed()) { completionHandler.handle(ar.mapEmpty()); return;
@Override public void start(Future<Void> startFuture) { HttpClient proxyClient = vertx.createHttpClient(new HttpClientOptions(clientOptions)); HttpServer proxyServer = vertx.createHttpServer(new HttpServerOptions(proxyOptions)); HttpProxy proxy = HttpProxy.reverseProxy(proxyClient); proxy.selector(selector); proxyServer.requestHandler(proxy); proxyServer.listen(ar -> startFuture.handle(ar.mapEmpty())); } }, ar -> {
@Override public void start(Future<Void> future) { message = config().getString("message"); String address = config().getString("address"); Future<Void> endpointReady = Future.future(); Future<Void> updateReady = Future.future(); vertx.eventBus().<JsonObject>consumer(address + "/update") .handler(json -> { message = json.body().getString("message"); json.reply("OK"); }) .completionHandler(updateReady); vertx.eventBus().consumer(address) .handler(msg -> msg.reply(message)) .completionHandler(endpointReady); CompositeFuture.all(endpointReady, updateReady).setHandler(x -> future.handle(x.mapEmpty())); } }
@Override public void start(Future<Void> future) { message = config().getString("message"); String address = config().getString("address"); Future<Void> endpointReady = Future.future(); Future<Void> updateReady = Future.future(); vertx.eventBus().<JsonObject>consumer(address + "/update") .handler(json -> { message = json.body().getString("message"); json.reply("OK"); }) .completionHandler(updateReady); vertx.eventBus().consumer(address) .handler(msg -> msg.reply(message)) .completionHandler(endpointReady); CompositeFuture.all(endpointReady, updateReady).setHandler(x -> future.handle(x.mapEmpty())); } }