List of usage examples for io.vertx.core Future future
future
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);//from w w w.ja v a 2 s . com fileSystem.readFile(filePath, res -> { if (res.succeeded()) { T asset = parse(res.result(), classOfT); future.complete(asset); } 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.//from w ww . j a v a2s. c om * * @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. *//*from w ww .ja v a 2s . co 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 w w w . ja v a2s . 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. */// w w w .j a v a 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);/* w w w .j a v a2 s. c o m*/ // 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(); } } 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);/*from www . ja va 2 s . c o m*/ DeliveryOptions options = Kernel.DELIVERY_OPTIONS.get(FlowInstanceMetadataCodec.NAME); eventBus.send(EngineAddresses.REPO_FLOW_NEXT_ROUTE, routeMetadata, options, reply -> { future.complete((Route) reply.result().body()); }); }
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);/* w ww .j a va 2 s . c om*/ 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()); }); } else { future.complete(new FlowInstance(null, flowMetadata)); } }
From source file:io.flowly.engine.verticles.Engine.java
License:Open Source License
private void saveInstance(FlowInstance instance, String status, boolean saveMetaData, Handler<AsyncResult<Boolean>> resultHandler) { Future<Boolean> future = Future.future(); future.setHandler(resultHandler);/*from w ww .j av a 2s . c o m*/ FlowInstanceWrapper wrapper = new FlowInstanceWrapper(instance, false, saveMetaData, status, null); eventBus.send(EngineAddresses.REPO_FLOW_SAVE_INSTANCE, wrapper, reply -> { future.complete((Boolean) reply.result().body()); }); }
From source file:io.flowly.engine.verticles.Engine.java
License:Open Source License
private void getInstance(Long flowObjectInstanceId, Handler<AsyncResult<FlowInstance>> resultHandler) { Future<FlowInstance> future = Future.future(); future.setHandler(resultHandler);/* ww w.java2 s .c om*/ if (flowObjectInstanceId != null) { eventBus.send(EngineAddresses.GET_FLOW_INSTANCE_TASK, flowObjectInstanceId, reply -> { future.complete((FlowInstance) reply.result().body()); }); } else { future.complete(null); } }