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);
}
}
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();
}
}));
}
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);
}
Aggregations