8131061: Use of -Dcom.sun.management.snmp needs to be examined for modules
Reviewed-by: mchung, dfuchs
This commit is contained in:
parent
d356b8d085
commit
09e25d0d1f
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -50,6 +50,7 @@ module java.management {
|
|||||||
uses javax.management.remote.JMXConnectorProvider;
|
uses javax.management.remote.JMXConnectorProvider;
|
||||||
uses javax.management.remote.JMXConnectorServerProvider;
|
uses javax.management.remote.JMXConnectorServerProvider;
|
||||||
uses sun.management.spi.PlatformMBeanProvider;
|
uses sun.management.spi.PlatformMBeanProvider;
|
||||||
|
uses sun.management.spi.AgentProvider;
|
||||||
|
|
||||||
provides javax.security.auth.spi.LoginModule
|
provides javax.security.auth.spi.LoginModule
|
||||||
with com.sun.jmx.remote.security.FileLoginModule;
|
with com.sun.jmx.remote.security.FileLoginModule;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -31,17 +31,19 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ import sun.management.jmxremote.ConnectorBootstrap;
|
|||||||
import sun.management.jdp.JdpController;
|
import sun.management.jdp.JdpController;
|
||||||
import sun.management.jdp.JdpException;
|
import sun.management.jdp.JdpException;
|
||||||
import jdk.internal.vm.VMSupport;
|
import jdk.internal.vm.VMSupport;
|
||||||
|
import sun.management.spi.AgentProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Agent is started by the VM when -Dcom.sun.management.snmp or
|
* This Agent is started by the VM when -Dcom.sun.management.snmp or
|
||||||
@ -248,8 +251,8 @@ public class Agent {
|
|||||||
"com.sun.management.enableThreadContentionMonitoring";
|
"com.sun.management.enableThreadContentionMonitoring";
|
||||||
private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
|
private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
|
||||||
"com.sun.management.jmxremote.localConnectorAddress";
|
"com.sun.management.jmxremote.localConnectorAddress";
|
||||||
private static final String SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME =
|
private static final String SNMP_AGENT_NAME =
|
||||||
"sun.management.snmp.AdaptorBootstrap";
|
"SnmpAgent";
|
||||||
|
|
||||||
private static final String JDP_DEFAULT_ADDRESS = "224.0.23.178";
|
private static final String JDP_DEFAULT_ADDRESS = "224.0.23.178";
|
||||||
private static final int JDP_DEFAULT_PORT = 7095;
|
private static final int JDP_DEFAULT_PORT = 7095;
|
||||||
@ -429,7 +432,7 @@ public class Agent {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (snmpPort != null) {
|
if (snmpPort != null) {
|
||||||
loadSnmpAgent(snmpPort, props);
|
loadSnmpAgent(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -554,28 +557,24 @@ public class Agent {
|
|||||||
return mgmtProps;
|
return mgmtProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadSnmpAgent(String snmpPort, Properties props) {
|
private static void loadSnmpAgent(Properties props) {
|
||||||
try {
|
/*
|
||||||
// invoke the following through reflection:
|
* Load the jdk.snmp service
|
||||||
// AdaptorBootstrap.initialize(snmpPort, props);
|
*/
|
||||||
final Class<?> adaptorClass =
|
AgentProvider provider = AccessController.doPrivileged(
|
||||||
Class.forName(SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME, true, null);
|
(PrivilegedAction<AgentProvider>) () -> {
|
||||||
final Method initializeMethod =
|
for(AgentProvider aProvider : ServiceLoader.loadInstalled(AgentProvider.class)) {
|
||||||
adaptorClass.getMethod("initialize",
|
if(aProvider.getName().equals(SNMP_AGENT_NAME))
|
||||||
String.class, Properties.class);
|
return aProvider;
|
||||||
initializeMethod.invoke(null, snmpPort, props);
|
}
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException x) {
|
return null;
|
||||||
// snmp runtime doesn't exist - initialization fails
|
}, null
|
||||||
throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT, x);
|
);
|
||||||
} catch (InvocationTargetException x) {
|
|
||||||
final Throwable cause = x.getCause();
|
if (provider != null) {
|
||||||
if (cause instanceof RuntimeException) {
|
provider.startAgent(props);
|
||||||
throw (RuntimeException) cause;
|
} else { // snmp runtime doesn't exist - initialization fails
|
||||||
} else if (cause instanceof Error) {
|
throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT);
|
||||||
throw (Error) cause;
|
|
||||||
}
|
|
||||||
// should not happen...
|
|
||||||
throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT, cause);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* This code 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 General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
package sun.management.spi;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service interface for management agent
|
||||||
|
*/
|
||||||
|
public abstract class AgentProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new AgentProvider.
|
||||||
|
*
|
||||||
|
* @throws SecurityException if the subclass (and calling code) does not
|
||||||
|
* have
|
||||||
|
* {@code RuntimePermission("sun.management.spi.AgentProvider.subclass")}
|
||||||
|
*/
|
||||||
|
protected AgentProvider() {
|
||||||
|
this(checkSubclassPermission());
|
||||||
|
}
|
||||||
|
|
||||||
|
private AgentProvider(Void unused) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Void checkSubclassPermission() {
|
||||||
|
SecurityManager sm = System.getSecurityManager();
|
||||||
|
if (sm != null) {
|
||||||
|
sm.checkPermission(new RuntimePermission(AgentProvider.class.getName() + ".subclass"));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of the agent provider.
|
||||||
|
*
|
||||||
|
* @return name of agent provider
|
||||||
|
*/
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes and starts the agent.
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException if this agent has already been started.
|
||||||
|
*/
|
||||||
|
public abstract void startAgent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes and starts the agent at given port and with given properties
|
||||||
|
*
|
||||||
|
* @param props environment variables for agent
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException if this agent has already been started.
|
||||||
|
*/
|
||||||
|
public abstract void startAgent(Properties props);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if agent is started and not terminated.
|
||||||
|
*
|
||||||
|
* @return true if agent is running, false otherwise.
|
||||||
|
*/
|
||||||
|
public abstract boolean isActive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops this agent.
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException if this agent is not started.
|
||||||
|
*/
|
||||||
|
public abstract void stopAgent();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user