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

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

Introduction

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

Prototype

MultiMap headers();

Source Link

Document

Multi-map of message headers.

Usage

From source file:io.hijynx.ensemble.identity.UserServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//  w w  w  .  j a  va 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 "addUser": {
            service.addUser(
                    json.getJsonObject("user") == null ? null
                            : new io.hijynx.ensemble.identity.User(json.getJsonObject("user")),
                    createHandler(msg));
            break;
        }
        case "retrieveUser": {
            service.retrieveUser((java.lang.String) json.getValue("id"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "retrieveByUsername": {
            service.retrieveByUsername((java.lang.String) json.getValue("username"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "retrieveAllUsers": {
            service.retrieveAllUsers(res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(new JsonArray(
                            res.result().stream().map(User::toJson).collect(Collectors.toList())));
                }
            });
            break;
        }
        case "updateUser": {
            service.updateUser(json.getJsonObject("user") == null ? null
                    : new io.hijynx.ensemble.identity.User(json.getJsonObject("user")), res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "deleteUser": {
            service.deleteUser((java.lang.String) json.getValue("id"), createHandler(msg));
            break;
        }
        case "updatePassword": {
            service.updatePassword((java.lang.String) json.getValue("userId"),
                    (java.lang.String) json.getValue("password"), 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:io.rebind.vertx.orientdb.OrientDBServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//from  www. j a  v 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 "addVertex": {
            service.addVertex((java.lang.String) json.getValue("iClassName"),
                    (java.lang.String) json.getValue("iClusterName"),
                    (io.vertx.core.json.JsonObject) json.getValue("properties"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "updateVertex": {
            service.updateVertex((java.lang.String) json.getValue("id"),
                    (io.vertx.core.json.JsonObject) json.getValue("properties"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "removeVertex": {
            service.removeVertex((java.lang.String) json.getValue("id"), res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "getVertex": {
            service.getVertex((java.lang.String) json.getValue("id"), res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "getVerticesOfClass": {
            service.getVerticesOfClass((java.lang.String) json.getValue("iClassName"), res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(new JsonArray(
                            res.result().stream().map(Record::toJson).collect(Collectors.toList())));
                }
            });
            break;
        }
        case "getVertices": {
            service.getVertices((java.lang.String) json.getValue("iClassName"),
                    (io.vertx.core.json.JsonObject) json.getValue("vertexQuery"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(new JsonArray(
                                    res.result().stream().map(Record::toJson).collect(Collectors.toList())));
                        }
                    });
            break;
        }
        case "getRelatedVertices": {
            service.getRelatedVertices((java.lang.String) json.getValue("sourceId"),
                    (java.lang.String) json.getValue("label"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(new JsonArray(
                                    res.result().stream().map(Record::toJson).collect(Collectors.toList())));
                        }
                    });
            break;
        }
        case "addEdge": {
            service.addEdge((java.lang.String) json.getValue("sourceId"),
                    (java.lang.String) json.getValue("destinationId"),
                    (java.lang.String) json.getValue("label"),
                    (io.vertx.core.json.JsonObject) json.getValue("properties"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "removeEdge": {
            service.removeEdge((java.lang.String) json.getValue("id"), res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "removeEdges": {
            service.removeEdges((java.lang.String) json.getValue("sourceId"),
                    (java.lang.String) json.getValue("destinationId"),
                    (java.lang.String) json.getValue("label"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(new JsonArray(
                                    res.result().stream().map(Record::toJson).collect(Collectors.toList())));
                        }
                    });
            break;
        }
        case "getEdges": {
            service.getEdges((java.lang.String) json.getValue("sourceId"),
                    (java.lang.String) json.getValue("destinationId"),
                    (java.lang.String) json.getValue("label"), res -> {
                        if (res.failed()) {
                            msg.fail(-1, res.cause().getMessage());
                        } else {
                            msg.reply(new JsonArray(
                                    res.result().stream().map(Record::toJson).collect(Collectors.toList())));
                        }
                    });
            break;
        }
        case "getEdge": {
            service.getEdge((io.vertx.core.json.JsonObject) json.getValue("edgeQuery"), res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(new JsonArray(
                            res.result().stream().map(Record::toJson).collect(Collectors.toList())));
                }
            });
            break;
        }
        case "close": {
            service.close();
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.fail(-1, t.getMessage());
        throw t;
    }
}

From source file:name.bpdp.vertx.blazegraph.BlazegraphServiceVertxProxyHandler.java

License:Apache License

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

    case "save": {
        service.save((java.lang.String) json.getValue("collection"));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:name.bpdp.vertx.changeme.ChangemeServiceVertxProxyHandler.java

License:Apache License

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

    case "method1": {
        service.method1((java.lang.String) json.getValue("method1Arg"), createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:net.kuujo.vertigo.instance.impl.ComponentInstanceImpl.java

License:Apache License

@Override
public void handle(Message<Object> message) {
    String action = message.headers().get(ACTION_HEADER);
    if (action == null) {
        input.handle(message);/* w  w  w.j a  v a2 s  . com*/
    } else {
        switch (action) {
        case MESSAGE_ACTION:
            input.handle(message);
            break;
        case ACK_ACTION:
        case FAIL_ACTION:
        case PAUSE_ACTION:
        case RESUME_ACTION:
            output.handle(message);
            break;
        default:
            message.fail(ReplyFailure.RECIPIENT_FAILURE.toInt(), String.format("Invalid action %s", action));
        }
    }
}

From source file:net.kuujo.vertigo.instance.impl.ControlledInputConnection.java

License:Apache License

@Override
public void handle(Message<T> message) {
    Long index = Long.valueOf(message.headers().get("index"));
    if (index != null && checkIndex(index)) {
        doMessage(message);/*from w w w  .  ja va  2s.  com*/
    }
}

From source file:net.kuujo.vertigo.instance.impl.ControlledInputConnection.java

License:Apache License

/**
 * Handles receiving a message.//from   www .  j av  a 2  s  .c o  m
 */
@SuppressWarnings("unchecked")
protected void doMessage(final Message<T> message) {
    if (messageHandler != null) {
        String id = message.headers().get(ID_HEADER);
        VertigoMessage<T> vertigoMessage = messageFactory.<T>createVertigoMessage(id, message);

        if (log.isDebugEnabled()) {
            log.debug("{} - Received: Message[name={}, value={}]", this, id, message);
        }
        messageHandler.handle(vertigoMessage);
    }
}

From source file:net.kuujo.vertigo.instance.impl.ControlledOutputConnection.java

License:Apache License

@Override
public void handle(Message<T> message) {
    String action = message.headers().get(ACTION_HEADER);
    Long id = Long.valueOf(message.headers().get(INDEX_HEADER));
    switch (action) {
    case ACK_ACTION:
        doAck(id);//w w  w.j a  va 2s.c  o  m
        break;
    case FAIL_ACTION:
        doFail(id);
        break;
    case PAUSE_ACTION:
        doPause(id);
        break;
    case RESUME_ACTION:
        doResume(id);
        break;
    }
}

From source file:net.kuujo.vertigo.instance.impl.InputCollectorImpl.java

License:Apache License

/**
 * Handles an input message./*from  w ww  .  j a  v a  2 s.  co m*/
 *
 * @param message The message to handle.
 */
@Override
@SuppressWarnings("unchecked")
public void handle(Message<Object> message) {
    String portName = message.headers().get("port");
    if (portName != null) {
        InputPort port = ports.get(portName);
        if (port != null) {
            port.handle(message);
        }
    }
}

From source file:net.kuujo.vertigo.instance.impl.InputPortImpl.java

License:Apache License

@Override
public void handle(Message<T> message) {
    String source = message.headers().get("source");
    if (source != null) {
        InputConnection<T> connection = connections.get(source);
        if (connection != null) {
            connection.handle(message);/*from www .  jav  a  2  s .c o  m*/
        }
    } else {
        if (stubConnection != null) {
            stubConnection.handle(message);
        }
    }
}