Example usage for io.vertx.core VertxOptions VertxOptions

List of usage examples for io.vertx.core VertxOptions VertxOptions

Introduction

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

Prototype

public VertxOptions() 

Source Link

Document

Default constructor

Usage

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

/**
 * @param args the command line arguments
 *///w w w. java  2s.co  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.consol.citrus.vertx.factory.AbstractVertxInstanceFactory.java

License:Apache License

/**
 * Creates new Vert.x instance with default factory. Subclasses may overwrite this
 * method in order to provide special Vert.x instance.
 * @return/*  ww  w  .  ja  v  a  2 s  . c  o  m*/
 */
protected Vertx createVertx(VertxEndpointConfiguration endpointConfiguration) {
    final Vertx[] vertx = new Vertx[1];
    final Future loading = new FutureFactoryImpl().future();

    Handler<AsyncResult<Vertx>> asyncLoadingHandler = new Handler<AsyncResult<Vertx>>() {
        @Override
        public void handle(AsyncResult<Vertx> event) {
            vertx[0] = event.result();
            loading.complete();
            log.info("Vert.x instance started");
        }
    };

    if (endpointConfiguration.getPort() > 0) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(),
                    endpointConfiguration.getPort()));
        }
        VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setClusterPort(endpointConfiguration.getPort());
        vertxOptions.setClusterHost(endpointConfiguration.getHost());
        vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler);
    } else {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(),
                    0L));
        }
        VertxOptions vertxOptions = new VertxOptions();
        vertxOptions.setClusterPort(0);
        vertxOptions.setClusterHost(endpointConfiguration.getHost());
        vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler);
    }

    // Wait for full loading
    while (!loading.isComplete()) {
        try {
            log.debug("Waiting for Vert.x instance to startup");
            Thread.sleep(250L);
        } catch (InterruptedException e) {
            log.warn("Interrupted while waiting for Vert.x instance startup", e);
        }
    }

    return vertx[0];
}

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);//w ww.j  a v  a2 s  .com

    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 runJava(String prefix, Class clazz, boolean clustered, String confFile) {
    runJava(prefix, clazz, new VertxOptions().setClustered(clustered).setClusterManager(mgr), confFile);
}

From source file:com.deblox.DebloxRunner.java

License:Apache License

public static void runJava(String prefix, Class clazz, boolean clustered) {

    runJava(prefix, clazz, new VertxOptions().setClustered(clustered).setClusterManager(mgr), "conf.json");
}

From source file:com.deblox.DebloxRunner.java

License:Apache License

public static void run(String runDir, String verticleID, boolean clustered) {
    run(runDir, verticleID, new VertxOptions().setClustered(clustered).setClusterManager(mgr), "/conf.json");
}

From source file:com.dinstone.vertx.starter.config.VertxAutoConfiguration.java

License:Apache License

private VertxOptions loadVertxOptions() {
    VertxOptions vertxOptions = new VertxOptions();
    int blockedCheckInterval = vertxProperties.getBlockedThreadCheckInterval();
    if (blockedCheckInterval > 0) {
        vertxOptions.setBlockedThreadCheckInterval(blockedCheckInterval);
    }//from w  w w  . ja v a 2s . c  o  m

    if (vertxProperties.getEventLoopPoolSize() > 0) {
        vertxOptions.setEventLoopPoolSize(vertxProperties.getEventLoopPoolSize());
    }

    if (vertxProperties.getWorkerPoolSize() > 0) {
        vertxOptions.setWorkerPoolSize(vertxProperties.getWorkerPoolSize());
    }

    return vertxOptions;
}

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 ww  w  .j a  v  a  2s.  com*/
    //    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:com.jtpark.example_vertx_amqp.util.Runner.java

License:Apache License

public static void runExample(Class<?> clazz) {
    runExample(AMQP_BRIDGE_EXAMPLES_DIR_JAVA, clazz, new VertxOptions().setClustered(false), null);
}

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 w ww  .  j a va 2s  .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);
    }
}