/
Main.java
647 lines (592 loc) · 27.9 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.host.controller;
import static org.jboss.as.host.controller.HostControllerMessages.MESSAGES;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.interfaces.InetAddressUtil;
import org.jboss.as.process.CommandLineConstants;
import org.jboss.as.process.ExitCodes;
import org.jboss.as.process.protocol.StreamUtils;
import org.jboss.as.version.ProductConfig;
import org.jboss.logging.MDC;
import org.jboss.logmanager.Level;
import org.jboss.logmanager.Logger;
import org.jboss.logmanager.handlers.ConsoleHandler;
import org.jboss.modules.Module;
import org.jboss.stdio.LoggingOutputStream;
import org.jboss.stdio.NullInputStream;
import org.jboss.stdio.SimpleStdioContextSelector;
import org.jboss.stdio.StdioContext;
/**
* The main-class entry point for the host controller process.
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
* @author <a href="mailto:kkhan@redhat.com">Kabir Khan</a>
* @author Brian Stansberry
*/
public final class Main {
/**
* The main method.
*
* @param args the command-line arguments
*/
public static void main(String[] args) throws IOException {
MDC.put("process", "host controller");
// Grab copies of our streams.
final InputStream in = System.in;
//final PrintStream out = System.out;
//final PrintStream err = System.err;
final byte[] authKey = new byte[16];
try {
StreamUtils.readFully(System.in, authKey);
} catch (IOException e) {
System.err.println(MESSAGES.failedToReadAuthenticationKey(e));
fail();
return;
}
// Make sure our original stdio is properly captured.
try {
Class.forName(ConsoleHandler.class.getName(), true, ConsoleHandler.class.getClassLoader());
} catch (Throwable ignored) {
}
// Install JBoss Stdio to avoid any nasty crosstalk.
StdioContext.install();
final StdioContext context = StdioContext.create(
new NullInputStream(),
new LoggingOutputStream(Logger.getLogger("stdout"), Level.INFO),
new LoggingOutputStream(Logger.getLogger("stderr"), Level.ERROR)
);
StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));
create(args, authKey);
while (in.read() != -1) {}
exit();
}
private Main() {
}
private static HostControllerBootstrap create(String[] args, final byte[] authCode) {
Main main = new Main();
return main.boot(args, authCode);
}
private HostControllerBootstrap boot(String[] args, final byte[] authCode) {
try {
final HostControllerEnvironment config = determineEnvironment(args);
if (config == null) {
abort();
return null;
} else {
try {
final HostControllerBootstrap hc = new HostControllerBootstrap(config, authCode);
hc.bootstrap();
return hc;
} catch(Throwable t) {
abort(t);
return null;
}
}
} catch (Throwable t) {
abort(t);
return null;
}
}
/**
* Terminates process with an exit code that will trigger shutdown of the process controller as well if there
* are no running servers. JVM shuts down with {@link ExitCodes#HOST_CONTROLLER_ABORT_EXIT_CODE}.
* @param t the throwable that triggered abort
*/
private static void abort(Throwable t) {
try {
if (t != null) {
t.printStackTrace();
}
} finally {
abort();
}
}
private static void abort() {
SystemExiter.exit(ExitCodes.HOST_CONTROLLER_ABORT_EXIT_CODE);
}
/**
* Terminates JVM with exit code: 0 - normal termination.
*/
private static void exit(){
SystemExiter.exit(ExitCodes.NORMAL);
}
/**
* Terminates JVM with exit code: 1 - failed termination but not an abort situation.
*/
private static void fail(){
SystemExiter.exit(ExitCodes.FAILED);
}
/**
* @deprecated this method is not meant for public use
*/
@Deprecated
public static HostControllerEnvironment determineEnvironment(String[] args, InputStream stdin, PrintStream stdout, PrintStream stderr) {
return determineEnvironment(args);
}
private static HostControllerEnvironment determineEnvironment(String[] args) {
Integer pmPort = null;
InetAddress pmAddress = null;
final PCSocketConfig pcSocketConfig = new PCSocketConfig();
String defaultJVM = null;
boolean isRestart = false;
boolean backupDomainFiles = false;
boolean cachedDc = false;
String domainConfig = null;
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));
return new HostControllerEnvironment(hostSystemProperties, isRestart, modulePath, pmAddress, pmPort,
pcSocketConfig.getBindAddress(), pcSocketConfig.getBindPort(), defaultJVM,
domainConfig, initialDomainConfig, hostConfig, initialHostConfig, initialRunningMode, backupDomainFiles, cachedDc, productConfig);
}
private static String parseValue(final String arg, final String key) {
int splitPos = key.length();
if (arg.length() <= splitPos + 1 || arg.charAt(splitPos) != '=') {
System.err.println(MESSAGES.argumentHasNoValue(arg, usageNote()));
return null;
} else {
return arg.substring(splitPos + 1);
}
}
/**
* Validates that param {@code value} does not begin with the character {@code -}. For use in cases where
* the legal value for an argument would not begin with that character. Usage is to detect missing argument
* values, where the command line includes another argument instead of the value for the last argument.
*
* @param argument the last argument, whose value should be {@code value}
* @param value the next item in the command line arguments, which should be the value for {@code argument}
* @return {@code value} if it is valid, or {@code null} if it is not
*/
private static String checkValueIsNotAnArg(String argument, String value) {
if (value.startsWith("-")) {
System.err.println(MESSAGES.argumentHasNoValue(argument, usageNote()));
return null;
}
return value;
}
private static boolean processProperties(final String arg, final String urlSpec, Map<String, String> hostSystemProperties) {
URL url = null;
try {
url = makeURL(urlSpec);
Properties props = new Properties();
props.load(url.openConnection().getInputStream());
SecurityActions.getSystemProperties().putAll(props);
for (Map.Entry<Object, Object> entry : props.entrySet()) {
hostSystemProperties.put((String)entry.getKey(), (String)entry.getValue());
}
return true;
} catch (MalformedURLException e) {
System.err.println(MESSAGES.malformedUrl(arg, usageNote()));
return false;
} catch (IOException e) {
System.err.println(MESSAGES.unableToLoadProperties(url, usageNote()));
return false;
}
}
private static Integer parsePort(final String value, final String key) {
try {
return Integer.valueOf(value);
} catch (NumberFormatException e) {
System.err.println(MESSAGES.invalidValue(key, "Integer", value, usageNote()));
return null;
}
}
private static InetAddress parseAddress(final String value, final String key) {
try {
return InetAddress.getByName(value);
} catch (UnknownHostException e) {
System.err.println(MESSAGES.unknownHostValue(key, value, usageNote()));
return null;
}
}
private static URL makeURL(String urlspec) throws MalformedURLException {
urlspec = urlspec.trim();
URL url;
try {
url = new URL(urlspec);
if (url.getProtocol().equals("file")) {
// make sure the file is absolute & canonical file url
File file = new File(url.getFile()).getCanonicalFile();
url = file.toURI().toURL();
}
} catch (Exception e) {
// make sure we have a absolute & canonical file url
try {
File file = new File(urlspec).getCanonicalFile();
url = file.toURI().toURL();
} catch (Exception n) {
throw new MalformedURLException(n.toString());
}
}
return url;
}
private static Map<String, String> getHostSystemProperties() {
final Map<String, String> hostSystemProperties = new HashMap<String, String>();
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
for (String arg : runtime.getInputArguments()) {
if (arg != null && arg.length() > 2 && arg.startsWith("-D")) {
arg = arg.substring(2);
String[] split = arg.split("=");
if (!hostSystemProperties.containsKey(split[0])) {
String val = split.length == 2 ? split[1] : null;
hostSystemProperties.put(split[0], val);
}
}
}
} catch (Exception e) {
System.err.println(MESSAGES.cannotAccessJvmInputArgument(e));
}
return hostSystemProperties;
}
private static String usageNote() {
boolean isWindows = (SecurityActions.getSystemProperty("os.name")).toLowerCase(Locale.ENGLISH).contains("windows");
String command = isWindows ? "domain" : "domain.sh";
return MESSAGES.usageNote(command);
}
private static class PCSocketConfig {
private final String defaultBindAddress;
private InetAddress bindAddress;
private int bindPort = 0;
private int argIncrement = 0;
private boolean parseFailed;
private final UnknownHostException uhe;
private PCSocketConfig() {
boolean preferIPv6 = Boolean.valueOf(SecurityActions.getSystemProperty("java.net.preferIPv6Addresses", "false"));
this.defaultBindAddress = preferIPv6 ? "::1" : "127.0.0.1";
UnknownHostException toCache = null;
try {
bindAddress = InetAddress.getByName(defaultBindAddress);
} catch (UnknownHostException e) {
try {
bindAddress = InetAddressUtil.getLocalHost();
} catch (UnknownHostException uhe) {
toCache = uhe;
}
}
uhe = toCache;
}
private InetAddress getBindAddress() {
if (bindAddress == null) {
throw MESSAGES.cannotObtainValidDefaultAddress(uhe, defaultBindAddress, CommandLineConstants.INTERPROCESS_HC_ADDRESS);
}
return bindAddress;
}
private int getBindPort() {
return bindPort;
}
private int getArgIncrement() {
return argIncrement;
}
private boolean isParseFailed() {
return parseFailed;
}
private boolean processPCSocketConfigArgument(final String arg, final String[] args, final int index) {
boolean isPCSocketArg = true;
argIncrement = 0;
if (CommandLineConstants.INTERPROCESS_HC_ADDRESS.equals(arg) || CommandLineConstants.OLD_INTERPROCESS_HC_ADDRESS.equals(arg)) {
setBindAddress(arg, args[index +1]);
argIncrement = 1;
} else if (arg.startsWith(CommandLineConstants.INTERPROCESS_HC_ADDRESS)) {
String addr = parseValue(arg, CommandLineConstants.INTERPROCESS_HC_ADDRESS);
if (addr == null) {
parseFailed = true;
} else {
setBindAddress(arg, addr);
}
} else if (arg.startsWith(CommandLineConstants.OLD_INTERPROCESS_HC_ADDRESS)) {
String addr = parseValue(arg, CommandLineConstants.OLD_INTERPROCESS_HC_ADDRESS);
if (addr == null) {
parseFailed = true;
} else {
setBindAddress(arg, addr);
}
} else if (CommandLineConstants.INTERPROCESS_HC_PORT.equals(arg) || CommandLineConstants.OLD_INTERPROCESS_HC_PORT.equals(arg)) {
bindPort = Integer.parseInt(args[index + 1]);
argIncrement = 1;
} else if (arg.startsWith(CommandLineConstants.INTERPROCESS_HC_PORT)) {
String port = parseValue(arg, CommandLineConstants.INTERPROCESS_HC_PORT);
if (port == null) {
parseFailed = true;
} else {
bindPort = Integer.parseInt(port);
}
} else if (arg.startsWith(CommandLineConstants.OLD_INTERPROCESS_HC_PORT)) {
String port = parseValue(arg, CommandLineConstants.OLD_INTERPROCESS_HC_PORT);
if (port == null) {
parseFailed = true;
} else {
bindPort = Integer.parseInt(port);
}
} else {
isPCSocketArg = false;
}
return isPCSocketArg;
}
private void setBindAddress(String key, String value) {
try {
bindAddress = InetAddress.getByName(value);
} catch (UnknownHostException e) {
parseFailed = true;
System.err.println(MESSAGES.invalidValue(key, "InetAddress", value, usageNote()));
}
}
}
}