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:net.kuujo.vertigo.instance.impl.OutputCollectorImpl.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public void handle(Message<Object> message) {
    String portName = message.headers().get("port");
    if (portName != null) {
        OutputPort port = ports.get(portName);
        if (port != null) {
            port.handle(message);/*from   w ww  .j  a  va2s  .  com*/
        }
    }
}

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

License:Apache License

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

From source file:net.kuujo.vertigo.message.impl.VertigoMessageImpl.java

License:Apache License

public VertigoMessageImpl(String id, Message<T> message) {
    this.id = id;
    this.body = message.body();
    this.headers = message.headers();
    this.message = message;
}

From source file:org.sub.bug.BugCRUDServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*  w w w.  j a 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 "saveBug": {
            service.saveBug(json.getJsonObject("bug") == null ? null
                    : new org.sub.bug.entity.Bug(json.getJsonObject("bug")), createHandler(msg));
            break;
        }
        case "retrieveBug": {
            service.retrieveBug((java.lang.String) json.getValue("bugId"), 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 "removeBug": {
            service.removeBug((java.lang.String) json.getValue("bugId"), 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:se.liquidbytes.jel.database.DatabaseConnectionVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();/*from  w  w w  . j a  va  2  s.co m*/
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }
    switch (action) {
    case "getSite": {
        service.getSite((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    case "getSites": {
        service.getSites(createHandler(msg));
        break;
    }
    case "addSite": {
        service.addSite((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "updateSite": {
        service.updateSite((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "removeSite": {
        service.removeSite((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    case "getUser": {
        service.getUser((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    case "getUserByUsername": {
        service.getUserByUsername((java.lang.String) json.getValue("username"), createHandler(msg));
        break;
    }
    case "getUsers": {
        service.getUsers(createHandler(msg));
        break;
    }
    case "addUser": {
        service.addUser((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "updateUser": {
        service.updateUser((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "removeUser": {
        service.removeUser((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

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

License:Apache License

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

    case "getConnection": {
        service.getConnection(res -> {
            if (res.failed()) {
                msg.fail(-1, res.cause().getMessage());
            } else {
                String proxyAddress = UUID.randomUUID().toString();
                ProxyHelper.registerService(DatabaseConnection.class, vertx, res.result(), proxyAddress);
                msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
            }
        });
        break;
    }
    case "start": {
        service.start();
        break;
    }
    case "stop": {
        service.stop();
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:se.liquidbytes.jel.owfs.OwfsAdapter.java

License:Apache License

/**
 * Main method for parsing the different requests that are sent to this adapter.
 *
 * @param message//from   ww  w .  j ava  2  s. c om
 */
private void handleRequest(Message message) {
    String action = message.headers().get("action");
    logger.debug("Executing action \"{}\" on Owserver with adapter id \"{}\" running at {}:{}.", action,
            this.getId(), this.host, this.port);

    try {
        switch (action) {
        case "listSupportedDevices":
            this.getSupportedDevices(message);
            break;
        case "listDevices":
            this.getAvailableDevices(message);
            break;
        case "retrieveDeviceValue":
            this.getDeviceValue(message);
            break;
        case "updateDeviceValue":
            this.setDeviceValue(message);
            break;
        default:
            logger.info("Received a request for a non-implemented action '{}'. Ignoring action.", action);
        }

        logger.debug("Done executing action \"{}\" on Owserver with adapter id \"{}\" running at {}:{}.",
                action, this.getId(), this.host, this.port);
    } catch (DeviceMissingException ex) {
        logger.info(
                "Trying to perform an action on a non existing device ({}) on Owserver with adapter id \"{}\" running at {}:{}.",
                ex.getHardwareId(), this.getId(), this.host, this.port);
        message.fail(404, ex.getMessage());
    } catch (OwServerConnectionException ex) {
        logger.error("Failed to execute action \"{}\" on Owserver with adapter id \"{}\" running at {}:{}.",
                action, this.getId(), this.host, this.port, ex);
        message.fail(500, ex.getMessage());
    }
}

From source file:servicefactories.BasicServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  www.j  av a2  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 "find": {
            service.find((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
            break;
        }
        case "hello": {
            service.hello((java.lang.String) json.getValue("key"), createHandler(msg));
            break;
        }
        case "call": {
            service.call((java.lang.String) json.getValue("key"));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}