Example usage for io.vertx.core Vertx deployVerticle

List of usage examples for io.vertx.core Vertx deployVerticle

Introduction

In this page you can find the example usage for io.vertx.core Vertx deployVerticle.

Prototype

void deployVerticle(String name, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler);

Source Link

Document

Like #deployVerticle(String,Handler) but io.vertx.core.DeploymentOptions are provided to configure the deployment.

Usage

From source file:com.dinstone.vertx.starter.VertxHelper.java

License:Apache License

public static boolean deployVerticle(Vertx vertx, DeploymentOptions deployOptions, String verticleName)
        throws Exception {
    CompletableFuture<Boolean> future = new CompletableFuture<>();
    vertx.deployVerticle(verticleName, deployOptions, deployResponse -> {
        if (deployResponse.succeeded()) {
            LOG.info("verticle deployment is succeeded, {}:{}", verticleName, deployResponse.result());
            future.complete(true);//from  w w  w  .  j a  v a 2s  . c o m
        } else {
            LOG.error("verticle deployment is failed, {}:{}", verticleName, deployResponse.cause());
            future.completeExceptionally(deployResponse.cause());
        }
    });

    return future.get();
}

From source file:com.dinstone.vertx.starter.VertxHelper.java

License:Apache License

public static boolean deployVerticle(Vertx vertx, DeploymentOptions deployOptions, Verticle verticle)
        throws Exception {
    CompletableFuture<Boolean> future = new CompletableFuture<>();
    vertx.deployVerticle(verticle, deployOptions, deployResponse -> {
        if (deployResponse.succeeded()) {
            LOG.info("verticle deployment is succeeded, {}:{}", verticle.getClass().getName(),
                    deployResponse.result());
            future.complete(true);/*from  www .j a va  2 s.  co m*/
        } else {
            LOG.error("verticle deployment is failed, {}:{}", verticle.getClass().getName(),
                    deployResponse.cause());
            future.completeExceptionally(deployResponse.cause());
        }
    });

    return future.get();
}

From source file:com.hpe.sw.cms.verticle.Boot.java

License:Apache License

public static void main(String... args) throws IOException {
    String file = args[0];//from   w  w  w .  j a v a2  s .  c  o  m
    //    String file="dockerWeb/startup.json";
    String confStr = FileUtils.readFileToString(new File(file));
    JsonObject jsonConf = new JsonObject(confStr);
    DeploymentOptions deploymentOptions = new DeploymentOptions(jsonConf);
    VertxOptions options = new VertxOptions();
    options.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
    Vertx vertx = Vertx.vertx(options);
    vertx.deployVerticle(new Boot(), deploymentOptions, r -> {
        if (r.succeeded()) {
            LOG.info("Successfully deployed");
        } else {
            throw new RuntimeException(r.cause());
        }
    });
}

From source file:io.flowly.core.verticles.VerticleUtils.java

License:Open Source License

private static void deployVerticles(Stack<VerticleDeployment> verticleDeployments,
        Set<JsonObject> deployedVerticles, Vertx vertx, Future<Void> deployedFuture) {
    VerticleDeployment verticleDeployment = verticleDeployments.pop();

    vertx.deployVerticle(verticleDeployment.getName(), verticleDeployment.getDeploymentOptions(), d -> {
        if (d.succeeded()) {
            // Add the deployment id to the provided map.
            if (deployedVerticles != null) {
                JsonObject deployedVerticle = new JsonObject().put(ObjectKeys.ID, verticleDeployment.getId())
                        .put(ObjectKeys.DEPLOYMENT_ID, d.result());
                deployedVerticles.add(deployedVerticle);
            }/*from   w ww  . j  av  a2 s.com*/

            // Convey success if all verticle deployments are complete.
            if (verticleDeployments.empty()) {
                deployedFuture.complete();
            } else {
                deployVerticles(verticleDeployments, deployedVerticles, vertx, deployedFuture);
            }
        }
        // Fail fast - if any of the verticle deployment fails, stop further processing.
        else {
            deployedFuture.fail(d.cause());
        }
    });
}

