Reputation: 161
I am working with Vert.x and a MainVerticle written in Java. I need to deploy different types of verticles in configurable number of instances. So, that's why I tried to create a List of futures and afterwards I could use a CompositeFuture.all() to complete the process.
The problem is that the composite future never calls the handler. For each verticle, the message [>] Deployed verticle... appears. But a the end, the message [>] Verticles deployment complete never does. The verticles are working, but I need to perform another actions when all the deploymens were ready.
This is the snippet:
private Future<Void> loadVerticles()
{
Promise<Void> promise = Promise.promise();
List<Future<Void>> verticleDeployments = new ArrayList<>();
for (Integer i = 0; i < instancesA; i++)
verticleDeployments.add(deployHelper(ApiVerticleA.class.getName()));
for (Integer i = 0; i < instancesB; i++)
verticleDeployments.add(deployHelper(ApiVerticleB.class.getName()));
for (Integer i = 0; i < instancesC; i++)
verticleDeployments.add(deployHelper(ApiVerticleC.class.getName()));
CompositeFuture.all(new ArrayList<>(verticleDeployments)).setHandler( result -> {
if (result.succeeded()) {
System.out.println("[>] Verticles deployment complete"); // This message never appears
promise.complete();
}
else
promise.fail(result.cause());
});
return promise.future();
}
private Future<Void> deployHelper(String name)
{
Promise<Void> promise = Promise.promise();
vertx.deployVerticle(name, res -> {
if(res.failed()) {
System.out.println("[>] Failed to deploy verticle " + name);
promise.fail(res.cause());
} else {
System.out.println("[>] Deployed verticle " + name); // This message is printed for each verticle instance
promise.complete();
}
});
return promise.future();
}
Upvotes: 0
Views: 976
Reputation: 161
There are some conditions in the start method for the verticles. In some cases for a verticle instance the promise wasn't being completed.
@Override
public void start(Promise<Void> startPromise) {
/*
* Some async conditions logic
*/
startPromise.complete(); // Some promises never were completed
}
Upvotes: 1