Search in sources :

Example 1 with Args

use of io.vertx.core.impl.Args in project vert.x by eclipse.

the class Starter method main.

public static void main(String[] sargs) {
    Args args = new Args(sargs);
    String extraCP = args.map.get("-cp");
    if (extraCP != null) {
        // If an extra CP is specified (e.g. to provide cp to a jar or cluster.xml) we must create a new classloader
        // and run the starter using that so it's visible to the rest of the code
        String[] parts = extraCP.split(PATH_SEP);
        URL[] urls = new URL[parts.length];
        for (int p = 0; p < parts.length; p++) {
            String part = parts[p];
            File file = new File(part);
            try {
                URL url = file.toURI().toURL();
                urls[p] = url;
            } catch (MalformedURLException e) {
                throw new IllegalStateException(e);
            }
        }
        ClassLoader icl = new URLClassLoader(urls, Starter.class.getClassLoader());
        ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(icl);
        try {
            Class<?> clazz = icl.loadClass(Starter.class.getName());
            Object instance = clazz.newInstance();
            Method run = clazz.getMethod("run", Args.class, String[].class);
            run.invoke(instance, args, sargs);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldTCCL);
        }
    } else {
        // No extra CP, just invoke directly
        new Starter().run(args, sargs);
    }
}
Also used : Args(io.vertx.core.impl.Args) Method(java.lang.reflect.Method) DecodeException(io.vertx.core.json.DecodeException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JsonObject(io.vertx.core.json.JsonObject) File(java.io.File)

Example 2 with Args

use of io.vertx.core.impl.Args in project vert.x by eclipse.

the class Starter method runVerticle.

private void runVerticle(String main, Args args) {
    boolean ha = args.map.get("-ha") != null;
    boolean clustered = args.map.get("-cluster") != null || ha;
    Vertx vertx = startVertx(clustered, ha, args);
    if (vertx == null) {
        // Throwable should have been logged at this point
        return;
    }
    String sinstances = args.map.get("-instances");
    int instances;
    if (sinstances != null) {
        try {
            instances = Integer.parseInt(sinstances);
            if (instances != -1 && instances < 1) {
                log.error("Invalid number of instances");
                displaySyntax();
                return;
            }
        } catch (NumberFormatException e) {
            displaySyntax();
            return;
        }
    } else {
        instances = 1;
    }
    String confArg = args.map.get("-conf");
    JsonObject conf;
    if (confArg != null) {
        try (Scanner scanner = new Scanner(new File(confArg)).useDelimiter("\\A")) {
            String sconf = scanner.next();
            try {
                conf = new JsonObject(sconf);
            } catch (DecodeException e) {
                log.error("Configuration file " + sconf + " does not contain a valid JSON object");
                return;
            }
        } catch (FileNotFoundException e) {
            try {
                conf = new JsonObject(confArg);
            } catch (DecodeException e2) {
                log.error("-conf option does not point to a file and is not valid JSON: " + confArg);
                return;
            }
        }
    } else {
        conf = null;
    }
    boolean worker = args.map.get("-worker") != null;
    String message = (worker) ? "deploying worker verticle" : "deploying verticle";
    deploymentOptions = new DeploymentOptions();
    configureFromSystemProperties(deploymentOptions, DEPLOYMENT_OPTIONS_PROP_PREFIX);
    deploymentOptions.setConfig(conf).setWorker(worker).setHa(ha).setInstances(instances);
    beforeDeployingVerticle(deploymentOptions);
    vertx.deployVerticle(main, deploymentOptions, createLoggingHandler(message, res -> {
        if (res.failed()) {
            handleDeployFailed();
        }
    }));
}
Also used : Manifest(java.util.jar.Manifest) java.util(java.util) DecodeException(io.vertx.core.json.DecodeException) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Attributes(java.util.jar.Attributes) LoggerFactory(io.vertx.core.logging.LoggerFactory) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Args(io.vertx.core.impl.Args) java.net(java.net) MetricsOptions(io.vertx.core.metrics.MetricsOptions) JsonObject(io.vertx.core.json.JsonObject) Logger(io.vertx.core.logging.Logger) Method(java.lang.reflect.Method) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) JsonObject(io.vertx.core.json.JsonObject) File(java.io.File) DecodeException(io.vertx.core.json.DecodeException)

Example 3 with Args

use of io.vertx.core.impl.Args in project vert.x by eclipse.

the class Starter method run.

protected void run(String commandLine) {
    String[] sargs = commandLine.split(" ");
    Args args = new Args(sargs);
    run(args, sargs);
}
Also used : Args(io.vertx.core.impl.Args)

Aggregations

Args (io.vertx.core.impl.Args)3 DecodeException (io.vertx.core.json.DecodeException)2 JsonObject (io.vertx.core.json.JsonObject)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1 MetricsOptions (io.vertx.core.metrics.MetricsOptions)1 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)1 InputStream (java.io.InputStream)1 java.net (java.net)1 java.util (java.util)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Attributes (java.util.jar.Attributes)1 Manifest (java.util.jar.Manifest)1