List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java
License:Apache License
public OrientDBService getEdges(String sourceId, String destinationId, String label, Handler<AsyncResult<List<Record>>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/* ww w . j a va 2 s.c om*/ JsonObject _json = new JsonObject(); _json.put("sourceId", sourceId); _json.put("destinationId", destinationId); _json.put("label", label); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getEdges"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture(res.result().body().stream().map( o -> o instanceof Map ? new Record(new JsonObject((Map) o)) : new Record((JsonObject) o)) .collect(Collectors.toList()))); } }); return this; }
From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java
License:Apache License
public OrientDBService getEdge(JsonObject edgeQuery, Handler<AsyncResult<List<Record>>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w w w .j a va2 s .com JsonObject _json = new JsonObject(); _json.put("edgeQuery", edgeQuery); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getEdge"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture(res.result().body().stream().map( o -> o instanceof Map ? new Record(new JsonObject((Map) o)) : new Record((JsonObject) o)) .collect(Collectors.toList()))); } }); return this; }
From source file:io.servicecomb.foundation.vertx.AsyncResultCallback.java
License:Apache License
default void success(T data) { handle(Future.succeededFuture(data)); }
From source file:microservicerx.example.impl.MicroServiceRxImpl.java
@Override public void cold(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) { System.out.println("Processing..."); Observable<JsonObject> observable; JsonObject result = document.copy(); if (!document.containsKey("name")) { observable = Observable.error(new ServiceException(NO_NAME_ERROR, "No name in the document")); } else if (document.getString("name").isEmpty() || document.getString("name").equalsIgnoreCase("bad")) { observable = Observable.error(new ServiceException(BAD_NAME_ERROR, "Bad name in the document")); } else {// w w w . ja v a 2 s.c o m result.put("approved", true); observable = Observable.just(result.copy().put("id", 0), result.copy().put("id", 1)); } DistributedObservable dist = DistributedObservable.toDistributable(observable.map(j -> (Object) j), vertx); resultHandler.handle(Future.succeededFuture(dist.toJsonObject())); }
From source file:microservicerx.example.impl.MicroServiceRxImpl.java
@Override public void hot(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) { System.out.println("Processing..."); BehaviorSubject<Object> subject = BehaviorSubject.create(); JsonObject result = document.copy(); if (!document.containsKey("name")) { subject.onError(new ServiceException(NO_NAME_ERROR, "No name in the document")); } else if (document.getString("name").isEmpty() || document.getString("name").equalsIgnoreCase("bad")) { subject.onError(new ServiceException(BAD_NAME_ERROR, "Bad name in the document")); } else {/*from www .j av a2 s. c o m*/ Long timerId = vertx.setPeriodic(1000, l -> { JsonObject event = result.copy().put("approved", true).put("now", System.currentTimeMillis()); subject.onNext(event); }); vertx.setTimer(3 * 1000, l -> { vertx.cancelTimer(timerId); subject.onCompleted(); }); } DistributedObservable dist = DistributedObservable.toDistributable(subject, vertx); resultHandler.handle(Future.succeededFuture(dist.toJsonObject())); }
From source file:name.bpdp.vertx.changeme.ChangemeServiceVertxEBProxy.java
License:Apache License
public void method1(String method1Arg, Handler<AsyncResult<String>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w w w. j a va 2s .co m*/ } JsonObject _json = new JsonObject(); _json.put("method1Arg", method1Arg); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "method1"); _vertx.eventBus().<String>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:net.kuujo.copycat.vertx.impl.CopycatAsyncMap.java
License:Apache License
/** * Handles a CompletableFuture result.//from w ww. j a v a 2 s .c om */ private <T> void handleResult(T result, Throwable error, Handler<AsyncResult<T>> resultHandler) { if (error == null) { Future.succeededFuture(result).setHandler(resultHandler); } else { Future.<T>failedFuture(error).setHandler(resultHandler); } }
From source file:net.kuujo.copycat.vertx.impl.CopycatAsyncMultiMap.java
License:Apache License
@Override public void remove(K k, V v, Handler<AsyncResult<Boolean>> resultHandler) { map.remove(k, v).whenComplete((result, error) -> { if (error == null) { Future.succeededFuture(result).setHandler(resultHandler); } else {// w ww.j av a2s . c om Future.<Boolean>failedFuture(error).setHandler(resultHandler); } }); }
From source file:net.kuujo.vertigo.deployment.impl.LocalDeploymentManager.java
License:Apache License
@Override public DeploymentManager getNetwork(String id, Handler<AsyncResult<NetworkContext>> doneHandler) { NetworkContext context = vertx.sharedData().<String, NetworkContext>getLocalMap(NETWORKS_KEY).get(id); if (context == null) { Future.<NetworkContext>failedFuture( new VertigoException(String.format("Invalid network %s: NetworkConfig not found", id))) .setHandler(doneHandler); } else {/*from w w w . ja va 2s . c o m*/ Future.succeededFuture(context).setHandler(doneHandler); } return this; }
From source file:net.kuujo.vertigo.deployment.impl.LocalDeploymentManager.java
License:Apache License
@Override public DeploymentManager getNetworkReference(String id, Handler<AsyncResult<NetworkReference>> doneHandler) { return getNetwork(id, result -> { if (result.succeeded()) { try { NetworkReferenceImpl ref = new NetworkReferenceImpl(vertx, result.result()); doneHandler.handle(Future.succeededFuture(ref)); } catch (Throwable throwable) { doneHandler.handle(Future.failedFuture(throwable)); }/* w w w . ja va 2 s.co m*/ } else { doneHandler.handle(Future.failedFuture(result.cause())); } }); }