Skip to content

Instantly share code, notes, and snippets.

@aesteve
Created January 19, 2016 08:57
Show Gist options
  • Save aesteve/4f828938a955af0a931f to your computer and use it in GitHub Desktop.
Save aesteve/4f828938a955af0a931f to your computer and use it in GitHub Desktop.
Use Future<Void> instead of timers
package com.github.vertx.node.example;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class MainVerticle extends AbstractVerticle {
private final Logger logger = LoggerFactory.getLogger(MainVerticle.class);
@Override
public void start(Future<Void> future) {
/** Count of services. */
final AtomicInteger serviceCount = new AtomicInteger();
/** List of verticles that we are starting. */
final List<AbstractVerticle> verticles = Arrays.asList(new HelloWorldVerticle(), new WebVerticle());
verticles.forEach(verticle -> vertx.deployVerticle(verticle, deployResponse -> {
if (deployResponse.failed()) {
Throwable cause = deployResponse.cause();
logger.error("Unable to deploy verticle " + verticle.getClass().getSimpleName(), cause);
future.fail(cause);
} else {
logger.info(verticle.getClass().getSimpleName() + " deployed");
if (serviceCount.incrementAndGet() == verticles.size()) {
future.complete();
}
}
}));
}
public static void main(final String... args) {
final Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new MainVerticle());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment