Example usage for io.vertx.core Future succeededFuture

List of usage examples for io.vertx.core Future succeededFuture

Introduction

In this page you can find the example usage for io.vertx.core Future succeededFuture.

Prototype

static <T> Future<T> succeededFuture(T result) 

Source Link

Document

Created a succeeded future with the specified result.

Usage

From source file:com.englishtown.vertx.elasticsearch.ElasticSearchServiceVertxEBProxy.java

License:Apache License

public void delete(String index, String type, String id, DeleteOptions options,
        Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//w w  w . j  a v  a 2s.  co m
    }
    JsonObject _json = new JsonObject();
    _json.put("index", index);
    _json.put("type", type);
    _json.put("id", id);
    _json.put("options", options == null ? null : options.toJson());
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "delete");
    _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:com.englishtown.vertx.mail.MailServiceVertxEBProxy.java

License:Apache License

public void send(SendOptions options, Handler<AsyncResult<Void>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from   w w  w .  j  a v a  2 s.  c  om
    }
    JsonObject _json = new JsonObject();
    _json.put("options", options == null ? null : options.toJson());
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "send");
    _vertx.eventBus().<Void>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:com.englishtown.vertx.solr.SolrServiceVertxEBProxy.java

License:Apache License

public void query(JsonObject query, QueryOptions options, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;// w w w.  j a  v  a2  s.c  o  m
    }
    JsonObject _json = new JsonObject();
    _json.put("query", query);
    _json.put("options", options == null ? null : options.toJson());
    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()));
        }
    });
}

From source file:com.example.myservice.services.ProductServiceVertxEBProxy.java

License:Apache License

public void list(Handler<AsyncResult<JsonArray>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//  ww w.j av  a 2 s .c o  m
    }
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "list");
    _vertx.eventBus().<JsonArray>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:com.github.ithildir.airbot.server.api.ai.AirQualityApiAiFulfillmentBuilder.java

License:Open Source License

private Future<Fulfillment> _buildFulfillment(Location location, String locationString, Locale locale) {

    Future<String> messageFuture = _airQualityMessageBuilder.getMessage(location, locationString, locale);

    return messageFuture.compose(message -> {
        Fulfillment fulfillment = new Fulfillment();

        fulfillment.setSpeech(message);/*from  w w w  .ja v a2  s .  c om*/

        return Future.succeededFuture(fulfillment);
    });
}

From source file:com.github.ithildir.airbot.server.api.ai.AirQualityApiAiFulfillmentBuilder.java

License:Open Source License

private Future<Fulfillment> _buildUserFulfillment(Locale locale, AIResponse aiResponse,
        JsonObject responseJsonObject) {

    String userId = aiResponse.getSessionId();

    Future<Location> locationFuture = _getReponseLocation(responseJsonObject);

    locationFuture = locationFuture.compose(location -> {
        if (location != null) {
            return Future.succeededFuture(location);
        }//from  w  ww.j a  v a 2s .c om

        Future<Location> future = Future.future();

        _userService.getUserLocation(userId, future);

        return future;
    });

    return locationFuture.compose(location -> {
        if (location == null) {
            Fulfillment fulfillment = ApiAiUtil.buildGooglePermissionFulfillment(
                    "in-order-to-get-information-about-the-air-" + "quality-around-you",
                    "DEVICE_PRECISE_LOCATION", locale);

            return Future.succeededFuture(fulfillment);
        }

        _updateUserLocation(userId, location);

        return _buildFulfillment(location, null, locale);
    });
}

From source file:com.github.ithildir.airbot.server.api.ai.AirQualityApiAiFulfillmentBuilder.java

License:Open Source License

private Future<Location> _getReponseLocation(JsonObject responseJsonObject) {

    double[] coordinates = ApiAiUtil.getResponseCoordinates(responseJsonObject);

    if (coordinates == null) {
        return Future.succeededFuture(null);
    }//from   ww  w .j  ava 2 s . c o  m

    Future<Location> future = Future.future();

    _geoService.getLocationByCoordinates(coordinates[0], coordinates[1], future);

    return future;
}

From source file:com.github.ithildir.airbot.server.SingleUserAuthProvider.java

License:Open Source License

public SingleUserAuthProvider(String username, String password) {
    _username = Objects.requireNonNull(username);
    _password = Objects.requireNonNull(password);

    _user = new AbstractUser() {

        @Override/*from w w w . ja  v  a 2 s  .  c  o  m*/
        public JsonObject principal() {
            JsonObject jsonObject = new JsonObject();

            jsonObject.put("username", _username);

            return jsonObject;
        }

        @Override
        public void setAuthProvider(AuthProvider authProvider) {

            // Nothing to do

        }

        @Override
        protected void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> handler) {

            handler.handle(Future.succeededFuture(Boolean.TRUE));
        }

    };
}

From source file:com.github.ithildir.airbot.server.SingleUserAuthProvider.java

License:Open Source License

@Override
public void authenticate(JsonObject authInfoJsonObject, Handler<AsyncResult<User>> handler) {

    String username = authInfoJsonObject.getString("username");

    if (username == null) {
        handler.handle(Future.failedFuture("Unable to get username in authentication info"));

        return;//  w  w w  . j  a  va  2s  .  com
    }

    String password = authInfoJsonObject.getString("password");

    if (password == null) {
        handler.handle(Future.failedFuture("Unable to get password in authentication info"));

        return;
    }

    if (!_username.equals(username) || !_password.equals(password)) {
        handler.handle(Future.failedFuture("Invalid username/password"));

        return;
    }

    handler.handle(Future.succeededFuture(_user));
}

From source file:com.github.ithildir.airbot.service.GeoServiceVertxEBProxy.java

License:Apache License

public void getLocationByCoordinates(double latitude, double longitude,
        Handler<AsyncResult<Location>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from w ww  .j ava 2  s  . com
    }
    JsonObject _json = new JsonObject();
    _json.put("latitude", latitude);
    _json.put("longitude", longitude);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getLocationByCoordinates");
    _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())));
        }
    });
}