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

Future<String> deployVerticle(String name, DeploymentOptions options);

Source Link

Document

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

Usage

From source file:com.ab.main.MainApp.java

/**
 * @param args the command line arguments
 *//*from  w ww . ja  v a  2s  .  c o  m*/
public static void main(String[] args) {

    System.out.println("Vertx webserver started at port 8080");

    Config hazelcastConfig = new Config();

    ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);

    VertxOptions options = new VertxOptions().setClusterManager(mgr);
    int port = 8081;
    DeploymentOptions depOptions = new DeploymentOptions().setConfig(new JsonObject().put("http.port", port));
    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            vertx.deployVerticle(new MainVerticle(), depOptions);
            System.out.println("Server started at port " + port + "...");
        } else {
            // failed!
        }
    });
}

From source file:com.cisco.ef.VertxMain.java

public static void main(final String... args) throws Exception {
    final ManagedServiceBuilder managedServiceBuilder = createManagedServiceBuilder();

    final CountDownLatch latch = new CountDownLatch(1);
    final Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(new VertxMain(managedServiceBuilder), result -> {
        if (result.succeeded()) {
            System.out.println("Deployment id is: " + result.result());
        } else {// www.j a v a2s. c om
            System.out.println("Deployment failed!");
            result.cause().printStackTrace();
        }
        latch.countDown();
    });

    latch.await(5, TimeUnit.SECONDS);

    logger.info("QBit and Vertx are open for e-Busbies");
}

From source file:com.ddp.SimpleREST.java

License:Open Source License

public static void main(String argv[]) {

    VertxOptions options = new VertxOptions().setBlockedThreadCheckInterval(200000000);
    options.setClustered(true);//from   w w  w  .j a  v  a  2s.  c om

    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            final JsonObject js = new JsonObject();
            vertx.fileSystem().readFile("app-conf.json", result -> {
                if (result.succeeded()) {
                    Buffer buff = result.result();
                    js.mergeIn(new JsonObject(buff.toString()));
                    initConfig(js);
                    DeploymentOptions deploymentOptions = new DeploymentOptions().setConfig(js)
                            .setMaxWorkerExecuteTime(5000).setWorker(true).setWorkerPoolSize(5);
                    vertx.deployVerticle(SimpleREST.class.getName(), deploymentOptions);
                } else {
                    System.err.println("Oh oh ..." + result.cause());
                }
            });

        }
    });
}

From source file:com.deblox.DebloxRunner.java

License:Apache License

public static void run(String runDir, String verticleID, VertxOptions options, String confFile) {
    logger.info("Booting");
    //    System.setProperty("vertx.cwd", runDir + "/");
    Consumer<Vertx> runner = vertx -> {
        try {//from w w  w .  j  a  va2 s.  co  m
            JsonObject config = Util.loadConfig(confFile);
            // put config inside a config tag to solve issue between running as fatJar and running main[]
            DeploymentOptions deploymentOptions = new DeploymentOptions(new JsonObject().put("config", config));
            vertx.deployVerticle(verticleID, deploymentOptions);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    };
    if (options.isClustered()) {
        Vertx.clusteredVertx(options, res -> {
            if (res.succeeded()) {
                Vertx vertx = res.result();
                runner.accept(vertx);
            } else {
                res.cause().printStackTrace();
            }
        });
    } else {
        Vertx vertx = Vertx.vertx(options);
        runner.accept(vertx);
    }
}

From source file:com.jtpark.example_vertx_amqp.util.Runner.java

License:Apache License

public static void runExample(String exampleDir, String verticleID, VertxOptions options,
        DeploymentOptions deploymentOptions) {
    if (options == null) {
        // Default parameter
        options = new VertxOptions();
    }//from   www . j  a  va2 s.c  om
    // Smart cwd detection

    // Based on the current directory (.) and the desired directory
    // (exampleDir), we try to compute the vertx.cwd
    // directory:
    try {
        // We need to use the canonical file. Without the file name is .
        File current = new File(".").getCanonicalFile();
        if (exampleDir.startsWith(current.getName()) && !exampleDir.equals(current.getName())) {
            exampleDir = exampleDir.substring(current.getName().length() + 1);
        }
    } catch (IOException e) {
        // Ignore it.
    }

    System.setProperty("vertx.cwd", exampleDir);
    Consumer<Vertx> runner = vertx -> {
        try {
            if (deploymentOptions != null) {
                vertx.deployVerticle(verticleID, deploymentOptions);
            } else {
                vertx.deployVerticle(verticleID);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    };
    if (options.isClustered()) {
        Vertx.clusteredVertx(options, res -> {
            if (res.succeeded()) {
                Vertx vertx = res.result();
                runner.accept(vertx);
            } else {
                res.cause().printStackTrace();
            }
        });
    } else {
        Vertx vertx = Vertx.vertx(options);
        runner.accept(vertx);
    }
}

From source file:com.mammatustech.todo.VertxTodoServiceVerticle.java

public static void main(final String... args) throws Exception {
    final ManagedServiceBuilder managedServiceBuilder = createManagedServiceBuilder();

    final CountDownLatch latch = new CountDownLatch(1);
    final Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(new VertxTodoServiceVerticle(managedServiceBuilder), result -> {
        if (result.succeeded()) {
            System.out.println("Deployment id is: " + result.result());
        } else {/* www  . java 2 s .  c  o  m*/
            System.out.println("Deployment failed!");
            result.cause().printStackTrace();
        }
        latch.countDown();
    });

    latch.await(5, TimeUnit.SECONDS);

    System.out.println("QBit and Vertx are open for e-Busbies");
}

From source file:com.sagalasan.swivel.control.Controller.java

License:Apache License

@Inject
public void setVertx(Vertx vertx) {
    this.vertx = vertx;
    vertx.deployVerticle(this, res -> {
        deploymentID = res.result();/*from w w  w.j a v  a2 s  . c  om*/
        System.out.println(this.getClass().getSimpleName() + " deployed");
        vertx.eventBus().send(CurrentTimeService.RECEIVE, new Ping(), reply -> {
            if (reply.succeeded()) {
                System.out.println("Reply successful");
                Time time = (Time) reply.result().body();
                onCurrentTimeReceived(time.getTime());
            }
        });
        onDeploy();
    });
}

From source file:de.braintags.netrelay.impl.NetRelayExt_InternalSettings.java

License:Open Source License

public static NetRelayExt_InternalSettings getInstance(Vertx vertx, TestContext context,
        NetRelayBaseTest baseTest) {//ww w .ja v a  2  s  .c o m
    if (netRelay == null) {
        netRelay = new NetRelayExt_InternalSettings();
        LOGGER.info("init NetRelay");
        Async async = context.async();
        ErrorObject err = new ErrorObject<>(null);
        baseTest.modifySettings(context, netRelay.settings);
        vertx.deployVerticle(netRelay, result -> {
            if (result.failed()) {
                err.setThrowable(result.cause());
                async.complete();
            } else {
                async.complete();
            }
        });
        async.awaitSuccess();
        if (err.isError()) {
            throw err.getRuntimeException();
        }
    }
    return netRelay;
}

From source file:demo.Main.java

License:Apache License

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();

    vertx.deployVerticle(SimpleVerticle.class.getName(),
            new DeploymentOptions().setConfig(new JsonObject().put("message", "bonjour")));
}

From source file:examples.CoreExamples.java

License:Open Source License

public void example7_1(Vertx vertx) {
    DeploymentOptions options = new DeploymentOptions().setWorker(true);
    vertx.deployVerticle("com.mycompany.MyOrderProcessorVerticle", options);
}