List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:se.liquidbytes.jel.system.impl.JelServiceImpl.java
License:Apache License
@Override public void listSupportedAdapterDevices(String id, Handler<AsyncResult<JsonArray>> resultHandler) { try {//from w w w . ja v a 2s . c o m JelService.deviceManager().listSupportedAdapterDevices(id, (onResult) -> { if (onResult.succeeded()) { resultHandler.handle(Future.succeededFuture(onResult.result())); } else { resultHandler.handle(Future.failedFuture(onResult.cause().getMessage())); } }); } catch (Exception ex) { resultHandler.handle(Future.failedFuture(ex.getMessage())); } }
From source file:se.liquidbytes.jel.system.impl.JelServiceImpl.java
License:Apache License
@Override public void listAllDevices(Handler<AsyncResult<JsonArray>> resultHandler) { try {/*from www . jav a2 s . co m*/ JelService.deviceManager().listAllDevices((onResult) -> { if (onResult.succeeded()) { resultHandler.handle(Future.succeededFuture(onResult.result())); } else { resultHandler.handle(Future.failedFuture(onResult.cause().getMessage())); } }); } catch (Exception ex) { resultHandler.handle(Future.failedFuture(ex.getMessage())); } }
From source file:se.liquidbytes.jel.system.impl.JelServiceImpl.java
License:Apache License
@Override public void retrieveDeviceValue(String deviceId, Handler<AsyncResult<JsonObject>> resultHandler) { try {//www. j av a 2 s . c o m JelService.deviceManager().retrieveDeviceValue(deviceId, (onResult) -> { if (onResult.succeeded()) { resultHandler.handle(Future.succeededFuture(onResult.result())); } else { resultHandler.handle(Future.failedFuture(onResult.cause().getMessage())); } }); } catch (Exception ex) { resultHandler.handle(Future.failedFuture(ex.getMessage())); } }
From source file:se.liquidbytes.jel.system.impl.JelServiceImpl.java
License:Apache License
@Override public void updateDeviceValue(String deviceId, String value, Handler<AsyncResult<Void>> resultHandler) { try {//from ww w. java 2 s . c o m JelService.deviceManager().updateDeviceValue(deviceId, value, (onResult) -> { if (onResult.succeeded()) { resultHandler.handle(Future.succeededFuture(onResult.result())); } else { resultHandler.handle(Future.failedFuture(onResult.cause().getMessage())); } }); } catch (Exception ex) { resultHandler.handle(Future.failedFuture(ex.getMessage())); } }
From source file:servicefactories.BasicServiceVertxEBProxy.java
License:Apache License
public void find(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//w ww . ja v a 2s . co m } JsonObject _json = new JsonObject(); _json.put("document", document); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "find"); _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:servicefactories.BasicServiceVertxEBProxy.java
License:Apache License
public void hello(String key, Handler<AsyncResult<String>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w ww. j av a 2s . c o m } JsonObject _json = new JsonObject(); _json.put("key", key); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "hello"); _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:studio.lysid.scales.query.scale.QueryScaleServiceImpl.java
License:Open Source License
@Override public void findScaleById(int id, Handler<AsyncResult<JsonObject>> handler) { logger.debug("findScaleById called with parameters: id={0}", id); db.findOne(ScaleCollection, new JsonObject().put("_id", Integer.toString(id)), new JsonObject(), res -> { if (res.succeeded() && res.result() != null) { handler.handle(Future.succeededFuture(res.result())); } else {/* w w w . j a v a 2 s .com*/ handler.handle(Future.failedFuture("Scale #" + id + " does not exist")); } }); }
From source file:vertigo.stream.SimpleReactNode.java
public SimpleReactNode<K, T> fromEventbus(K key, String fromAddress, String toAddress, SerializableFunction<LazyFutureStream<T>, LazyFutureStream<?>> builder, Handler<Future<Void>> deployed) { this.execute(key, p -> { EventBus eb = p.getVertx().eventBus(); Queue<T> inQueue = QueueFactories.<T>unboundedQueue().build(); LazyFutureStream<T> processingIn = ((SimpleReactNode<?, ?>) p).react .fromStream(inQueue.streamCompletableFutures()); LazyFutureStream<?> processingOut = builder.apply(processingIn) .peek(data -> eb.publish(toAddress, data)); processingOut.run();/*w w w . j a v a2 s. com*/ eb.<T>consumer(fromAddress).handler(msg -> { inQueue.offer(msg.body()); }); }, throwable -> { if (deployed != null) { if (throwable != null) { deployed.handle(Future.succeededFuture()); } else { deployed.handle(Future.failedFuture(throwable)); } } }); return this; }