List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:io.apiman.gateway.platforms.vertx3.services.impl.InitializeIngestorServiceImpl.java
License:Apache License
@Override public void createIngestor(String uuid, Handler<AsyncResult<IngestorToPolicyService>> resultHandler) { log.debug("Creating ingestor who will listen on " + uuid); IngestorToPolicyImpl service = new IngestorToPolicyImpl(vertx); ProxyHelper.registerService(IngestorToPolicyService.class, vertx, service, uuid); PolicyToIngestorService replyProxy = PolicyToIngestorService.createProxy(vertx, uuid + VertxEngineConfig.GATEWAY_ENDPOINT_RESPONSE); PolicyExecutor executor = new PolicyExecutor(engine, service, replyProxy, log); executor.execute();//from w ww .j ava 2s. c om // Open up a IngestorToPolicy service log.debug("Called Future#succededFuture(service)"); resultHandler.handle(Future.succeededFuture(service)); }
From source file:io.apiman.gateway.platforms.vertx3.services.impl.PolicyToIngestorServiceImpl.java
License:Apache License
@Override public void head(VertxApiResponse apiResponse, Handler<AsyncResult<Void>> readyHandler) { log.debug(String.format("%s received ApiResponse %s", uuid, apiResponse)); headHandler.handle(apiResponse);/*from ww w. j ava2 s . c o m*/ // Fire the ready handler immediately readyHandler.handle(Future.succeededFuture((Void) null)); }
From source file:io.apiman.gateway.platforms.vertx3.services.IngestorToPolicyServiceVertxEBProxy.java
License:Apache License
@Override public void head(VertxApiRequest apiRequest, Handler<AsyncResult<Boolean>> readyHandler) { if (closed) { readyHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w ww. j av a 2 s . c o m*/ } JsonObject _json = new JsonObject(); _json.put("apiRequest", apiRequest == null ? null : apiRequest.toJson()); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "head"); _vertx.eventBus().<Boolean>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { readyHandler.handle(Future.failedFuture(res.cause())); } else { readyHandler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:io.apiman.gateway.platforms.vertx3.services.IngestorToPolicyServiceVertxEBProxy.java
License:Apache License
@Override public void end(Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*w w w. jav a 2 s. c om*/ } closed = true; JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "end"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:io.apiman.gateway.platforms.vertx3.services.InitializeIngestorServiceVertxEBProxy.java
License:Apache License
@Override public void createIngestor(String uuid, Handler<AsyncResult<IngestorToPolicyService>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w w w. j a v a2s. co m } JsonObject _json = new JsonObject(); _json.put("uuid", uuid); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "createIngestor"); _vertx.eventBus().<IngestorToPolicyService>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { String addr = res.result().headers().get("proxyaddr"); resultHandler.handle(Future .succeededFuture(ProxyHelper.createProxy(IngestorToPolicyService.class, _vertx, addr))); } }); }
From source file:io.apiman.gateway.platforms.vertx3.services.PolicyToIngestorServiceVertxEBProxy.java
License:Apache License
@Override public void head(VertxApiResponse apiResponse, Handler<AsyncResult<Void>> readyHandler) { if (closed) { readyHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from ww w.j a va 2 s. c o m } JsonObject _json = new JsonObject(); _json.put("apiResponse", apiResponse == null ? null : apiResponse.toJson()); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "head"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { readyHandler.handle(Future.failedFuture(res.cause())); } else { readyHandler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:io.atomix.vertx.VertxFutures.java
License:Apache License
/** * Wraps a Vert.x handler./*from w w w .j a v a 2s . c om*/ */ static <T> BiConsumer<T, Throwable> resultHandler(Handler<AsyncResult<T>> handler, Context context) { Assert.notNull(handler, "handler"); Assert.notNull(context, "context"); return (result, error) -> { if (error == null) { context.runOnContext(v -> Future.succeededFuture(result).setHandler(handler)); } else { context.runOnContext(v -> Future.<T>failedFuture(error).setHandler(handler)); } }; }
From source file:io.atomix.vertx.VertxFutures.java
License:Apache License
/** * Converts a return value./*w w w .ja v a 2 s .c o m*/ */ static <T, U> BiConsumer<T, Throwable> convertHandler(Handler<AsyncResult<U>> handler, Function<T, U> converter, Context context) { return (result, error) -> { if (error == null) { context.runOnContext(v -> Future.succeededFuture(converter.apply(result)).setHandler(handler)); } else { context.runOnContext(v -> Future.<U>failedFuture(error).setHandler(handler)); } }; }
From source file:io.engagingspaces.graphql.proxy.GraphQLSchemaProxy.java
License:Open Source License
@Override public void queryWithVariables(String graphqlQuery, JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) { try {//www . j a va 2 s. c o m QueryResult result = queryBlocking(graphqlQuery, variables); resultHandler.handle(Future.succeededFuture(result)); } catch (RuntimeException ex) { resultHandler.handle(Future.failedFuture(ex)); } }
From source file:io.engagingspaces.graphql.query.QueryableVertxEBProxy.java
License:Apache License
public void query(String graphqlQuery, Handler<AsyncResult<QueryResult>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w w w . ja va 2 s . c o m*/ } JsonObject _json = new JsonObject(); _json.put("graphqlQuery", graphqlQuery); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "query"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture( res.result().body() == null ? null : new QueryResult(res.result().body()))); } }); }