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

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

Introduction

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

Prototype

default void reply(@Nullable Object message) 

Source Link

Document

Reply to this message.

Usage

From source file:org.entcore.workspace.service.WorkspaceService.java

License:Open Source License

public void copyDocument(final Message<JsonObject> message) {
    emptySize(message.body().getJsonObject("user").getString("userId"), new Handler<Long>() {
        @Override//from   w w w  . j av a  2  s .  c  o  m
        public void handle(Long emptySize) {
            copyFile(message.body(), documentDao, emptySize, new Handler<JsonObject>() {
                @Override
                public void handle(JsonObject res) {
                    if ("ok".equals(res.getString("status")))
                        message.reply(res);
                    else
                        message.fail(500, res.getString("status"));
                }
            });
        }
    });
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*www .j  a va2 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:org.vertx.java.resourceadapter.OutboundTestVerticle.java

License:Apache License

public void start() {
    this.vertx.eventBus().consumer("outbound-address").handler((Message<Object> msg) -> {
        String string = (String) msg.body();
        if (string != null && string.length() > 0) {
            msg.reply("Hello " + string + " from Outbound");
        }/*from   w  w w.jav a  2 s  .co  m*/
    });

}

From source file:pt.davidafsilva.slacker.server.EventServerVerticle.java

License:Open Source License

/**
 * Handles a executor register request message event by trying to register the executor with the
 * received information.//from  w  w w  . ja va2 s .c  o m
 * The registry might fail due to incompatible versions
 *
 * @param message the request message event
 */
private void handlerRegisterEvent(final Message<Object> message) {
    LOGGER.debug("received register event message: {0}", message.body());

    // validate the received event
    if (message.body() == null || !JsonObject.class.isInstance(message.body())) {
        message.fail(1, "invalid register event received");
        return;
    }

    // try to register the executor
    final JsonObject executorRequest = (JsonObject) message.body();
    executorRegistry.register(executorRequest, address -> message.reply(new JsonObject().put("a", address)),
            reason -> message.fail(1, String.format("unable to register executor: %s", reason)));
}

From source file:scp.targets.vertx.CommunicationManagerImpl.java

License:Open Source License

@Override
public <T extends Serializable> Status registerReceiver(@NonNull ReceiverConfiguration<T> configuration) {
    final ReceiverInvoker<T> _receiverInvoker = new ReceiverInvoker<>(configuration);
    this.eventBus.consumer(configuration.identifier, (Message<byte[]> msg) -> {
        final ReceiverInvokerStatus _status = _receiverInvoker.receive(getData(msg.body()));
        msg.reply(CommunicationManagerImpl.getBytes(_status));
    });/*w  w  w .  j  a va2  s  .c  o m*/
    return Status.SUCCESS;
}

From source file:scp.targets.vertx.CommunicationManagerImpl.java

License:Open Source License

@Override
public <T extends Serializable> Status registerExecutor(@NonNull ExecutorConfiguration<T> configuration) {
    final ExecutorInvoker<T> _receiverInvoker = new ExecutorInvoker<>(configuration);
    this.eventBus.consumer(configuration.identifier, (Message<byte[]> msg) -> {
        final ExecutorInvokerStatus _status = _receiverInvoker.execute(getData(msg.body()));
        msg.reply(CommunicationManagerImpl.getBytes(_status));
    });//from  ww  w  .  j av a 2  s.c om
    return Status.SUCCESS;
}

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

License:Apache License

/**
 * Returns a list of all supported devices by this adapter.
 *
 * @param message eventbus message.//from   w  ww . ja v  a  2s  .co  m
 */
private void getSupportedDevices(Message message) {

    JsonArray result = new JsonArray();

    for (JsonObject device : DeviceDatabase.getSuportedDeviceTypes()) {
        result.add(new JsonObject().put("typeId", device.getString("typeId"))
                .put("name", device.getString("name")).put("description", device.getString("description"))
                .put("manufacturer", device.getJsonObject("manufacturer")));
    }

    message.reply(constructReply(result));
}

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

License:Apache License

/**
 * Returns a list of all available devices on 1-wire bus.
 *
 * @param message eventbus message.//w w  w.  j ava  2  s .  co m
 */
private void getAvailableDevices(Message message) {
    message.reply(constructReply(getAvailableDevices()));
}

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

License:Apache License

/**
 * Read value from device with specified hwId.
 *
 * @param message eventbus message.//from www  .  j a  va  2 s . c  o m
 * @throws DeviceMissingException throws exception if specified device does not exist.
 */
private void getDeviceValue(Message message) throws DeviceMissingException {
    // Validate and extract action-specific parameters.
    if (message.body() == null) {
        message.fail(400, "Missing parameters.");
        return;
    }

    JsonObject params = (JsonObject) message.body();
    String hwId = params.getString("hwId");

    if (hwId == null || hwId.isEmpty()) {
        message.fail(400, "Missing parameter 'hwId'.");
        return;
    }

    message.reply(this.constructReply(this.getDeviceValue(hwId)));
}

From source file:servicefactories.BasicServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//  ww w  .  ja 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 "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;
    }
}