public static void main(String args[]) { String worldName = System.getProperty("multiverse.worldname"); Properties properties = InitLogAndPid.initLogAndPid(args, worldName, null); System.err.println("Multiverse server version " + ServerVersion.getVersionString()); List<String> agentNames = new LinkedList<String>(); LongOpt[] longopts = new LongOpt[2]; longopts[0] = new LongOpt("pid", LongOpt.REQUIRED_ARGUMENT, null, 2); longopts[1] = new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 3); Getopt opt = new Getopt("DomainServer", args, "a:m:t:p:P:", longopts); int c; int port = DEFAULT_PORT; String portStr = properties.getProperty("multiverse.msgsvr_port"); if (portStr != null) port = Integer.parseInt(portStr); PluginStartGroup pluginStartGroup = new PluginStartGroup(); while ((c = opt.getopt()) != -1) { switch (c) { case 'a': agentNames.add(opt.getOptarg()); break; case 't': case 'm': // ignore RuntimeMarshalling flags opt.getOptarg(); break; case 'p': String pluginSpec = opt.getOptarg(); String[] pluginDef = pluginSpec.split(",", 2); if (pluginDef.length != 2) { System.err.println("Invalid plugin spec format: " + pluginSpec); Log.error("Invalid plugin spec format: " + pluginSpec); System.exit(1); } int expected = Integer.parseInt(pluginDef[1]); pluginStartGroup.add(pluginDef[0], expected); break; case '?': System.exit(1); break; case 'P': break; case 2: // ignore --pid opt.getOptarg(); break; // port case 3: String arg = opt.getOptarg(); port = Integer.parseInt(arg); break; default: break; } } String svrName = System.getProperty("multiverse.loggername"); String runDir = System.getProperty("multiverse.rundir"); // Windows non-Cygwin only - save process ID for status script if (System.getProperty("os.name").contains("Windows") && svrName != null && runDir != null) { saveProcessID(svrName, runDir); } // parse command-line options domainServer = new DomainServer(port); domainServer.setAgentNames(agentNames); domainServer.setWorldName(worldName); domainServer.start(); pluginStartGroup.prepareDependencies(properties, worldName); domainServer.addPluginStartGroup(pluginStartGroup); pluginStartGroup.pluginAvailable("Domain", "Domain"); String timeoutStr = properties.getProperty("multiverse.startup_timeout"); int timeout = 120; if (timeoutStr != null) { timeout = Integer.parseInt(timeoutStr); } ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); ScheduledFuture<?> timeoutHandler = scheduler.schedule(new TimeoutRunnable(timeout), timeout, TimeUnit.SECONDS); javax.crypto.SecretKey domainKey = SecureTokenUtil.generateDomainKey(); // XXX Use a random keyID for now. Ideally, this would be semi-unique. long keyId = new Random().nextLong(); encodedDomainKey = Base64.encodeBytes(SecureTokenUtil.encodeDomainKey(keyId, domainKey)); Log.debug("generated domain key: " + encodedDomainKey); try { pluginStartGroup.awaitDependency("Domain"); timeoutHandler.cancel(false); String availableMessage = properties.getProperty("multiverse.world_available_message"); String availableFile = properties.getProperty("multiverse.world_available_file"); if (availableFile != null) touchFile(FileUtil.expandFileName(availableFile)); if (availableMessage != null) System.err.println("\n" + availableMessage); while (true) { Thread.sleep(10000000); } } catch (Exception ex) { Log.exception("DomainServer.main", ex); } }