|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -117,6 +117,8 @@ public static interface PropertyNames {
|
117 | 117 | "com.sun.management.jmxremote.host";
|
118 | 118 | public static final String RMI_PORT =
|
119 | 119 | "com.sun.management.jmxremote.rmi.port";
|
| 120 | + public static final String LOCAL_PORT = |
| 121 | + "com.sun.management.jmxremote.local.port"; |
120 | 122 | public static final String CONFIG_FILE_NAME =
|
121 | 123 | "com.sun.management.config.file";
|
122 | 124 | public static final String USE_LOCAL_ONLY =
|
@@ -531,13 +533,35 @@ public static JMXConnectorServer startLocalConnectorServer() {
|
531 | 533 | }
|
532 | 534 |
|
533 | 535 | MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
| 536 | + |
| 537 | + Properties props = null; |
534 | 538 | try {
|
535 |
| - JMXServiceURL url = new JMXServiceURL("rmi", localhost, 0); |
536 |
| - // Do we accept connections from local interfaces only? |
537 |
| - Properties props = Agent.getManagementProperties(); |
| 539 | + props = Agent.getManagementProperties(); |
538 | 540 | if (props == null) {
|
539 | 541 | props = new Properties();
|
540 | 542 | }
|
| 543 | + } catch (Exception e) { |
| 544 | + throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString()); |
| 545 | + } |
| 546 | + |
| 547 | + // User can specify a port to be used to start local connector server. |
| 548 | + // Random one will be allocated if port is not specified. |
| 549 | + int localPort = 0; |
| 550 | + String localPortStr = props.getProperty(PropertyNames.LOCAL_PORT); |
| 551 | + try { |
| 552 | + if (localPortStr != null) { |
| 553 | + localPort = Integer.parseInt(localPortStr); |
| 554 | + } |
| 555 | + } catch (NumberFormatException x) { |
| 556 | + throw new AgentConfigurationError(INVALID_JMXREMOTE_LOCAL_PORT, x, localPortStr); |
| 557 | + } |
| 558 | + if (localPort < 0) { |
| 559 | + throw new AgentConfigurationError(INVALID_JMXREMOTE_LOCAL_PORT, localPortStr); |
| 560 | + } |
| 561 | + |
| 562 | + try { |
| 563 | + JMXServiceURL url = new JMXServiceURL("rmi", localhost, localPort); |
| 564 | + // Do we accept connections from local interfaces only? |
541 | 565 | String useLocalOnlyStr = props.getProperty(
|
542 | 566 | PropertyNames.USE_LOCAL_ONLY, DefaultValues.USE_LOCAL_ONLY);
|
543 | 567 | boolean useLocalOnly = Boolean.valueOf(useLocalOnlyStr).booleanValue();
|
|
0 commit comments