List of usage examples for io.vertx.core.json JsonObject JsonObject
public JsonObject()
From source file:FileAccess.java
public JsonObject getProjectStructure(String projectId) { JsonObject projectStructure = new JsonObject(); JsonArray rootFolder = new JsonArray(); JsonArray rootFile = new JsonArray(); List<String> rootDirectorys = vertx.fileSystem().readDirBlocking("project/" + projectId); System.out.println(new JsonArray(rootDirectorys).toString()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (String directory : rootDirectorys) { System.out.println(directory + "directory"); FileProps something = vertx.fileSystem().lpropsBlocking(directory); if (something.isDirectory()) { JsonObject directoryJSON = new JsonObject(); String splitDirectory[] = directory.split("\\\\"); directoryJSON.put("name", splitDirectory[splitDirectory.length - 1]); // tinggal tambahkan encode menggunakan base 64 agar tidak terdeteksi titik. String id = splitDirectory[splitDirectory.length - 2]; String tmpId = new Base32().encodeAsString(splitDirectory[splitDirectory.length - 1].getBytes()) .replace("=", "0"); directoryJSON.put("id", tmpId); directoryJSON.put("create_date", dateFormat.format(new Date(something.creationTime()))); directoryJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime()))); rootFolder.add(directoryJSON); List<String> subDirectorysFiles = vertx.fileSystem().readDirBlocking(directory); JsonArray subFiles = new JsonArray(); for (String subDirectoryFile : subDirectorysFiles) { JsonObject fileJSON = new JsonObject(); String splitFile[] = subDirectoryFile.split("\\\\"); fileJSON.put("name", splitFile[splitFile.length - 1]); fileJSON.put("id", new Base32().encodeAsString( (splitFile[splitFile.length - 2] + "/" + splitFile[splitFile.length - 1]).getBytes()) .replace("=", "0")); fileJSON.put("create_date", dateFormat.format(new Date(something.creationTime()))); fileJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime()))); subFiles.add(fileJSON);/*from ww w .j a v a 2 s . c o m*/ } directoryJSON.put("files", subFiles); } else { JsonObject fileJSON = new JsonObject(); String splitFile[] = directory.split("\\\\"); fileJSON.put("name", splitFile[splitFile.length - 1]); fileJSON.put("id", new Base32().encodeAsString(splitFile[splitFile.length - 1].getBytes()).replace("=", "0")); fileJSON.put("create_date", dateFormat.format(new Date(something.creationTime()))); fileJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime()))); rootFile.add(fileJSON); } } projectStructure.put("folders", rootFolder); projectStructure.put("files", rootFile); System.out.println(projectStructure.toString()); return projectStructure; }
From source file:RestAPI.java
private void setUpInitialData() { addProduct(new JsonObject().put("id", "prod3568").put("name", "Egg Whisk").put("price", 3.99).put("weight", 150));// w w w . j av a2 s. c o m addProduct(new JsonObject().put("id", "prod7340").put("name", "Tea Cosy").put("price", 5.99).put("weight", 100)); addProduct( new JsonObject().put("id", "prod8643").put("name", "Spatula").put("price", 1.00).put("weight", 80)); }
From source file:FortuneCookieServiceVerticle.java
License:Apache License
@Override public void start() throws Exception { try (BufferedReader br = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/fortune-cookie.txt")))) { for (String line; (line = br.readLine()) != null;) { fortuneCookies.put(++bound, line); }//from ww w.j ava 2 s .c o m } catch (Exception e) { throw new RuntimeException("Error setting up FortuneCookieServiceVerticle"); } service = AMQPService.createEventBusProxy(vertx, "vertx.service-amqp"); ServiceOptions options = new ServiceOptions(); service.registerService(serviceAddress, noticeAddress, options, result -> { if (result.succeeded()) { print("Service registered succesfully with the vertx-amqp-bridge using address : '%s'", serviceAddress); } else { print("Unable to register service"); } }); vertx.eventBus().<JsonObject>consumer(serviceAddress, msg -> { JsonObject request = msg.body(); // print(request.encodePrettily()); String linkId = request.getString(AMQPService.INCOMING_MSG_LINK_REF); print("Received a request for a fortune-cookie from client [%s]", linkId); print("reply-to %s", msg.replyAddress()); service.accept(request.getString(AMQPService.INCOMING_MSG_REF), result -> { }); JsonObject response = new JsonObject(); response.put(AMQPService.OUTGOING_MSG_REF, linkId); response.put("body", fortuneCookies.get(random.nextInt(bound))); msg.reply(response); }); vertx.eventBus().<JsonObject>consumer(noticeAddress, msg -> { NotificationType type = NotificationHelper.getType(msg.body()); if (type == NotificationType.DELIVERY_STATE) { DeliveryTracker tracker = NotificationHelper.getDeliveryTracker(msg.body()); print("The the fortune-cookie is acknowledged by the client. Issuing another request credit after a 30s delay"); print("=============================================================\n"); vertx.setTimer(30 * 1000, timer -> { service.issueCredits(tracker.getMessageRef(), 1, result -> { }); }); } else if (type == NotificationType.INCOMING_LINK_OPENED) { String linkRef = NotificationHelper.getLinkRef(msg.body()); print("A client [%s] contacted the fortune-cookie service, issueing a single request-credit to start with", linkRef); print("============================================================="); service.issueCredits(linkRef, 1, result -> { }); } }); }
From source file:DbHelper.java
public void init(Vertx vertx) { JsonObject mysqlConfig = new JsonObject().put("host", "127.0.0.1") // .put("port", 5432) .put("maxPoolSize", 1000).put("username", "admin").put("password", "212") .put("database", "easy_arduino").put("queryTimeout", 7000); this.mySQLClient = MySQLClient.createShared(vertx, mysqlConfig); mySQLClient.getConnection(conHandler -> { System.out.println(conHandler.cause()); });/*ww w . j a v a 2 s .com*/ }
From source file:DbHelper.java
public void getProjectByFile(String projectId, Handler<JsonObject> handlerRequest) { handlerRequest.handle(new JsonObject().put("m", "m")); }
From source file:DbHelper.java
public void getProject(String projectId, Handler<JsonObject> handlerRequest) { String queryFolder = "SELECT pk_id_project as id, name , detail, board_type as arduinoType, ic_type as icType, accessbility FROM project WHERE project.pk_id_project ='" + projectId + "';"; System.out.println(queryFolder); mySQLClient.getConnection(resConnection -> { if (resConnection.succeeded()) { SQLConnection connection;/*w w w . ja v a 2 s . c o m*/ connection = resConnection.result(); connection.setAutoCommit(false, autoCommit -> { if (autoCommit.succeeded()) { connection.query(queryFolder, handlerQuery -> { if (handlerQuery.succeeded()) { ResultSet resultSet = handlerQuery.result(); JsonObject resultJSON = resultSet.getRows().get(0); JsonObject project = new JsonObject(); project.put("id", resultJSON.getString("id")); project.put("name", resultJSON.getString("name")); project.put("detail", resultJSON.getString("detail")); JsonObject configProject = new JsonObject(); configProject.put("arduinoType", resultJSON.getString("arduinoType")); configProject.put("icType", resultJSON.getString("icType")); configProject.put("arduinoType", resultJSON.getString("arduinoType")); configProject.put("acessbility", resultJSON.getString("acessbility")); configProject.put("port", "com3"); project.put("config", configProject); handlerRequest.handle(project); // getProjectStructure(projectId, handler -> { // System.out.println("finisssss--------------------"); // JsonObject folders = new JsonObject(); // folders.put("folders", handler); // project.put("sourceCode", folders); //// project.put("files", new JsonArray().add(handler.getJsonObject(0).getJsonArray("files").getJsonObject(0))); //// System.out.println(project.toString()); // handlerRequest.handle(project); // }); } else { System.out.println("failed " + handlerQuery.cause()); } connection.close(); }); } else { System.out.println("auto commit failed"); } }); // Got a connection } else { // Failed to get connection - deal with it System.out.println("true failes"); } }); }
From source file:app.Main.java
License:Apache License
public static void main(String... args) throws Throwable { Vertx vertx = Vertx.vertx();/*w w w .ja va2s .c om*/ TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddressRegex("sample.*")) .addOutboundPermitted(new PermittedOptions().setAddressRegex("sample.*"))); vertx.eventBus().consumer("sample.dumb.inbox", message -> { JsonObject body = (JsonObject) message.body(); System.out.println(body.encodePrettily()); }); MessageProducer<Object> tickPublisher = vertx.eventBus().publisher("sample.clock.ticks"); vertx.setPeriodic(1000L, id -> { tickPublisher.send(new JsonObject().put("tick", id)); }); vertx.eventBus().consumer("sample.echo", message -> { JsonObject body = (JsonObject) message.body(); System.out.println("Echoing: " + body.encodePrettily()); message.reply(body); }); bridge.listen(7000, result -> { if (result.failed()) { throw new RuntimeException(result.cause()); } else { System.out.println("TCP Event Bus bridge running on port 7000"); } }); }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxEBProxy.java
License:Apache License
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }// w w w . j av a2 s . c om JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "fetchAllPages"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private void logVertxOptions() { LOG.logp(CONFIG, getClass().getName(), "logVertxOptions", () -> { final JsonObject json = new JsonObject() .put("BlockedThreadCheckInterval", vertxOptions.getBlockedThreadCheckInterval()) .put("ClusterHost", vertxOptions.getClusterHost()) .put("ClusterPingInterval", vertxOptions.getClusterPingInterval()) .put("ClusterPingReplyInterval", vertxOptions.getClusterPingReplyInterval()) .put("ClusterPort", vertxOptions.getClusterPort()) .put("EventLoopPoolSize", vertxOptions.getEventLoopPoolSize()) .put("HAGroup", vertxOptions.getHAGroup()) .put("InternalBlockingPoolSize", vertxOptions.getInternalBlockingPoolSize()) .put("MaxEventLoopExecuteTime", vertxOptions.getMaxEventLoopExecuteTime()) .put("MaxWorkerExecuteTime", vertxOptions.getMaxWorkerExecuteTime()) .put("QuorumSize", vertxOptions.getQuorumSize()) .put("WarningExceptionTime", vertxOptions.getWarningExceptionTime()) .put("WorkerPoolSize", vertxOptions.getWorkerPoolSize()); final ClusterManager clusterManager = vertxOptions.getClusterManager(); if (clusterManager != null) { json.put("clusterManagerClass", clusterManager.getClass().getName()); }/* www . j a v a 2 s.com*/ final MetricsOptions metricsOptions = vertxOptions.getMetricsOptions(); if (metricsOptions != null) { json.put("MetricsOptions", toJsonObject(metricsOptions)); } return json.encodePrettily(); }); }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private JsonObject toJsonObject(final MetricsOptions metricsOptions) { if (metricsOptions instanceof DropwizardMetricsOptions) { final DropwizardMetricsOptions dropwizardMetricsOptions = (DropwizardMetricsOptions) metricsOptions; final JsonObject json = new JsonObject().put("enabled", metricsOptions.isEnabled()).put("jmxEnabled", dropwizardMetricsOptions.isJmxEnabled()); toJsonObject(dropwizardMetricsOptions.getMonitoredEventBusHandlers()) .ifPresent(jsonArray -> json.put("MonitoredEventBusHandlers", jsonArray)); toJsonObject(dropwizardMetricsOptions.getMonitoredHttpClientUris()) .ifPresent(jsonArray -> json.put("MonitoredHttpClientUris", jsonArray)); toJsonObject(dropwizardMetricsOptions.getMonitoredHttpServerUris()) .ifPresent(jsonArray -> json.put("MonitoredHttpServerUris", jsonArray)); return json; } else {//from w w w . ja v a 2 s . com return new JsonObject().put("enabled", metricsOptions.isEnabled()); } }