List of usage examples for io.vertx.core.json JsonObject JsonObject
public JsonObject()
From source file:com.github.ithildir.airbot.service.UserServiceVertxEBProxy.java
License:Apache License
public void updateUserLocation(String userId, double latitude, double longitude, String country, Handler<AsyncResult<Void>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/* www .j av a2 s . c o m*/ } JsonObject _json = new JsonObject(); _json.put("userId", userId); _json.put("latitude", latitude); _json.put("longitude", longitude); _json.put("country", country); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "updateUserLocation"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
public static void ask(HttpServerResponse httpServerResponse, String conversationToken, String initialPrompt, String[] noInputPrompts) { httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8"); httpServerResponse.putHeader("Google-Assistant-API-Version", "v1"); JsonObject responseJSON = new JsonObject(); if (conversationToken != null) { responseJSON.put("conversation_token", conversationToken); }//from w w w . j av a 2s . c o m responseJSON.put("expect_user_response", true); responseJSON.put("expected_inputs", JsonUtil.getArray(_getExpectedInputJSON(initialPrompt, noInputPrompts))); httpServerResponse.end(responseJSON.encode()); }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
public static void tell(HttpServerResponse httpServerResponse, String textToSpeech) { httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8"); httpServerResponse.putHeader("Google-Assistant-API-Version", "v1"); JsonObject responseJSON = new JsonObject(); JsonObject finalResponseJSON = new JsonObject(); finalResponseJSON.put("speech_response", _getPromptJSON(textToSpeech)); responseJSON.put("final_response", finalResponseJSON); httpServerResponse.end(responseJSON.encode()); }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
private static JsonObject _getExpectedInputJSON(String initialPrompt, String[] noInputPrompts) { JsonObject expectedInputJSON = new JsonObject(); JsonObject inputPromptJSON = new JsonObject(); inputPromptJSON.put("initial_prompts", JsonUtil.getArray(_getPromptJSON(initialPrompt))); if (noInputPrompts.length > 0) { JsonArray noInputPromptsJSON = new JsonArray(); for (String noInputPrompt : noInputPrompts) { noInputPromptsJSON.add(_getPromptJSON(noInputPrompt)); }/*from w w w . j a v a2 s . c o m*/ inputPromptJSON.put("no_input_prompts", noInputPromptsJSON); } expectedInputJSON.put("input_prompt", inputPromptJSON); expectedInputJSON.put("possible_intents", _getPossibleIntentsJSON(INTENT_TEXT)); return expectedInputJSON; }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
private static JsonArray _getPossibleIntentsJSON(String intent) { JsonObject jsonObject = new JsonObject(); jsonObject.put("intent", intent); return JsonUtil.getArray(jsonObject); }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
private static JsonObject _getPromptJSON(String textToSpeech) { JsonObject jsonObject = new JsonObject(); jsonObject.put("text_to_speech", textToSpeech); return jsonObject; }
From source file:com.github.jackygurui.vertxredissonrepository.provider.RedissonProvider.java
License:Apache License
public static Redisson create() { return create(new JsonObject()); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void ensureUniqueAndIndexingBlocking(String id, JsonObject data, Boolean isNew, AsyncResultHandler<String> resultHandler) { Async.waterfall().<String>task(t -> { RBatch batch = redissonOther.createBatch(); ArrayList<String> pList = new ArrayList(); try {//www.j a va 2 s.co m prepareEnsureUnique(id, data, batch, pList, null); } catch (RepositoryException ex) { t.handle(Future.failedFuture(ex)); return; } if (pList.isEmpty()) { t.handle(Future.succeededFuture()); return; } batch.executeAsync().addListener(future -> { if (future.isSuccess() && future.get() != null) { List<String> result = (List<String>) future.get(); Stream<String> filter = pList.stream().filter( p -> result.get(pList.indexOf(p)) != null && !result.get(pList.indexOf(p)).equals(id));//uniques are ensured by using putIfAbsent and all results should be null or itself to indicate no violation. Object[] filterArray = filter.toArray(); if (filterArray.length != 0) { t.handle(Future.succeededFuture( new JsonObject().put("uniqueViolation", Json.encode(filterArray)).encode())); //now undo these things. ArrayList<String> undoList = pList.stream() .filter(p -> result.get(pList.indexOf(p)) == null || result.get(pList.indexOf(p)).equals(id)) .collect(Collectors.toCollection(ArrayList::new)); Async.<Void>waterfall().<Void>task(task -> { RBatch b = redissonOther.createBatch(); try { prepareUndoUnique(id, data, b, undoList, null); } catch (RepositoryException ex) { task.handle(Future.failedFuture(ex)); } b.executeAsync().addListener(fu -> { task.handle(fu.isSuccess() ? Future.succeededFuture((Void) fu.get()) : Future.failedFuture(fu.cause())); }); }).run(run -> { logger.debug("Parallel undo indexing [id: " + id + "] " + (run.succeeded() ? "successed." : "failed.")); }); } else { t.handle(Future.succeededFuture()); } } else { t.handle(Future.failedFuture(!future.isSuccess() ? future.cause().fillInStackTrace() : new RepositoryException("No unique check result returned"))); } }); }).<String>task((violations, t) -> { if (violations != null) { t.handle(Future.failedFuture(violations)); return; } else { t.handle(Future.succeededFuture()); } //parallel indexing Async.<Void>waterfall().<T>task(task -> { if (!isNew) { fetch(id, Boolean.TRUE, task); } else { task.handle(Future.succeededFuture(null)); } }).<Void>task((r, task) -> { reIndex(id, r, data, isNew, ri -> { task.handle( ri.succeeded() ? Future.succeededFuture(ri.result()) : Future.failedFuture(ri.cause())); }); }).run(run -> { logger.debug("Parallel Indexing [id: " + id + "] " + (run.succeeded() ? "successed." : "failed."), run.cause()); }); }).run(resultHandler); }
From source file:com.github.mcollovati.vertx.vaadin.VaadinVerticle.java
License:Open Source License
@Override public void start(Future<Void> startFuture) throws Exception { log.info("Starting vaadin verticle " + getClass().getName()); VaadinVerticleConfiguration vaadinVerticleConfiguration = getClass() .getAnnotation(VaadinVerticleConfiguration.class); JsonObject vaadinConfig = new JsonObject(); vaadinConfig.put("serviceName", this.deploymentID()); vaadinConfig.put("mountPoint", Optional.ofNullable(vaadinVerticleConfiguration) .map(VaadinVerticleConfiguration::mountPoint).orElse("/")); readUiFromEnclosingClass(vaadinConfig); readConfigurationAnnotation(vaadinConfig); vaadinConfig.mergeIn(config().getJsonObject("vaadin", new JsonObject())); String mountPoint = vaadinConfig.getString("mountPoint"); VertxVaadin vertxVaadin = createVertxVaadin(vaadinConfig); vaadinService = vertxVaadin.vaadinService(); HttpServerOptions serverOptions = new HttpServerOptions().setCompressionSupported(true); httpServer = vertx.createHttpServer(serverOptions); Router router = Router.router(vertx); router.mountSubRouter(mountPoint, vertxVaadin.router()); httpServer.websocketHandler(vertxVaadin.webSocketHandler()); httpServer.requestHandler(router::accept).listen(config().getInteger("httpPort", 8080)); serviceInitialized(vaadinService, router); log.info("Started vaadin verticle " + getClass().getName()); startFuture.complete();/*from w w w .ja va 2 s . c om*/ }
From source file:com.github.meshuga.vertx.neo4j.rbac.auth.AuthServiceVertxEBProxy.java
License:Apache License
public void hasPermission(String userName, String permission, Handler<AsyncResult<Boolean>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/* ww w .ja v a 2 s. c om*/ } JsonObject _json = new JsonObject(); _json.put("userName", userName); _json.put("permission", permission); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "hasPermission"); _vertx.eventBus().<Boolean>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); }