String initialDomainConfig = null;
String hostConfig = null;
String initialHostConfig = null;
RunningMode initialRunningMode = RunningMode.NORMAL;
Map<String, String> hostSystemProperties = getHostSystemProperties();
ProductConfig productConfig;
String modulePath = null;
final int argsLength = args.length;
for (int i = 0; i < argsLength; i++) {
final String arg = args[i];
try {
if (CommandLineConstants.PROPERTIES.equals(arg) || CommandLineConstants.OLD_PROPERTIES.equals(arg)
|| CommandLineConstants.SHORT_PROPERTIES.equals(arg)) {
// Set system properties from url/file
if (!processProperties(arg, args[++i], hostSystemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec, hostSystemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.SHORT_PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.SHORT_PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec, hostSystemProperties)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.OLD_PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.OLD_PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec, hostSystemProperties)) {
return null;
}
} else if (CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT.equals(arg)) {
final String port = args[++i];
try {
pmPort = Integer.valueOf(port);
} catch (NumberFormatException e) {
System.err.println(MESSAGES.invalidValue(CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT, "Integer", port, usageNote()));
return null;
}
} else if (arg.startsWith(CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT)) {
String val = parseValue(arg, CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT);
if (val == null) {
return null;
}
final Integer port = parsePort(val, CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT);
if (port == null) {
return null;
}
pmPort = port;
} else if (CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR.equals(arg)) {
final String addr = args[++i];
try {
pmAddress = InetAddress.getByName(addr);
} catch (UnknownHostException e) {
System.err.println(MESSAGES.unknownHostValue(CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR, addr, usageNote()));
return null;
}
} else if (arg.startsWith(CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR)) {
final String val = parseValue(arg, CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR);
if (val == null) {
return null;
}
final InetAddress addr = parseAddress(val, arg);
if (addr == null) {
return null;
}
pmAddress = addr;
} else if (pcSocketConfig.processPCSocketConfigArgument(arg, args, i)) {
if (pcSocketConfig.isParseFailed()) {
return null;
}
i += pcSocketConfig.getArgIncrement();
} else if (CommandLineConstants.RESTART_HOST_CONTROLLER.equals(arg)) {
isRestart = true;
} else if (CommandLineConstants.BACKUP_DC.equals(arg) || CommandLineConstants.OLD_BACKUP_DC.equals(arg)) {
backupDomainFiles = true;
} else if (CommandLineConstants.CACHED_DC.equals(arg) || CommandLineConstants.OLD_CACHED_DC.equals(arg)) {
cachedDc = true;
} else if(CommandLineConstants.DEFAULT_JVM.equals(arg) || CommandLineConstants.OLD_DEFAULT_JVM.equals(arg)) {
defaultJVM = checkValueIsNotAnArg(arg, args[++i]);
if (defaultJVM == null) {
return null;
}
} else if (CommandLineConstants.DOMAIN_CONFIG.equals(arg)
|| CommandLineConstants.SHORT_DOMAIN_CONFIG.equals(arg)
|| CommandLineConstants.OLD_DOMAIN_CONFIG.equals(arg)) {
domainConfig = checkValueIsNotAnArg(arg, args[++i]);
if (domainConfig == null) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.DOMAIN_CONFIG)) {
String val = parseValue(arg, CommandLineConstants.DOMAIN_CONFIG);
if (val == null) {
return null;
}
domainConfig = val;
} else if (arg.startsWith(CommandLineConstants.SHORT_DOMAIN_CONFIG)) {
String val = parseValue(arg, CommandLineConstants.SHORT_DOMAIN_CONFIG);
if (val == null) {
return null;
}
domainConfig = val;
} else if (arg.startsWith(CommandLineConstants.OLD_DOMAIN_CONFIG)) {
String val = parseValue(arg, CommandLineConstants.OLD_DOMAIN_CONFIG);
if (val == null) {
return null;
}
domainConfig = val;
} else if (arg.startsWith(CommandLineConstants.READ_ONLY_DOMAIN_CONFIG)) {
initialDomainConfig = parseValue(arg, CommandLineConstants.READ_ONLY_DOMAIN_CONFIG);
if (initialDomainConfig == null) {
return null;
}
} else if (CommandLineConstants.HOST_CONFIG.equals(arg) || CommandLineConstants.OLD_HOST_CONFIG.equals(arg)) {
hostConfig = checkValueIsNotAnArg(arg, args[++i]);
if (hostConfig == null) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.HOST_CONFIG)) {
String val = parseValue(arg, CommandLineConstants.HOST_CONFIG);
if (val == null) {
return null;
}
hostConfig = val;
} else if (arg.startsWith(CommandLineConstants.OLD_HOST_CONFIG)) {
String val = parseValue(arg, CommandLineConstants.OLD_HOST_CONFIG);
if (val == null) {
return null;
}
hostConfig = val;
} else if (arg.startsWith(CommandLineConstants.READ_ONLY_HOST_CONFIG)) {
initialHostConfig = parseValue(arg, CommandLineConstants.READ_ONLY_HOST_CONFIG);
if (initialHostConfig == null) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.MASTER_ADDRESS)) {
int idx = arg.indexOf('=');
if (idx == arg.length() - 1) {
System.err.println(MESSAGES.argumentExpected(arg, usageNote()));
return null;
}
String value = idx > -1 ? arg.substring(idx + 1) : checkValueIsNotAnArg(arg, args[++i]);
if (value == null) {
return null;
}
hostSystemProperties.put(HostControllerEnvironment.JBOSS_DOMAIN_MASTER_ADDRESS, value);
SecurityActions.setSystemProperty(HostControllerEnvironment.JBOSS_DOMAIN_MASTER_ADDRESS, value);
} else if (arg.startsWith(CommandLineConstants.MASTER_PORT)) {
int idx = arg.indexOf('=');
if (idx == arg.length() - 1) {
System.err.println(MESSAGES.argumentExpected(arg, usageNote()));
return null;
}
String value = idx > -1 ? arg.substring(idx + 1) : args[++i];
final Integer port = parsePort(value, CommandLineConstants.MASTER_PORT);
if (port == null) {
return null;
}
hostSystemProperties.put(HostControllerEnvironment.JBOSS_DOMAIN_MASTER_PORT, value);
SecurityActions.setSystemProperty(HostControllerEnvironment.JBOSS_DOMAIN_MASTER_PORT, value);
} else if (CommandLineConstants.ADMIN_ONLY.equals(arg)) {
initialRunningMode = RunningMode.ADMIN_ONLY;
} else if (arg.startsWith(CommandLineConstants.SYS_PROP)) {
// set a system property
String name, value;
int idx = arg.indexOf("=");
if (idx == -1) {
name = arg.substring(2);
value = "true";
} else {
name = arg.substring(2, idx);
value = arg.substring(idx + 1, arg.length());
}
SecurityActions.setSystemProperty(name, value);
hostSystemProperties.put(name, value);
} else if (arg.startsWith(CommandLineConstants.PUBLIC_BIND_ADDRESS)) {
int idx = arg.indexOf('=');
if (idx == arg.length() - 1) {
System.err.println(MESSAGES.argumentExpected(arg, usageNote()));
return null;
}
String value = idx > -1 ? arg.substring(idx + 1) : checkValueIsNotAnArg(arg, args[++i]);
if (value == null) {
return null;
}
String propertyName;
if (idx < 0) {
// -b xxx -bmanagement xxx
propertyName = arg.length() == 2 ? HostControllerEnvironment.JBOSS_BIND_ADDRESS : HostControllerEnvironment.JBOSS_BIND_ADDRESS_PREFIX + arg.substring(2);
} else if (idx == 2) {
// -b=xxx
propertyName = HostControllerEnvironment.JBOSS_BIND_ADDRESS;
} else {
// -bmanagement=xxx
propertyName = HostControllerEnvironment.JBOSS_BIND_ADDRESS_PREFIX + arg.substring(2, idx);
}
hostSystemProperties.put(propertyName, value);
SecurityActions.setSystemProperty(propertyName, value);
} else if (arg.startsWith(CommandLineConstants.DEFAULT_MULTICAST_ADDRESS)) {
int idx = arg.indexOf('=');
if (idx == arg.length() - 1) {
System.err.println(MESSAGES.argumentExpected(arg, usageNote()));
return null;
}
String value = idx > -1 ? arg.substring(idx + 1) : checkValueIsNotAnArg(arg, args[++i]);
if (value == null) {
return null;
}
hostSystemProperties.put(HostControllerEnvironment.JBOSS_DEFAULT_MULTICAST_ADDRESS, value);
SecurityActions.setSystemProperty(HostControllerEnvironment.JBOSS_DEFAULT_MULTICAST_ADDRESS, value);
} else if (arg.equals(CommandLineConstants.MODULE_PATH)) {
modulePath = checkValueIsNotAnArg(arg, args[++i]);
if (modulePath == null) {
return null;
}
} else {
System.err.println(MESSAGES.invalidOption(arg, usageNote()));
return null;
}
} catch (IndexOutOfBoundsException e) {
System.err.println(MESSAGES.argumentExpected(arg, usageNote()));
return null;
}
}
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(HostControllerEnvironment.HOME_DIR), hostSystemProperties);
return new HostControllerEnvironment(hostSystemProperties, isRestart, modulePath, pmAddress, pmPort,
pcSocketConfig.getBindAddress(), pcSocketConfig.getBindPort(), defaultJVM,
domainConfig, initialDomainConfig, hostConfig, initialHostConfig, initialRunningMode, backupDomainFiles, cachedDc, productConfig);
}