List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:com.github.ithildir.airbot.service.GeoServiceVertxEBProxy.java
License:Apache License
public void getLocationByQuery(String query, Handler<AsyncResult<Location>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w w w .ja va 2s . c om } JsonObject _json = new JsonObject(); _json.put("query", query); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getLocationByQuery"); _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.impl.AirNowMeasurementServiceImpl.java
License:Open Source License
@Override public void getMeasurement(double latitude, double longitude, Handler<AsyncResult<Measurement>> handler) { Measurement measurement = null;//from ww w .jav a 2 s . co m String reportingArea = _getReportingArea(latitude, longitude); if (reportingArea != null) { measurement = _reportingAreaMeasurements.get(reportingArea); } handler.handle(Future.succeededFuture(measurement)); }
From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java
License:Open Source License
@Override public void getName(Handler<AsyncResult<String>> handler) { handler.handle(Future.succeededFuture("airnow")); }
From source file:com.github.ithildir.airbot.service.impl.DummyUserServiceImpl.java
License:Open Source License
@Override public void getUserLocation(String userId, Handler<AsyncResult<Location>> handler) { Location location = _userLocationsMap.get(userId); handler.handle(Future.succeededFuture(location)); }
From source file:com.github.ithildir.airbot.service.impl.MapQuestGeoServiceImpl.java
License:Open Source License
private void _getLocation(HttpRequest<Buffer> httpRequest, Handler<AsyncResult<Location>> handler) { httpRequest.setQueryParam("key", _key); httpRequest.send(asyncResult -> { HttpResponse<Buffer> httpResponse = _handleHttpResponse(asyncResult, handler); if (httpResponse == null) { return; }//from w w w . j a v a 2s . co m Location location = _getLocation(httpResponse.bodyAsJsonObject()); handler.handle(Future.succeededFuture(location)); }); }
From source file:com.github.ithildir.airbot.service.impl.WaqiMeasurementServiceImpl.java
License:Open Source License
@Override public void getMeasurement(double latitude, double longitude, Handler<AsyncResult<Measurement>> handler) { HttpRequest<Buffer> httpRequest = _webClient.get("/feed/geo:" + latitude + ";" + longitude + "/"); httpRequest.setQueryParam("token", _key); httpRequest.send(asyncResult -> { HttpResponse<Buffer> httpResponse = _handleHttpResponse(asyncResult, handler); if (httpResponse == null) { return; }// w w w . j a v a2s.co m Measurement measurement = _getMeasurement(httpResponse.bodyAsJsonObject()); handler.handle(Future.succeededFuture(measurement)); }); }
From source file:com.github.ithildir.airbot.service.impl.WaqiMeasurementServiceImpl.java
License:Open Source License
@Override public void getName(Handler<AsyncResult<String>> handler) { handler.handle(Future.succeededFuture("aqicn")); }
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;/*w w w . ja 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 ww w. ja va 2 s . c om } 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 w w w . java 2 s . c om } 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())); } }); }