OpenJDK / jdk / jdk
changeset 57758:dff4792e3206
8234484: Add ability to configure third port for remote JMX
Reviewed-by: dfuchs
Contributed-by: hedongbo@huawei.com
author | fyang |
---|---|
date | Wed, 15 Jan 2020 16:00:01 +0800 |
parents | c61cd64e09ac |
children | 1af0eec6c10d |
files | src/jdk.management.agent/share/classes/jdk/internal/agent/AgentConfigurationError.java src/jdk.management.agent/share/classes/sun/management/jmxremote/ConnectorBootstrap.java src/jdk.management.agent/share/conf/management.properties |
diffstat | 3 files changed, 34 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.management.agent/share/classes/jdk/internal/agent/AgentConfigurationError.java Tue Jan 21 08:46:06 2020 -0500 +++ b/src/jdk.management.agent/share/classes/jdk/internal/agent/AgentConfigurationError.java Wed Jan 15 16:00:01 2020 +0800 @@ -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 @@ -55,6 +55,8 @@ "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 =
--- a/src/jdk.management.agent/share/classes/sun/management/jmxremote/ConnectorBootstrap.java Tue Jan 21 08:46:06 2020 -0500 +++ b/src/jdk.management.agent/share/classes/sun/management/jmxremote/ConnectorBootstrap.java Wed Jan 15 16:00:01 2020 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2017, 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 @@ -116,6 +116,8 @@ "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 = @@ -540,13 +542,35 @@ } 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(); - if (props == null) { + 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();
--- a/src/jdk.management.agent/share/conf/management.properties Tue Jan 21 08:46:06 2020 -0500 +++ b/src/jdk.management.agent/share/conf/management.properties Wed Jan 15 16:00:01 2020 +0800 @@ -25,6 +25,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> ##################################################################### # Optional Instrumentation