});
}
private void runVerticle(boolean zip, boolean module, String main, Args args) {
boolean clustered = args.map.get("-cluster") != null;
PlatformManager mgr;
if (clustered) {
log.info("Starting clustering...");
int clusterPort = args.getInt("-cluster-port");
if (clusterPort == -1) {
// Default to zero - this means choose an ephemeral port
clusterPort = 0;
}
String clusterHost = args.map.get("-cluster-host");
if (clusterHost == null) {
clusterHost = getDefaultAddress();
if (clusterHost == null) {
log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host");
return;
} else {
log.info("No cluster-host specified so using address " + clusterHost);
}
}
mgr = createPM(clusterPort, clusterHost);
} else {
mgr = createPM();
}
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 configFile = args.map.get("-conf");
JsonObject conf;
if (configFile != null) {
try (Scanner scanner = new Scanner(new File(configFile)).useDelimiter("\\A")){
String sconf = scanner.next();
try {
conf = new JsonObject(sconf);
} catch (DecodeException e) {
log.error("Configuration file does not contain a valid JSON object");
return;
}
} catch (FileNotFoundException e) {
log.error("Config file " + configFile + " does not exist");
return;
}
} else {
conf = null;
}
Handler<AsyncResult<String>> doneHandler = new Handler<AsyncResult<String>>() {
public void handle(AsyncResult<String> res) {
if (res.failed()) {
// Failed to deploy
unblock();
}
}
};
if (zip) {
mgr.deployModuleFromZip(main, conf, instances, createLoggingHandler("Successfully deployed module from zip", doneHandler));
} else if (module) {
mgr.deployModule(main, conf, instances, createLoggingHandler("Successfully deployed module", doneHandler));
} else {
boolean worker = args.map.get("-worker") != null;
String cp = args.map.get("-cp");
if (cp == null) {
cp = ".";
}
// Convert to URL[]
String[] parts;
if (cp.contains(CP_SEPARATOR)) {
parts = cp.split(CP_SEPARATOR);
} else {
parts = new String[] { cp };
}
int index = 0;
final URL[] urls = new URL[parts.length];
for (String part: parts) {
try {
URL url = new File(part).toURI().toURL();
urls[index++] = url;
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid path " + part + " in cp " + cp) ;
}
}
String includes = args.map.get("-includes");
if (worker) {
mgr.deployWorkerVerticle(false, main, conf, urls, instances, includes,
createLoggingHandler("Successfully deployed worker verticle", doneHandler));
} else {
mgr.deployVerticle(main, conf, urls, instances, includes, createLoggingHandler("Successfully deployed verticle", doneHandler));
}
}
addShutdownHook(mgr);
block();