List of usage examples for io.vertx.core.eventbus Message body
@CacheReturn T body();
From source file:com.hpe.sw.cms.verticle.ScanVerticle.java
License:Apache License
@Override public void start() throws Exception { super.start(); httpClient = vertx.createHttpClient(); final String dricHost = config().getString("dric.host"); final String swarmProtocol = config().getString("swarm.protocol"); final String swarmHost = config().getString("swarm.host"); final String swarmImage = config().getString("swarm.scan.image"); final int scanMax = config().getInteger("scanner.max"); getVertx().setPeriodic(config().getLong("scan.interval", INTERVAL), h -> { httpClient.getAbs(swarmProtocol + swarmHost + "/containers/json", new Handler<HttpClientResponse>() { @Override/*from w w w. j av a2s. c o m*/ public void handle(HttpClientResponse httpClientResponse) { httpClientResponse.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer res) { JsonArray containers = res.toJsonArray(); int currentRunning = 0; for (Object obj : containers) { JsonObject container = (JsonObject) obj; if (swarmImage.equals(container.getString("Image"))) { currentRunning++; } } int fetchSize = scanMax - currentRunning; if (fetchSize > 0) { getVertx().eventBus().send(Events.IMAGES_UPDATED.name(), fetchSize, event -> { Message msg = event.result(); if (msg != null) { JsonArray updates = (JsonArray) msg.body(); for (Object obj : updates) { try { JsonObject image = (JsonObject) obj; processImage(dricHost, image.getString("host"), image.getString("name"), image.getString("tag")); } catch (Exception e) { LOG.error("image sent to Scan error", e); } } } }); } } }); } }).end(); }); //delete exited containers of scan. getVertx().setPeriodic(config().getLong("scan.interval", INTERVAL), h -> { Set containerIds = getVertx().sharedData().getLocalMap("scanContainerIds").keySet(); containerIds.forEach(containerId -> { httpClient.getAbs(swarmProtocol + swarmHost + "/containers/" + containerId + "/json", new Handler<HttpClientResponse>() { @Override public void handle(HttpClientResponse httpClientResponse) { httpClientResponse.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer event) { if ("exited".equals( event.toJsonObject().getJsonObject("State").getString("Status"))) { String containerId = event.toJsonObject().getString("Id"); httpClient .deleteAbs("http://" + swarmHost + "/containers/" + containerId, new Handler<HttpClientResponse>() { @Override public void handle(HttpClientResponse event) { LOG.info("delete container with response code :" + event.statusCode()); getVertx().sharedData() .getLocalMap("scanContainerIds") .remove(containerId); } }) .end(); } } }); } }).end(); }); }); }
From source file:com.jedlab.vertee.DatabaseServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from w w w. ja v a2s. 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 "persist": { service.persist((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.kumuluz.ee.samples.reactive.vertx.VertxEventListener.java
License:MIT License
@ReactiveEventListener(address = "tacos") public void onMessage(Message<Object> event) { if (event.body() != null) { messages.add((String) event.body()); log.info("New message received: " + event.body()); } else {// w ww . j av a 2 s.c o m log.warning("Error when receiving messages."); } }
From source file:com.panjiesw.std.service.user.UserServiceVertxProxyHandler.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 va2 s. co m*/ accessed(); switch (action) { case "save": { service.save((io.vertx.core.json.JsonObject) json.getValue("payload"), createHandler(msg)); break; } case "query": { service.query((java.lang.String) json.getValue("sql"), createListHandler(msg)); break; } case "queryOne": { service.queryOne((java.lang.String) json.getValue("sql"), createHandler(msg)); break; } case "one": { service.one((java.lang.Long) json.getValue("id"), createHandler(msg)); break; } case "findByUsername": { service.findByUsername((java.lang.String) json.getValue("username"), createHandler(msg)); break; } case "findByEmail": { service.findByEmail((java.lang.String) json.getValue("email"), createHandler(msg)); break; } case "start": { service.start(createHandler(msg)); break; } case "stop": { service.stop(createHandler(msg)); close(); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } }
From source file:com.pluralsight.dockerproductionaws.portfolio.PortfolioServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from w w w . ja 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 "getPortfolio": { service.getPortfolio(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 "buy": { service.buy(json.getValue("amount") == null ? null : (json.getLong("amount").intValue()), (io.vertx.core.json.JsonObject) json.getValue("quote"), 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 "sell": { service.sell(json.getValue("amount") == null ? null : (json.getLong("amount").intValue()), (io.vertx.core.json.JsonObject) json.getValue("quote"), 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 "evaluate": { service.evaluate(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.reachauto.account.AccountServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from www.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 "addAccount": { service.addAccount( json.getJsonObject("account") == null ? null : new com.reachauto.account.Account(json.getJsonObject("account")), createHandler(msg)); break; } case "deleteAccount": { service.deleteAccount(json.getValue("id") == null ? null : (json.getLong("id").intValue()), createHandler(msg)); break; } case "updateAccount": { service.updateAccount(json.getJsonObject("account") == null ? null : new com.reachauto.account.Account(json.getJsonObject("account")), 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 "retrieveAccount": { service.retrieveAccount(json.getValue("id") == null ? null : (json.getLong("id").intValue()), 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; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.reachauto.device.DeviceServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from www .j a v 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 "addDevice": { service.addDevice( json.getJsonObject("device") == null ? null : new com.reachauto.device.Device(json.getJsonObject("device")), createHandler(msg)); break; } case "deleteDevice": { service.deleteDevice((java.lang.String) json.getValue("id"), createHandler(msg)); break; } case "updateDevice": { service.updateDevice(json.getJsonObject("device") == null ? null : new com.reachauto.device.Device(json.getJsonObject("device")), 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 "retrieveDevice": { service.retrieveDevice((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; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.reachauto.product.ProductServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from w w w . j a v 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 "addProduct": { service.addProduct( json.getJsonObject("product") == null ? null : new com.reachauto.product.Product(json.getJsonObject("product")), createHandler(msg)); break; } case "deleteProduct": { service.deleteProduct(json.getValue("id") == null ? null : (json.getLong("id").intValue()), createHandler(msg)); break; } case "updateProduct": { service.updateProduct(json.getJsonObject("product") == null ? null : new com.reachauto.product.Product(json.getJsonObject("product")), 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 "retrieveProduct": { service.retrieveProduct(json.getValue("id") == null ? null : (json.getLong("id").intValue()), 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; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.sagalasan.swivel.control.Controller.java
License:Apache License
public void handleTimeReceived(Message message) { Time time = (Time) message.body(); onCurrentTimeReceived(time.getTime()); }
From source file:com.test.db.DbServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/* w ww . j a v a2s . com*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "storedProc": { service.storedProc((java.lang.String) json.getValue("procName"), (io.vertx.core.json.JsonObject) json.getValue("databaseConfig"), createHandler(msg)); break; } case "createStm": { service.createStm((java.lang.String) json.getValue("query"), (io.vertx.core.json.JsonObject) json.getValue("databaseConfig"), createHandler(msg)); break; } case "update": { service.update((java.lang.String) json.getValue("query"), (io.vertx.core.json.JsonObject) json.getValue("databaseConfig"), createHandler(msg)); break; } case "delete": { service.delete((java.lang.String) json.getValue("query"), (io.vertx.core.json.JsonObject) json.getValue("databaseConfig"), createHandler(msg)); break; } case "read": { service.read((java.lang.String) json.getValue("query"), (io.vertx.core.json.JsonObject) json.getValue("databaseConfig"), createHandler(msg)); break; } case "nonSharedRead": { service.nonSharedRead((java.lang.String) json.getValue("query"), (io.vertx.core.json.JsonObject) json.getValue("databaseConfig"), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.fail(-1, t.getMessage()); throw t; } }