List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:com.github.ithildir.airbot.service.MeasurementServiceVertxEBProxy.java
License:Apache License
public void getMeasurement(double latitude, double longitude, Handler<AsyncResult<Measurement>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//ww w . j a v a 2 s .c o m } JsonObject _json = new JsonObject(); _json.put("latitude", latitude); _json.put("longitude", longitude); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getMeasurement"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture( res.result().body() == null ? null : new Measurement(res.result().body()))); } }); }
From source file:com.github.ithildir.airbot.service.MeasurementServiceVertxEBProxy.java
License:Apache License
public void getName(Handler<AsyncResult<String>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w w w .j a v a 2 s.c o m } JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getName"); _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:com.github.ithildir.airbot.service.MeasurementServiceVertxEBProxy.java
License:Apache License
public void init(Handler<AsyncResult<Void>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from ww w .java2s .com } JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "init"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:com.github.ithildir.airbot.service.UserServiceVertxEBProxy.java
License:Apache License
public void getUserLocation(String userId, Handler<AsyncResult<Location>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w w w . j av a 2 s .c o m*/ } JsonObject _json = new JsonObject(); _json.put("userId", userId); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getUserLocation"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future .succeededFuture(res.result().body() == null ? null : new Location(res.result().body()))); } }); }
From source file:com.github.ithildir.airbot.service.UserServiceVertxEBProxy.java
License:Apache License
public void updateUserLocation(String userId, double latitude, double longitude, String country, Handler<AsyncResult<Void>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from www .j av a 2s . co m } JsonObject _json = new JsonObject(); _json.put("userId", userId); _json.put("latitude", latitude); _json.put("longitude", longitude); _json.put("country", country); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "updateUserLocation"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void getBlocking(String id, AsyncResultHandler<T> resultHandler) { idExist(id, r -> {/* w ww . ja va 2s.co m*/ if (r.succeeded() && r.result()) { deepFetch(id, resultHandler); } else { resultHandler.handle(Future.failedFuture(r.cause())); } }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void getAllIdsBlocking(AsyncResultHandler<List<String>> resultHandler) { redissonOther.<String, String>getMap(getStorageKey(), StringCodec.INSTANCE).keySetAsync() .addListener(future -> {//from w w w . j a v a 2 s.c o m resultHandler.handle(future.isSuccess() ? (future.get() != null ? Future.succeededFuture( ((Set<String>) future.get()).stream().collect(Collectors.toList())) : Future.failedFuture(new RepositoryException("No search result returned"))) : Future.failedFuture(new RepositoryException(future.cause()))); if (future.isSuccess()) { logger.debug("[" + getStorageKey() + "] Get ALL Keys in Unique [" + getUniqueKey("id") + "] Success."); } else { logger.debug("[" + getStorageKey() + "] Get ALL Keys in Unique [" + getUniqueKey("id") + "] Failed: ", future.cause()); } }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void getByListBlocking(List<String> ids, AsyncResultHandler<List<T>> resultHandler) { if (ids == null) { resultHandler.handle(Future.failedFuture(new IllegalArgumentException("List of ids can't be null."))); return;//from w w w.j ava2 s . c o m } else if (ids.isEmpty()) { resultHandler.handle(Future.succeededFuture(Collections.emptyList())); return; } AtomicLong c = new AtomicLong(0); ArrayList<T> l = new ArrayList<>(ids.size()); IntStream.range(0, ids.size()).forEach(i -> l.add(null)); ids.stream().forEach(e -> { getBlocking(e, r -> { l.set(ids.indexOf(e), r.result()); if (c.incrementAndGet() == ids.size()) { resultHandler.handle(Future.succeededFuture( l.stream().filter(s -> s != null).collect(Collectors.toCollection(ArrayList::new)))); } }); }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void searchIndexByPositionBlocking(String fieldName, String indexName, Integer start, Integer stop, AsyncResultHandler<List<String>> resultHandler) { redissonOther.getScoredSortedSet(getScoredSortedIndexKey(fieldName, indexName), StringCodec.INSTANCE) .valueRangeAsync(start, stop).addListener(future -> { Collection<String> res = (Collection<String>) future.get(); try { ArrayList<String> ids = res.stream().map(r -> lookupIdFromIndex(r, fieldName, indexName)) .collect(Collectors.toCollection(ArrayList::new)); resultHandler// w w w . j a v a 2 s.c o m .handle(future.isSuccess() ? (future.get() != null ? Future.succeededFuture(ids) : Future.failedFuture( new RepositoryException("No search result returned"))) : Future.failedFuture(new RepositoryException(future.cause()))); if (future.isSuccess()) { logger.debug("[" + getStorageKey() + "] Search Index By Position Success. Records: " + ((Collection<String>) future.get()).size()); } else { logger.debug("[" + getStorageKey() + "] Search Index By Position Failure.", future.cause()); } } catch (RuntimeException e) { resultHandler.handle(Future.failedFuture(e.getCause())); logger.debug("[" + getStorageKey() + "] Search Index By Position Failure.", e); } }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void searchIndexByScoreBlocking(String fieldName, String indexName, Double min, Double max, Integer offset, Integer limit, AsyncResultHandler<List<String>> resultHandler) { redissonOther/*w w w . j a va 2s. c o m*/ .<String>getScoredSortedSet(getScoredSortedIndexKey(fieldName, indexName), StringCodec.INSTANCE) .valueRangeAsync(min, true, max, true, offset, limit).addListener(future -> { Collection<String> res = (Collection<String>) future.get(); try { ArrayList<String> ids = res.stream().map(r -> lookupIdFromIndex(r, fieldName, indexName)) .collect(Collectors.toCollection(ArrayList::new)); resultHandler .handle(future.isSuccess() ? (future.get() != null || ids == null ? Future.succeededFuture(ids) : Future.failedFuture( new RepositoryException("No search result returned"))) : Future.failedFuture(new RepositoryException(future.cause()))); if (future.isSuccess()) { logger.debug("[" + getStorageKey() + "] Search Index By Score Success. Records: " + ((Collection<String>) future.get()).size()); } else { logger.debug("[" + getStorageKey() + "] Search Index By Score Failure.", future.cause()); } } catch (RuntimeException e) { resultHandler.handle(Future.failedFuture(e.getCause())); logger.debug("[" + getStorageKey() + "] Search Index By Score Failure.", e); } }); }