Example usage for io.vertx.core.eventbus Message body

List of usage examples for io.vertx.core.eventbus Message body

Introduction

In this page you can find the example usage for io.vertx.core.eventbus Message body.

Prototype

@CacheReturn
T body();

Source Link

Document

The body of the message.

Usage

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {// w  w w . j a  va2s  .com
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "abort": {
            service.abort(createHandler(msg));
            break;
        }
        case "start": {
            service.start(createHandler(msg));
            break;
        }
        case "getInstanceId": {
            service.getInstanceId(createHandler(msg));
            break;
        }
        case "getName": {
            service.getName(createHandler(msg));
            break;
        }
        case "getParentInstanceId": {
            service.getParentInstanceId(createHandler(msg));
            break;
        }
        case "getState": {
            service.getState(createHandler(msg));
            break;
        }
        case "signalEvent": {
            service.signalEvent((java.lang.String) json.getValue("eventName"),
                    (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg));
            break;
        }
        case "close": {
            service.close();
            close();
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  w w w  . j  av  a 2 s .  co m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "abort": {
            service.abort(json.getValue("processInstanceId") == null ? null
                    : (json.getLong("processInstanceId").longValue()), createHandler(msg));
            break;
        }
        case "create": {
            service.create((java.lang.String) json.getValue("processId"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    String proxyAddress = UUID.randomUUID().toString();
                    ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(), proxyAddress,
                            false, timeoutSeconds);
                    msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                }
            });
            break;
        }
        case "createWithVariables": {
            service.createWithVariables((java.lang.String) json.getValue("processId"),
                    (io.vertx.core.json.JsonObject) json.getValue("variables"), res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            String proxyAddress = UUID.randomUUID().toString();
                            ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(),
                                    proxyAddress, false, timeoutSeconds);
                            msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                        }
                    });
            break;
        }
        case "signalEvent": {
            service.signalEvent((java.lang.String) json.getValue("eventName"),
                    (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg));
            break;
        }
        case "signalEventForProcess": {
            service.signalEventForProcess((java.lang.String) json.getValue("eventName"),
                    json.getValue("processInstanceId") == null ? null
                            : (json.getLong("processInstanceId").longValue()),
                    (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg));
            break;
        }
        case "startProcess": {
            service.startProcess((java.lang.String) json.getValue("processId"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    String proxyAddress = UUID.randomUUID().toString();
                    ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(), proxyAddress,
                            false, timeoutSeconds);
                    msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                }
            });
            break;
        }
        case "startProcessWithVariables": {
            service.startProcessWithVariables((java.lang.String) json.getValue("processId"),
                    (io.vertx.core.json.JsonObject) json.getValue("jsonObject"), res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            String proxyAddress = UUID.randomUUID().toString();
                            ProxyHelper.registerService(ProcessInstanceService.class, vertx, res.result(),
                                    proxyAddress, false, timeoutSeconds);
                            msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                        }
                    });
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  w ww  . j  ava  2 s. c  o  m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "delete": {
            service.delete((java.lang.String) json.getValue("factHandle"), createHandler(msg));
            break;
        }
        case "fireAllRules": {
            service.fireAllRules(createHandler(msg));
            break;
        }
        case "getQueryResults": {
            service.getQueryResults((java.lang.String) json.getValue("queryName"),
                    (java.lang.String) json.getValue("resultName"), createHandler(msg));
            break;
        }
        case "insert": {
            service.insert((java.lang.String) json.getValue("packageName"),
                    (java.lang.String) json.getValue("typeName"),
                    (io.vertx.core.json.JsonObject) json.getValue("attributes"), createHandler(msg));
            break;
        }
        case "update": {
            service.update((java.lang.String) json.getValue("factHandle"),
                    (java.lang.String) json.getValue("factType"),
                    (io.vertx.core.json.JsonObject) json.getValue("attributes"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/* w w w.  j av a  2s. co m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "addComment": {
            service.addComment(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), (java.lang.String) json.getValue("comment"),
                    createHandler(msg));
            break;
        }
        case "claim": {
            service.claim(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "complete": {
            service.complete(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"),
                    (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg));
            break;
        }
        case "delegate": {
            service.delegate(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), (java.lang.String) json.getValue("newUserId"),
                    createHandler(msg));
            break;
        }
        case "exit": {
            service.exit(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "fail": {
            service.fail(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"),
                    (io.vertx.core.json.JsonObject) json.getValue("data"), createHandler(msg));
            break;
        }
        case "forward": {
            service.forward(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), (java.lang.String) json.getValue("newUserId"),
                    createHandler(msg));
            break;
        }
        case "getContent": {
            service.getContent(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    createHandler(msg));
            break;
        }
        case "release": {
            service.release(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "resume": {
            service.resume(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "skip": {
            service.skip(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "start": {
            service.start(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "stop": {
            service.stop(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        case "suspend": {
            service.suspend(json.getValue("taskId") == null ? null : (json.getLong("taskId").longValue()),
                    (java.lang.String) json.getValue("userId"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:com.edgar.vertx.service.discovery.eventbus.MyServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from   ww w  . j  ava  2s  .c o  m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {
        case "say": {
            service.say();
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:com.edgar.vertx.serviceproxy.provider.ProcessorServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//from w  ww  .ja  v  a  2 s .  c  o m
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "process": {
            service.process((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:com.emikra.vertx.oak.OakServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }//from ww  w .ja v a  2  s  . com
    accessed();
    switch (action) {

    case "createNode": {
        service.createNode(
                json.getJsonObject("options") == null ? null
                        : new com.emikra.vertx.oak.CreateNodeOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:com.emikra.vertx.orientdb.OrientDBServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }//from w ww.  j  a va 2  s .  com
    accessed();
    switch (action) {

    case "createDatabase": {
        service.createDatabase(json.getJsonObject("options") == null ? null
                : new com.emikra.vertx.orientdb.database.data.CreateDatabaseParams(
                        json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "createDocument": {
        service.createDocument((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "createVertex": {
        service.createVertex((io.vertx.core.json.JsonObject) json.getValue("vertexDoc"), createHandler(msg));
        break;
    }
    case "createEdge": {
        service.createEdge((io.vertx.core.json.JsonObject) json.getValue("edgeDoc"), createHandler(msg));
        break;
    }
    case "createClass": {
        service.createClass(
                json.getJsonObject("params") == null ? null
                        : new com.emikra.vertx.orientdb.CreateClassParams(json.getJsonObject("params")),
                createHandler(msg));
        break;
    }
    case "getDocument": {
        service.getDocument((io.vertx.core.json.JsonObject) json.getValue("docQuery"), createHandler(msg));
        break;
    }
    case "getVertex": {
        service.getVertex((io.vertx.core.json.JsonObject) json.getValue("vertexQuery"), createHandler(msg));
        break;
    }
    case "getEdge": {
        service.getEdge((io.vertx.core.json.JsonObject) json.getValue("edgeQuery"), createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*ww w . j a  va2 s.co  m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "putMapping": {
            service.putMapping(convertList(json.getJsonArray("indices").getList()),
                    (java.lang.String) json.getValue("type"),
                    (io.vertx.core.json.JsonObject) json.getValue("source"),
                    json.getJsonObject("options") == null ? null
                            : new com.englishtown.vertx.elasticsearch.MappingOptions(
                                    json.getJsonObject("options")),
                    createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }// w ww.  ja v  a 2s  .c om
    accessed();
    switch (action) {

    case "start": {
        service.start();
        break;
    }
    case "stop": {
        service.stop();
        break;
    }
    case "index": {
        service.index((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (io.vertx.core.json.JsonObject) json.getValue("source"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.IndexOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "update": {
        service.update((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (java.lang.String) json.getValue("id"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.UpdateOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "get": {
        service.get((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (java.lang.String) json.getValue("id"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.GetOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "search": {
        service.search(convertList(json.getJsonArray("indices").getList()),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.SearchOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "searchScroll": {
        service.searchScroll((java.lang.String) json.getValue("scrollId"), json.getJsonObject("options") == null
                ? null
                : new com.englishtown.vertx.elasticsearch.SearchScrollOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "delete": {
        service.delete((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (java.lang.String) json.getValue("id"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.DeleteOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}