Search in sources :

Example 1 with GeneratorService

use of io.vertx.starter.service.GeneratorService in project vertx-starter by vert-x3.

the class GeneratorVerticle method start.

@Override
public void start(Promise<Void> startPromise) {
    vertx.fileSystem().readFile("keywords", kar -> {
        if (kar.succeeded()) {
            Set<String> keywords = NEWLINE_REGEX.splitAsStream(kar.result().toString()).map(String::trim).filter(s -> !s.isEmpty()).collect(toSet());
            generatorService = new GeneratorService(vertx, keywords);
            MessageConsumer<VertxProject> consumer = vertx.eventBus().consumer(Topics.PROJECT_REQUESTED);
            consumer.handler(this::onProjectRequested).completionHandler(ar -> {
                if (ar.succeeded()) {
                    log.info("\n----------------------------------------------------------\n\t" + "{} is running!\n" + "----------------------------------------------------------", GeneratorVerticle.class.getSimpleName());
                    startPromise.complete();
                } else {
                    startPromise.fail(ar.cause());
                }
            });
        } else {
            startPromise.fail(kar.cause());
        }
    });
}
Also used : Topics(io.vertx.starter.config.Topics) Logger(org.slf4j.Logger) AbstractVerticle(io.vertx.core.AbstractVerticle) Promise(io.vertx.core.Promise) LoggerFactory(org.slf4j.LoggerFactory) Message(io.vertx.core.eventbus.Message) Set(java.util.Set) GeneratorService(io.vertx.starter.service.GeneratorService) Pattern(java.util.regex.Pattern) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) VertxProject(io.vertx.starter.model.VertxProject) Collectors.toSet(java.util.stream.Collectors.toSet) VertxProject(io.vertx.starter.model.VertxProject) GeneratorService(io.vertx.starter.service.GeneratorService)

Aggregations

AbstractVerticle (io.vertx.core.AbstractVerticle)1 Promise (io.vertx.core.Promise)1 Message (io.vertx.core.eventbus.Message)1 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)1 Topics (io.vertx.starter.config.Topics)1 VertxProject (io.vertx.starter.model.VertxProject)1 GeneratorService (io.vertx.starter.service.GeneratorService)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1