From source file:io.github.bckfnn.actioner.Main.java

License:Apache License

public static void deploy(Class<? extends Verticle> verticle, String configName, String[] args,
        Handler<Vertx> result) throws Exception {
    if (args.length >= 1 && args[0].equals("stop")) {
        System.out.println("stopping");
        System.exit(1);//w w  w  .j av  a 2  s  .  co  m
    }

    System.setProperty("appConfig", configName);
    System.setProperty("vertx.logger-delegate-factory-class-name",
            "io.vertx.core.logging.SLF4JLogDelegateFactory");
    System.setProperty("vertx.disableFileCaching", "true");

    Config config = loadConfig();
    boolean develop = config.getBoolean("develop");

    checkEndorsed(config, args);

    VertxOptions vertxOptions = new VertxOptions();
    vertxOptions.setWorkerPoolSize(config.getInt("workerPoolSize"));

    if (config.hasPath("metrics")) {
        DropwizardMetricsOptions opt = new DropwizardMetricsOptions();
        opt.setEnabled(config.getBoolean("metrics.enabled"));
        opt.setRegistryName(config.getString("metrics.registryName"));
        opt.addMonitoredHttpServerUri(new Match().setValue(".*").setType(MatchType.REGEX));
        opt.addMonitoredHttpClientUri(new Match().setValue(".*").setType(MatchType.REGEX));
        opt.addMonitoredEventBusHandler(new Match().setValue(".*").setType(MatchType.REGEX));
        vertxOptions.setMetricsOptions(opt);
    }
    Vertx vertx = Vertx.vertx(vertxOptions);

    /*
    MetricRegistry registry = SharedMetricRegistries.getOrCreate("vertxRegistry");
            
    ConsoleReporter rep = ConsoleReporter.forRegistry(registry)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build();
    rep.start(10, TimeUnit.SECONDS);
     */
    /*
    System.out.println(vertx);
    MetricsService metricsService = MetricsService.create(vertx);
    JsonObject metrics = metricsService.getMetricsSnapshot(vertx);
    System.out.println("xx:" + metrics);
    System.out.println("xx:" + AbstractMetrics.class.getClassLoader());
     */
    DeploymentOptions opts = new DeploymentOptions();
    opts.setInstances(config.getInt("instances"));
    if (develop) {
        opts.setIsolatedClasses(config.getStringList("isolatedClasses"));
    }

    AtomicReference<String> deploymentId = new AtomicReference<>();

    Function<Handler<Vertx>, Void> deploy = h -> {
        if (develop) {
            opts.setIsolationGroup("ethics" + System.currentTimeMillis());
        }
        vertx.deployVerticle(verticle.getName(), opts, res -> {
            if (res.succeeded()) {
                deploymentId.set(res.result());
                h.handle(vertx);
            } else {
                res.cause().printStackTrace();
            }
        });
        return null;
    };

    deploy.apply(result);
    if (develop) {
        redeploy(() -> {
            vertx.undeploy(deploymentId.get(), r -> {
                deploy.apply(h -> {
                    System.err.println("redeployed!");
                });
            });
        });
    }
}

From source file:io.github.jdocker.serviceregistry.ServiceRegistry.java

License:Apache License

public static void main(String[] args) {
    // DeploymentOptions options = new DeploymentOptions().setInstances(1).setConfig(new JsonObject().put("host","localhost"));
    // Vertx.vertx().deployVerticle(ServiceRegistry.class.getServiceName(),options);

    VertxOptions vOpts = new VertxOptions();
    DeploymentOptions options = new DeploymentOptions().setInstances(1);
    vOpts.setClustered(true);/*ww w  .  j a  va  2s  . c  om*/
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(ServiceRegistry.class.getName(), options, handle -> {

            });
        }
    });
}

