Skip to content

Commit

Permalink
8234484: Add ability to configure third port for remote JMX
Browse files Browse the repository at this point in the history
Reviewed-by: ksrini
Backport-of: f129cc43283a18cb5afdd1416b09691a636a7758
  • Loading branch information
Vyom Tewari authored and Kumar Srinivasan committed Dec 19, 2022
1 parent 06546d7 commit 78cdc41
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -55,6 +55,8 @@ public class AgentConfigurationError extends Error {
"agent.err.invalid.jmxremote.port";
public static final String INVALID_JMXREMOTE_RMI_PORT =
"agent.err.invalid.jmxremote.rmi.port";
public static final String INVALID_JMXREMOTE_LOCAL_PORT =
"agent.err.invalid.jmxremote.local.port";
public static final String PASSWORD_FILE_NOT_SET =
"agent.err.password.file.notset";
public static final String PASSWORD_FILE_NOT_READABLE =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -117,6 +117,8 @@ public static interface PropertyNames {
"com.sun.management.jmxremote.host";
public static final String RMI_PORT =
"com.sun.management.jmxremote.rmi.port";
public static final String LOCAL_PORT =
"com.sun.management.jmxremote.local.port";
public static final String CONFIG_FILE_NAME =
"com.sun.management.config.file";
public static final String USE_LOCAL_ONLY =
Expand Down Expand Up @@ -531,13 +533,35 @@ public static JMXConnectorServer startLocalConnectorServer() {
}

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

Properties props = null;
try {
JMXServiceURL url = new JMXServiceURL("rmi", localhost, 0);
// Do we accept connections from local interfaces only?
Properties props = Agent.getManagementProperties();
props = Agent.getManagementProperties();
if (props == null) {
props = new Properties();
}
} catch (Exception e) {
throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
}

// User can specify a port to be used to start local connector server.
// Random one will be allocated if port is not specified.
int localPort = 0;
String localPortStr = props.getProperty(PropertyNames.LOCAL_PORT);
try {
if (localPortStr != null) {
localPort = Integer.parseInt(localPortStr);
}
} catch (NumberFormatException x) {
throw new AgentConfigurationError(INVALID_JMXREMOTE_LOCAL_PORT, x, localPortStr);
}
if (localPort < 0) {
throw new AgentConfigurationError(INVALID_JMXREMOTE_LOCAL_PORT, localPortStr);
}

try {
JMXServiceURL url = new JMXServiceURL("rmi", localhost, localPort);
// Do we accept connections from local interfaces only?
String useLocalOnlyStr = props.getProperty(
PropertyNames.USE_LOCAL_ONLY, DefaultValues.USE_LOCAL_ONLY);
boolean useLocalOnly = Boolean.valueOf(useLocalOnlyStr).booleanValue();
Expand Down
2 changes: 2 additions & 0 deletions jdk/src/share/lib/management/management.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
# For setting the JMX RMI agent port use the following line
# com.sun.management.jmxremote.port=<port-number>
#
# For setting the JMX local server port use the following line
# com.sun.management.jmxremote.local.port=<port-number>
# For setting the SNMP agent port use the following line
# com.sun.management.snmp.port=<port-number>

Expand Down

1 comment on commit 78cdc41

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.