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.system.impl.JelServiceImpl.java

License:Apache License

@Override
public void listAvailableAdapterTypes(Handler<AsyncResult<JsonArray>> resultHandler) {
    try {/*from   w  ww .j  a va  2 s.c o m*/
        List<PluginDesc> adapterTypes = JelService.adapterManager().getAvailableAdapterTypes();

        JsonArray list = new JsonArray();
        adapterTypes.stream().forEach((adapterType) -> {
            list.add(adapterType.toApi());
        });

        resultHandler.handle(Future.succeededFuture(list));
    } 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 listAdapters(Handler<AsyncResult<JsonArray>> resultHandler) {
    try {//from   w  ww. j  a v a  2  s  .co  m
        List<DeployedAdapter> adapters = JelService.adapterManager().getAdapters();

        JsonArray list = new JsonArray();
        adapters.stream().forEach((adapter) -> {
            list.add(adapter.toApi());
        });

        resultHandler.handle(Future.succeededFuture(list));
    } 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 retrieveAdapter(String id, Handler<AsyncResult<JsonObject>> resultHandler) {
    try {//from   ww  w. j ava  2s .co  m
        DeployedAdapter adapter = JelService.adapterManager().getAdapter(id);
        if (adapter != null) {
            resultHandler.handle(Future.succeededFuture(adapter.toApi()));
        } else {
            resultHandler.handle(Future.succeededFuture(null));
        }
    } 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 addAdapter(JsonObject adapter, Handler<AsyncResult<Void>> resultHandler) {
    try {//from  w  w w  .j  a  v  a 2 s  .c o  m
        AdapterConfiguration config = new AdapterConfiguration();
        config.setType(adapter.getString("type"));
        config.setAddress(adapter.getString("address"));
        config.setPort(adapter.getInteger("port"));

        JelService.adapterManager().addAdapter(config);
        resultHandler.handle(Future.succeededFuture());
    } catch (IllegalArgumentException | JelException ex) {
        resultHandler.handle(Future.failedFuture(ex.getMessage()));
    }
}

From source file:se.liquidbytes.jel.system.impl.JelServiceImpl.java

License:Apache License

@Override
public void removeAdapter(String id, Handler<AsyncResult<Void>> resultHandler) {
    try {//ww  w .jav  a  2s  . co m
        JelService.adapterManager().removeAdapter(id);
        resultHandler.handle(Future.succeededFuture());
    } catch (IllegalArgumentException | JelException ex) {
        resultHandler.handle(Future.failedFuture(ex.getMessage()));
    }
}

From source file:se.liquidbytes.jel.system.impl.JelServiceImpl.java

License:Apache License

@Override
public void createAdapterDevice(String adapterId, JsonObject device,
        Handler<AsyncResult<JsonObject>> resultHandler) {
    try {//from   ww  w  . j  ava  2  s .  c  om
        JelService.deviceManager().createAdapterDevice(adapterId, device, (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 listAdapterDevices(String adapterId, Handler<AsyncResult<JsonArray>> resultHandler) {
    try {/*from   www  . ja v  a2s  .com*/
        JelService.deviceManager().listAdapterDevices(adapterId, (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 retrieveAdapterDevice(String id, Handler<AsyncResult<JsonObject>> resultHandler) {
    try {//from w w  w . j  av  a2s  . c o m
        JelService.deviceManager().retrieveAdapterDevice(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 updateAdapterDevice(String id, JsonObject device, Handler<AsyncResult<JsonObject>> resultHandler) {
    try {/*from   ww w  . j av a  2 s .  c om*/
        JelService.deviceManager().updateAdapterDevice(id, device, (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 deleteAdapterDevice(String id, Handler<AsyncResult<Void>> resultHandler) {
    try {/*from   w w w  . j  a  v a  2 s  .c  o m*/
        JelService.deviceManager().deleteAdapterDevice(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()));
    }
}