Skip to content

Commit 78cdc41

Browse files
Vyom TewariKumar Srinivasan
authored andcommitted
8234484: Add ability to configure third port for remote JMX
Reviewed-by: ksrini Backport-of: f129cc43283a18cb5afdd1416b09691a636a7758
1 parent 06546d7 commit 78cdc41

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

jdk/src/share/classes/sun/management/AgentConfigurationError.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,6 +55,8 @@ public class AgentConfigurationError extends Error {
5555
"agent.err.invalid.jmxremote.port";
5656
public static final String INVALID_JMXREMOTE_RMI_PORT =
5757
"agent.err.invalid.jmxremote.rmi.port";
58+
public static final String INVALID_JMXREMOTE_LOCAL_PORT =
59+
"agent.err.invalid.jmxremote.local.port";
5860
public static final String PASSWORD_FILE_NOT_SET =
5961
"agent.err.password.file.notset";
6062
public static final String PASSWORD_FILE_NOT_READABLE =

jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -117,6 +117,8 @@ public static interface PropertyNames {
117117
"com.sun.management.jmxremote.host";
118118
public static final String RMI_PORT =
119119
"com.sun.management.jmxremote.rmi.port";
120+
public static final String LOCAL_PORT =
121+
"com.sun.management.jmxremote.local.port";
120122
public static final String CONFIG_FILE_NAME =
121123
"com.sun.management.config.file";
122124
public static final String USE_LOCAL_ONLY =
@@ -531,13 +533,35 @@ public static JMXConnectorServer startLocalConnectorServer() {
531533
}
532534

533535
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
536+
537+
Properties props = null;
534538
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();
538540
if (props == null) {
539541
props = new Properties();
540542
}
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?
541565
String useLocalOnlyStr = props.getProperty(
542566
PropertyNames.USE_LOCAL_ONLY, DefaultValues.USE_LOCAL_ONLY);
543567
boolean useLocalOnly = Boolean.valueOf(useLocalOnlyStr).booleanValue();

jdk/src/share/lib/management/management.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# For setting the JMX RMI agent port use the following line
2727
# com.sun.management.jmxremote.port=<port-number>
2828
#
29+
# For setting the JMX local server port use the following line
30+
# com.sun.management.jmxremote.local.port=<port-number>
2931
# For setting the SNMP agent port use the following line
3032
# com.sun.management.snmp.port=<port-number>
3133

0 commit comments

Comments
 (0)