Refine search
private void removeSub(String subName, ClusterNodeInfo node, Handler<AsyncResult<Void>> completionHandler) { subs.remove(subName, node, ar -> { if (!ar.succeeded()) { log.error("Failed to remove sub", ar.cause()); } else { if (ar.result()) { if (completionHandler != null) { completionHandler.handle(Future.succeededFuture()); } } else { if (completionHandler != null) { completionHandler.handle(Future.failedFuture("sub not found")); } } } }); }
setClusterViewChangedHandler(haManager); clusterManager.<String, ClusterNodeInfo>getAsyncMultiMap(SUBS_MAP_NAME, ar1 -> { if (ar1.succeeded()) { subs = ar1.result(); server = vertx.createNetServer(getServerOptions()); if (asyncResult.succeeded()) { int serverPort = getClusterPublicPort(options, server.actualPort()); String serverHost = getClusterPublicHost(options); nodeInfo = new ClusterNodeInfo(clusterManager.getNodeID(), serverID); vertx.executeBlocking(fut -> { haManager.addDataToAHAInfo(SERVER_ID_HA_KEY, new JsonObject().put("host", serverID.host).put("port", serverID.port)); fut.complete(); }, false, ar2 -> { if (ar2.succeeded()) { started = true; resultHandler.handle(Future.succeededFuture()); } else { resultHandler.handle(Future.failedFuture(ar2.cause())); resultHandler.handle(Future.failedFuture(asyncResult.cause())); resultHandler.handle(Future.failedFuture(ar1.cause()));
@Override public void methodWithHandlerAsyncResultListComplexJsonArray(Handler<AsyncResult<List<JsonArray>>> listHandler) { List<JsonArray> list = Arrays.asList(new JsonArray().add(new JsonObject().put("foo", "hello")), new JsonArray().add(new JsonObject().put("bar", "bye"))); listHandler.handle(Future.succeededFuture(list)); }
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { if (skip != null && context.normalisedPath().startsWith(skip)) { context.next(); return; } parseAuthorization(context, false, parseAuthorization -> { if (parseAuthorization.failed()) { handler.handle(Future.failedFuture(parseAuthorization.cause())); return; } handler.handle(Future.succeededFuture(new JsonObject().put("jwt", parseAuthorization.result()).put("options", options))); }); }
/** * Undeploys the previously deployed verticle. * * @param completionHandler the completion handler */ public void undeploy(Handler<AsyncResult<Void>> completionHandler) { vertx.undeploy(deploymentId, res -> { if (res.failed()) { log.error("Failed in undeploying " + deploymentId, res.cause()); } else { log.info("Succeeded in undeploying " + deploymentId); } deploymentId = null; completionHandler.handle(res); }); }
private void testFSProps(String fileName, Handler<FileSystemProps> afterOK) throws Exception { vertx.fileSystem().fsProps(testDir + pathSep + fileName, ar -> { if (ar.failed()) { fail(ar.cause().getMessage()); } else { afterOK.handle(ar.result()); testComplete(); } }); }
private void doDeployVerticle(final String verticleName, DeploymentOptions deploymentOptions, final Handler<AsyncResult<String>> doneHandler) { final Handler<AsyncResult<String>> wrappedHandler = ar1 -> { vertx.<String>executeBlocking(fut -> { if (ar1.succeeded()) { // Tell the other nodes of the cluster about the verticle for HA purposes String deploymentID = ar1.result(); addToHA(deploymentID, verticleName, deploymentOptions); fut.complete(deploymentID); } else { fut.fail(ar1.cause()); } }, false, ar2 -> { if (doneHandler != null) { doneHandler.handle(ar2); } else if (ar2.failed()) { log.error("Failed to deploy verticle", ar2.cause()); } }); }; deploymentManager.deployVerticle(verticleName, deploymentOptions, wrappedHandler); }
protected void getPropertiesConfiguration(Vertx vertx, ConfigStore store, Handler<AsyncResult<JsonObject>> handler) { store.get(buffer -> { if (buffer.failed()) { handler.handle(Future.failedFuture(buffer.cause())); } else { PROPERTIES.process(vertx, new JsonObject(), buffer.result(), handler); } }); } }
@Override public SomeDatabaseService getDataById(int id, Handler<AsyncResult<JsonObject>> resultHandler) { if (id > 0) { resultHandler.handle(Future.succeededFuture(new JsonObject() .put("id", id) .put("name", "vertx"))); } else { resultHandler.handle(Future.failedFuture("Invalid id")); } return this; } }
private void createHaManager(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler) { this.<Map<String, String>>executeBlocking(fut -> { fut.complete(clusterManager.getSyncMap(CLUSTER_MAP_NAME)); }, false, ar -> { if (ar.succeeded()) { Map<String, String> clusterMap = ar.result(); haManager = new HAManager(this, deploymentManager, clusterManager, clusterMap, options.getQuorumSize(), options.getHAGroup(), options.isHAEnabled()); startEventBus(resultHandler); } else { log.error("Failed to start HAManager", ar.cause()); resultHandler.handle(Future.failedFuture(ar.cause())); } }); }
private void initializeHaManager(Handler<AsyncResult<Vertx>> resultHandler) { this.executeBlocking(fut -> { // Init the manager (i.e register listener and check the quorum) // after the event bus has been fully started and updated its state // it will have also set the clustered changed view handler on the ha manager haManager.init(); fut.complete(); }, false, ar -> { if (ar.succeeded()) { if (metrics != null) { metrics.vertxCreated(this); } resultHandler.handle(Future.succeededFuture(this)); } else { log.error("Failed to initialize HAManager", ar.cause()); resultHandler.handle(Future.failedFuture(ar.cause())); } }); }
void subscribe(Handler<WebSocket> completionHandler, Handler<Throwable> failureHandler) { Future<WebSocket> fut = Future.future(); fut.setHandler(ar -> { if (ar.succeeded()) { completionHandler.handle(ar.result()); } else { failureHandler.handle(ar.cause()); } }); exceptionHandler(fut::tryFail); handler(fut::tryComplete); }
AtomicBoolean failed = new AtomicBoolean(); for (Closeable hook : copy) { Future<Void> a = Future.future(); a.setHandler(ar -> { if (ar.failed()) { if (failed.compareAndSet(false, true)) { completionHandler.handle(Future.failedFuture(ar.cause())); completionHandler.handle(Future.succeededFuture()); hook.close(a); } catch (Throwable t) { log.warn("Failed to run close hooks", t); a.tryFail(t); completionHandler.handle(Future.succeededFuture()); completionHandler.handle(Future.succeededFuture());
@Override public void process(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) { System.out.println("Processing..."); JsonObject result = document.copy(); if (!document.containsKey("name")) { resultHandler.handle(ServiceException.fail(NO_NAME_ERROR, "No name in the document")); } else if (document.getString("name").isEmpty() || document.getString("name").equalsIgnoreCase("bad")) { resultHandler.handle(ServiceException.fail(BAD_NAME_ERROR, "Bad name in the document: " + document.getString("name"), new JsonObject().put("name", document.getString("name")))); } else { result.put("approved", true); resultHandler.handle(Future.succeededFuture(result)); } }
@Test public void testCloseHooksCalled() throws Exception { AtomicInteger closedCount = new AtomicInteger(); Closeable myCloseable1 = completionHandler -> { closedCount.incrementAndGet(); completionHandler.handle(Future.succeededFuture()); }; Closeable myCloseable2 = completionHandler -> { closedCount.incrementAndGet(); completionHandler.handle(Future.succeededFuture()); }; MyAsyncVerticle verticle = new MyAsyncVerticle(f-> { ContextInternal ctx = (ContextInternal)Vertx.currentContext(); ctx.addCloseHook(myCloseable1); ctx.addCloseHook(myCloseable2); f.complete(null); }, f -> f.complete(null)); vertx.deployVerticle(verticle, ar -> { assertTrue(ar.succeeded()); assertEquals(0, closedCount.get()); // Now undeploy vertx.undeploy(ar.result(), ar2 -> { assertTrue(ar2.succeeded()); assertEquals(2, closedCount.get()); testComplete(); }); }); await(); }
@SuppressWarnings("unchecked") @Override public void handle(AsyncResult event) { if (event.failed()) { handler.handle(event); } else { List<String> txts = new ArrayList<>(); List<List<String>> records = (List<List<String>>) event.result(); for (List<String> txt: records) { txts.addAll(txt); } handler.handle(Future.succeededFuture(txts)); } } }, DnsRecordType.TXT);
@Override public void createStream(Handler<AsyncResult<HttpClientStream>> handler) { if (current instanceof Http1xClientConnection) { current.createStream(ar -> { if (ar.succeeded()) { HttpClientStream stream = ar.result(); UpgradingStream upgradingStream = new UpgradingStream(stream, (Http1xClientConnection) current); handler.handle(Future.succeededFuture(upgradingStream)); } else { handler.handle(ar); } }); } else { current.createStream(handler); } }
@Override public void update(Record record, Handler<AsyncResult<Void>> resultHandler) { Objects.requireNonNull(record.getRegistration(), "No registration id in the record"); redis.hset(key, record.getRegistration(), record.toJson().encode(), ar -> { if (ar.succeeded()) { resultHandler.handle(Future.succeededFuture()); } else { resultHandler.handle(Future.failedFuture(ar.cause())); } }); }