List of usage examples for io.vertx.core Future setHandler
@Fluent
default Future<T> setHandler(Handler<AsyncResult<T>> handler)
From source file:de.braintags.netrelay.processor.impl.AbstractProcessor.java
License:Open Source License
@Override public void handle(Long timerId) { if (running) { LOGGER.info("still running"); return;/*w ww . j a va 2 s. c om*/ } else { running = true; this.timerId = timerId; Future<Void> future = Future.future(); future.setHandler(ar -> { if (ar.failed()) { if (finishOnError) { LOGGER.warn("Finishing processor " + getClass().getName() + " cause of an error", ar.cause()); vertx.cancelTimer(timerId); } else { LOGGER.warn("Error occured in processor " + getClass().getName(), ar.cause()); } running = false; } else { LOGGER.info("successfully finished processor"); running = false; } }); handleEvent(future); } }
From source file:examples.ConfigExamples.java
License:Apache License
public void future(ConfigRetriever retriever) { Future<JsonObject> future = retriever.getConfig(); future.setHandler(ar -> { if (ar.failed()) { // Failed to retrieve the configuration } else {//from w ww .j av a2s.co m JsonObject config = ar.result(); } }); }
From source file:io.flowly.core.parser.JsonParser.java
License:Open Source License
@Override public <T extends Object> void parse(String filePath, Class<T> classOfT, Handler<AsyncResult<T>> resultHandler) { Future<T> future = Future.future(); future.setHandler(resultHandler); fileSystem.readFile(filePath, res -> { if (res.succeeded()) { T asset = parse(res.result(), classOfT); future.complete(asset);// w ww . j a va2 s . c om } else { future.fail(res.cause()); } }); }
From source file:io.flowly.core.verticles.VerticleUtils.java
License:Open Source License
/** * Recursively deploy a list of verticles. Fails fast, i.e. if a verticle fails, the remaining verticles * are not deployed.// w w w . j av a2 s. c o m * * @param verticleDeployments the stack of verticles to be deployed. By the end of the method execution * the stack will most likely become empty. * @param deployedVerticles set that is used to store the deployment ids of verticles. * @param vertx vertx platform used to deploy verticles. * @param resultHandler result handler that is invoked after verticle deployments are complete. */ public static void deployVerticles(Stack<VerticleDeployment> verticleDeployments, Set<JsonObject> deployedVerticles, Vertx vertx, Handler<AsyncResult<Void>> resultHandler) { Future<Void> deployedFuture = Future.future(); deployedFuture.setHandler(resultHandler); deployVerticles(verticleDeployments, deployedVerticles, vertx, deployedFuture); }
From source file:io.flowly.core.verticles.VerticleUtils.java
License:Open Source License
/** * Undeploy verticles based on the given list of deployment ids. * * @param deployementIds the list of ids associated with deployed verticles. * @param vertx vertx platform used to undeploy verticles. * @param resultHandler result handler that is invoked after the verticles are undeployed. *//* www . jav a 2 s. c o m*/ public static void undeployVerticles(Iterator<String> deployementIds, Vertx vertx, Handler<AsyncResult<Void>> resultHandler) { Future<Void> undeployedFuture = Future.future(); undeployedFuture.setHandler(resultHandler); undeployVerticles(deployementIds, vertx, undeployedFuture); }
From source file:io.flowly.core.verticles.VerticleUtils.java
License:Open Source License
public static void undeployVerticles(Set<JsonObject> deployedVerticles, Vertx vertx, Handler<AsyncResult<Void>> resultHandler) { Future<Void> undeployedFuture = Future.future(); undeployedFuture.setHandler(resultHandler); List<String> deploymentIds = new ArrayList<>(); Iterator<JsonObject> iterator = deployedVerticles.iterator(); while (iterator.hasNext()) { deploymentIds.add(iterator.next().getString(ObjectKeys.DEPLOYMENT_ID)); }//from ww w .ja v a 2 s . c o m undeployVerticles(deploymentIds.iterator(), vertx, resultHandler); }
From source file:io.flowly.core.verticles.VerticleUtils.java
License:Open Source License
/** * Registers all the message handlers in the queue on the event bus. * * @param eventBus the event bus on which given message handlers are registered. * @param logger the logger used to capture registration failures. * @param registrations queue of consumer registrations. * @param resultHandler handler that is invoked after all handlers are registered on the event bus. *///from w w w . ja va 2 s . co m public static <T> void registerHandlers(EventBus eventBus, Logger logger, Queue<ConsumerRegistration<T>> registrations, Handler<AsyncResult<Void>> resultHandler) { Future<Void> future = Future.future(); future.setHandler(resultHandler); recursivelyRegisterHandlers(eventBus, logger, registrations, future); }
From source file:io.flowly.engine.verticles.Build.java
License:Open Source License
private void saveFlows(List<Flow> flows, Handler<AsyncResult<Void>> resultHandler) { Future<Void> future = Future.future(); future.setHandler(resultHandler); // Save flow and its router in the repository. AtomicInteger counter = new AtomicInteger(0); for (Flow flow : flows) { vertx.eventBus().send(EngineAddresses.REPO_FLOW_SAVE, flow, reply -> { if (reply.succeeded() && (Boolean) reply.result().body()) { if (counter.incrementAndGet() == flows.size()) { future.complete();/* w ww. j ava 2s. c o m*/ } } else if (!future.failed()) { future.fail(reply.cause()); } }); } }
From source file:io.flowly.engine.verticles.Engine.java
License:Open Source License
private void getNextRoute(FlowInstanceMetadata routeMetadata, Handler<AsyncResult<Route>> resultHandler) { Future<Route> future = Future.future(); future.setHandler(resultHandler); DeliveryOptions options = Kernel.DELIVERY_OPTIONS.get(FlowInstanceMetadataCodec.NAME); eventBus.send(EngineAddresses.REPO_FLOW_NEXT_ROUTE, routeMetadata, options, reply -> { future.complete((Route) reply.result().body()); });// w ww . ja v a2 s.com }
From source file:io.flowly.engine.verticles.Engine.java
License:Open Source License
private void createInstance(FlowMetadata flowMetadata, Handler<AsyncResult<FlowInstance>> resultHandler) { Future<FlowInstance> future = Future.future(); future.setHandler(resultHandler); if (flowMetadata.persistenceEnabled()) { DeliveryOptions options = Kernel.DELIVERY_OPTIONS.get(FlowMetadataCodec.NAME); eventBus.send(EngineAddresses.REPO_FLOW_CREATE_INSTANCE, flowMetadata, options, reply -> { future.complete((FlowInstance) reply.result().body()); });//www . ja va2 s . c o m } else { future.complete(new FlowInstance(null, flowMetadata)); } }