List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
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 w ww . j a v a2 s. com*/ } 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.engagingspaces.graphql.proxy.GraphQLSchemaProxy.java
License:Open Source License
@Override public void queryWithVariables(String graphqlQuery, JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) { try {//from w w w .j a v a 2 s . c om 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;//w ww. j a v a 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()))); } }); }
From source file:io.engagingspaces.graphql.query.QueryableVertxEBProxy.java
License:Apache License
public void queryWithVariables(String graphqlQuery, JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from www .ja va 2s .co m } JsonObject _json = new JsonObject(); _json.put("graphqlQuery", graphqlQuery); _json.put("variables", variables); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "queryWithVariables"); _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()))); } }); }
From source file:io.engagingspaces.graphql.query.QueryableVertxEBProxy.java
License:Apache License
public void resolveType(String typeResolverId, JsonObject typeHolder, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w w w .j a va2s . co m*/ } JsonObject _json = new JsonObject(); _json.put("typeResolverId", typeResolverId); _json.put("typeHolder", typeHolder); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "resolveType"); _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())); } }); }
From source file:io.engagingspaces.graphql.query.QueryableVertxEBProxy.java
License:Apache License
public void fetchData(String dataFetcherId, JsonObject dataFetchingEnvironment, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*w ww . j a v a 2s . c om*/ } JsonObject _json = new JsonObject(); _json.put("dataFetcherId", dataFetcherId); _json.put("dataFetchingEnvironment", dataFetchingEnvironment); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "fetchData"); _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())); } }); }
From source file:io.engagingspaces.graphql.schema.SchemaDefinition.java
License:Open Source License
/** * Executes the GraphQL query on the GraphQL schema proxy using the provided variables. * * @param graphqlQuery the graphql query * @param resultHandler the result handler with the graphql query result on success, or a failure *///from www. ja va 2 s . com @Override default void queryWithVariables(String graphqlQuery, JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) { try { QueryResult result = queryBlocking(graphqlQuery, variables); resultHandler.handle(Future.succeededFuture(result)); } catch (RuntimeException ex) { resultHandler.handle(Future.failedFuture(ex)); } }
From source file:io.engagingspaces.graphql.servicediscovery.client.GraphQLClient.java
License:Open Source License
/** * Lookup a GraphQL service record using the provided filter and if found, retrieve the service proxy of type * {@link Queryable} used for querying./*from w w w . j a va 2 s . co m*/ * * @param discovery the service discovery instance * @param filter the filter to select the schema * @param resultHandler the result handler */ static void getSchemaProxy(ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<Queryable>> resultHandler) { Objects.requireNonNull(discovery, "Service discovery cannot be null"); Objects.requireNonNull(resultHandler, "Schema proxy result handler cannot be null"); discovery.getRecord(filter, rh -> { if (rh.failed()) { resultHandler.handle(Future.failedFuture(rh.cause())); } else { if (rh.result() == null) { resultHandler.handle(Future.failedFuture("Failed to find schema proxy using filter " + filter)); } else { Record record = rh.result(); if (!SERVICE_TYPE.equals(record.getType())) { resultHandler.handle(Future.failedFuture("Record '" + record.getName() + "' is of wrong type '" + record.getType() + "'. Expected: " + SERVICE_TYPE)); } else { getSchemaProxy(discovery, rh.result(), resultHandler); } } } }); }
From source file:io.engagingspaces.graphql.servicediscovery.client.GraphQLClient.java
License:Open Source License
/** * Get the GraphQL service proxy that is associated with the provided service record. * * @param discovery the service discovery instance * @param record the service record of a published GraphQL service * @param resultHandler the result handler *//*ww w .ja v a2 s . com*/ static void getSchemaProxy(ServiceDiscovery discovery, Record record, Handler<AsyncResult<Queryable>> resultHandler) { Objects.requireNonNull(discovery, "Service discovery cannot be null"); Objects.requireNonNull(record, "Record cannot be null"); Objects.requireNonNull(resultHandler, "Schema proxy result handler cannot be null"); if (!SERVICE_TYPE.equals(record.getType())) { resultHandler.handle(Future.failedFuture("Record '" + record.getName() + "' is of wrong type '" + record.getType() + "'. Expected: " + SERVICE_TYPE)); } else if (!Status.UP.equals(record.getStatus())) { resultHandler.handle(Future.failedFuture("Record status indicates service '" + record.getName() + "' is: " + record.getStatus() + ". Expected: " + Status.UP)); } else if (record.getRegistration() == null) { resultHandler.handle( Future.failedFuture("Record '" + record.getName() + "' has no service discovery registration")); } else { ServiceReference reference = discovery.getReference(record); Queryable queryable = reference.cached() == null ? reference.get() : reference.cached(); reference.release(); resultHandler.handle(Future.succeededFuture(queryable)); } }
From source file:io.engagingspaces.graphql.servicediscovery.client.GraphQLClient.java
License:Open Source License
/** * Executes the parametrized GraphQL query on the GraphQL service associated with the provided service record. * <p>/* ww w. j a v a 2s.c om*/ * On success a {@link QueryResult} is returned. Note that at * this point the GraphQL query may still have failed, so be sure to check the * {@link QueryResult#getErrors()} property afterwards. * <p> * The top-level keys in the `variables` parameter represent the variable names that are used in the query, and * the json values are passed as {@link Object} to the query executor. * * @param discovery the service discovery instance * @param record the service record of a published GraphQL service * @param query the GraphQL query * @param variables the variables to pass to the query executor * @param resultHandler the result handler */ static void executeQuery(ServiceDiscovery discovery, Record record, String query, JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) { Objects.requireNonNull(discovery, "Service discovery cannot be null"); Objects.requireNonNull(record, "Record cannot be null"); Objects.requireNonNull(query, "GraphQL query cannot be null"); Objects.requireNonNull(resultHandler, "Query result handler cannot be null"); getSchemaProxy(discovery, record, rh -> { if (rh.succeeded()) { rh.result().queryWithVariables(query, variables, resultHandler); } else { resultHandler.handle(Future.failedFuture(rh.cause())); } }); }