From source file:io.servicecomb.foundation.vertx.VertxUtils.java

License:Apache License

public static <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls,
        DeploymentOptions options) throws InterruptedException {
    Holder<Boolean> result = new Holder<>();

    CountDownLatch latch = new CountDownLatch(1);
    vertx.deployVerticle(cls.getName(), options, ar -> {
        result.value = ar.succeeded();/*from   www .  j a  va2 s  . c  om*/

        if (ar.failed()) {
            LOGGER.error("deploy vertx failed, cause ", ar.cause());
        }

        latch.countDown();
    });

    latch.await();

    return result.value;
}

From source file:io.silverware.microservices.providers.vertx.VertxMicroserviceProvider.java

License:Apache License

private void deployVerticles(Vertx vertx) {
    for (Map.Entry<String, DeploymentOptions> verticle : verticles.entrySet()) {

        String verticleName = verticle.getKey();
        DeploymentOptions deploymentOptions = verticle.getValue();

        //deploy verticle to vertx platform
        if (log.isDebugEnabled()) {
            log.debug("Deploying " + verticleName + " with options "
                    + VertxUtils.printDeploymentOptions(deploymentOptions));
        }//from   w w w.  ja  v  a 2  s  . c  o  m

        //asynchronous handler for monitoring of the deployment process
        vertx.deployVerticle(verticleName, deploymentOptions, res -> {
            if (res.succeeded()) {
                if (log.isDebugEnabled()) {
                    log.debug("Deployment of the verticle \"" + verticleName + "\" was successful.");
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Cannot deploy \"" + verticleName + "\", cause: " + res.cause());
                }
            }
        });
    }
}

From source file:org.apache.servicecomb.foundation.vertx.VertxUtils.java

License:Apache License

public static <VERTICLE extends Verticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls,
        DeploymentOptions options) throws InterruptedException {
    Holder<Boolean> result = new Holder<>();

    CountDownLatch latch = new CountDownLatch(1);
    vertx.deployVerticle(cls.getName(), options, ar -> {
        result.value = ar.succeeded();//from  w  w  w .j a va2 s  .c o m

        if (ar.failed()) {
            LOGGER.error("deploy vertx failed, cause ", ar.cause());
        }

        latch.countDown();
    });

    latch.await();

    return result.value;
}

From source file:org.schors.flibot.Main.java

License:Open Source License

public static void main(String[] args) throws IOException {

    String log4j = "log4j.properties";
    if (args.length > 1)
        log4j = args[1];//from   w w  w  .  ja  v a2  s . c  o m
    PropertyConfigurator.configure(log4j);

    JsonObject config = new JsonObject();
    if (System.getenv("flibot") != null) {
        //get from env
        config.put("name", System.getenv("name")).put("token", System.getenv("token"))
                .put("usetor", Boolean.valueOf(System.getenv("usetor")))
                .put("torhost", System.getenv("torhost")).put("torport", System.getenv("torport"))
                .put("admin", System.getenv("admin"));
    } else {
        //trying to read properties
        Properties p = new Properties();
        p.load(new FileInputStream("bot.ini"));
        config.put("name", p.getProperty("name")).put("token", p.getProperty("token"))
                .put("usetor", Boolean.valueOf(p.getProperty("usetor")))
                .put("torhost", p.getProperty("torhost")).put("torport", p.getProperty("torport"))
                .put("admin", p.getProperty("admin"));
    }

    VertxOptions options = new VertxOptions().setWorkerPoolSize(40);
    Vertx vertx = Vertx.vertx(options);

    DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(1).setConfig(config);
    vertx.deployVerticle(new DBManager(), deploymentOptions, event -> {
        if (event.succeeded()) {
            vertx.deployVerticle(new FliBot(), deploymentOptions);
        } else {
            event.cause().printStackTrace();
            vertx.close();
        }
    });
}