Example usage for io.vertx.core Future failedFuture

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

Introduction

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

Prototype

static <T> Future<T> failedFuture(String failureMessage) 

Source Link

Document

Create a failed future with the specified failure message.

Usage

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection updateSite(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//from www .j  ava 2s. com
    JsonObject _json = new JsonObject();
    _json.put("document", document);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "updateSite");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection removeSite(String id, Handler<AsyncResult<Void>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from w ww. j  a v a 2s  . c  o m*/
    JsonObject _json = new JsonObject();
    _json.put("id", id);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "removeSite");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection getUser(String id, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//from   www . ja  v  a 2  s. c  o  m
    JsonObject _json = new JsonObject();
    _json.put("id", id);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getUser");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection getUserByUsername(String username, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//from w w w.  j av a 2  s  . c o m
    JsonObject _json = new JsonObject();
    _json.put("username", username);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getUserByUsername");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection getUsers(Handler<AsyncResult<JsonArray>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/* w  w  w . j  a va2 s .  c  om*/
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getUsers");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection addUser(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*  w w w  .  j  a v a 2 s.  co m*/
    JsonObject _json = new JsonObject();
    _json.put("document", document);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "addUser");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection updateUser(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//  w  w w .  j  a v  a 2s . c o m
    JsonObject _json = new JsonObject();
    _json.put("document", document);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "updateUser");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

License:Apache License

public DatabaseConnection removeUser(String id, Handler<AsyncResult<Void>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//w w  w .  j  a  v  a2s  .  c om
    JsonObject _json = new JsonObject();
    _json.put("id", id);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "removeUser");
    _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()));
        }
    });
    return this;
}

From source file:se.liquidbytes.jel.database.DatabaseServiceVertxEBProxy.java

License:Apache License

public void getConnection(Handler<AsyncResult<DatabaseConnection>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from   w ww.j  ava  2s  .c  o m
    }
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getConnection");
    _vertx.eventBus().<DatabaseConnection>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            String addr = res.result().headers().get("proxyaddr");
            handler.handle(
                    Future.succeededFuture(ProxyHelper.createProxy(DatabaseConnection.class, _vertx, addr)));
        }
    });
}

From source file:se.liquidbytes.jel.system.device.DeviceManager.java

License:Apache License

public void listAdapterDevices(String adapterId, Handler<AsyncResult<JsonArray>> resultHandler) {
    DeliveryOptions options = new DeliveryOptions();
    options.addHeader("action", "listDevices");
    DeployedAdapter adapter = JelService.adapterManager().getAdapter(adapterId);

    if (adapter == null) {
        resultHandler/*from   w  ww.  ja  v a 2 s  .  c om*/
                .handle(Future.failedFuture(String.format("Adapter with id %s does not exist.", adapterId)));
    } else {
        // Send message to adapter to report back its devices.
        JelService.vertx().eventBus().send(String.format("%s.%s@%s:%d", AdapterEvents.EVENTBUS_ADAPTERS,
                adapter.config().getType(), adapter.config().getAddress(), adapter.config().getPort()), null,
                options, res -> {
                    if (res.succeeded()) {
                        JsonArray devices = new JsonArray();

                        JsonObject result = (JsonObject) res.result().body();
                        result.getJsonArray("result").forEach((d) -> {
                            JsonObject tmpDevice = (JsonObject) d;

                            // Sync found devices with allDevices-collection in case we are out of sync and have missed an event!
                            addToDeviceCollections(new JsonObject().put("adapterId", adapterId)
                                    .put("name", tmpDevice.getString("name"))
                                    .put("type", tmpDevice.getString("type"))
                                    .put("hwId", tmpDevice.getString("hwId")));

                            devices.add(new JsonObject()
                                    .put("deviceId", generateDeviceId(adapterId, tmpDevice.getString("hwId")))
                                    .put("type", tmpDevice.getString("type"))
                                    .put("name", tmpDevice.getString("name")));
                        });

                        resultHandler.handle(Future.succeededFuture(devices));
                    } else {
                        resultHandler.handle(Future.failedFuture(res.cause()));
                    }
                });
    }
}