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:cm.study.vertx.database.WikiDatabaseServiceVertxEBProxy.java

License:Apache License

public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//from  w ww .j a  v a2s  . c o m
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "fetchAllPages");
    _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:com.appdocker.iop.InternetOfPeopleServiceVertxEBProxy.java

License:Apache License

public void hello(String message, Handler<AsyncResult<String>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*from  w w  w.j  a  va  2 s .com*/
    }
    JsonObject _json = new JsonObject();
    _json.put("message", message);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "hello");
    _vertx.eventBus().<String>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.baldmountain.depot.DepotHandlebarsTemplateEngine.java

License:Open Source License

@Override
public void render(RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
    try {/*from   w  ww  .  j  av a2 s. c o m*/
        Template template = cache.get(templateFileName);
        if (template == null) {
            synchronized (this) {
                loader.setVertx(context.vertx());
                template = handlebars.compile(templateFileName);
                cache.put(templateFileName, template);
            }
        }
        handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(context.data()))));
    } catch (Exception ex) {
        handler.handle(Future.failedFuture(ex));
    }
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceFactoryVertxEBProxy.java

License:Apache License

public KnowledgeServiceFactory getKnowledgeService(Handler<AsyncResult<KnowledgeService>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from ww  w.ja v  a 2  s .  c o m*/
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getKnowledgeService");
    _vertx.eventBus().<KnowledgeService>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(KnowledgeService.class, _vertx, addr)));
        }
    });
    return this;
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxEBProxy.java

License:Apache License

public KnowledgeService addClassPathResource(String resourceName, Handler<AsyncResult<Void>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*  w w w  . j  ava2 s .co  m*/
    JsonObject _json = new JsonObject();
    _json.put("resourceName", resourceName);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "addClassPathResource");
    _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()));
        }
    });
    return this;
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxEBProxy.java

License:Apache License

public KnowledgeService addFileResource(String fileName, Handler<AsyncResult<Void>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from w w  w . j  a  v  a  2 s  .c  o  m*/
    JsonObject _json = new JsonObject();
    _json.put("fileName", fileName);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "addFileResource");
    _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()));
        }
    });
    return this;
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxEBProxy.java

License:Apache License

public KnowledgeService processDefinitions(Handler<AsyncResult<JsonArray>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//  w  w  w . j a va 2s. c  o m
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "processDefinitions");
    _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future.succeededFuture(res.result().body()));
        }
    });
    return this;
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxEBProxy.java

License:Apache License

public KnowledgeService getProcessService(Handler<AsyncResult<ProcessService>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from w  w w.j a va2  s  .  c o m*/
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getProcessService");
    _vertx.eventBus().<ProcessService>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(ProcessService.class, _vertx, addr)));
        }
    });
    return this;
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxEBProxy.java

License:Apache License

public KnowledgeService getRuleService(Handler<AsyncResult<RuleService>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }// ww w .  ja  v a 2  s . c  om
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getRuleService");
    _vertx.eventBus().<RuleService>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(RuleService.class, _vertx, addr)));
        }
    });
    return this;
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxEBProxy.java

License:Apache License

public KnowledgeService getTaskService(Handler<AsyncResult<TaskService>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from   w  w  w . ja va2 s.c  o  m*/
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getTaskService");
    _vertx.eventBus().<TaskService>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(TaskService.class, _vertx, addr)));
        }
    });
    return this;
}