MBeanServerFactoryBean returns JDK 1.5 platform MBeanServer for agent id "" (SPR-5909)
This commit is contained in:
@@ -161,6 +161,7 @@ public class MBeanClientInterceptor
|
||||
* attempt being made to locate the attendant MBeanServer, unless
|
||||
* the {@link #setServiceUrl "serviceUrl"} property has been set.
|
||||
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
|
||||
* <p>Specifying the empty String indicates the platform MBeanServer.
|
||||
*/
|
||||
public void setAgentId(String agentId) {
|
||||
this.agentId = agentId;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,6 +105,7 @@ public class NotificationListenerRegistrar extends NotificationListenerHolder
|
||||
* attempt being made to locate the attendant MBeanServer, unless
|
||||
* the {@link #setServiceUrl "serviceUrl"} property has been set.
|
||||
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
|
||||
* <p>Specifying the empty String indicates the platform MBeanServer.
|
||||
*/
|
||||
public void setAgentId(String agentId) {
|
||||
this.agentId = agentId;
|
||||
|
||||
@@ -91,28 +91,31 @@ public abstract class JmxUtils {
|
||||
* <code>MBeanServer</code> can be found. Logs a warning if more than one
|
||||
* <code>MBeanServer</code> found, returning the first one from the list.
|
||||
* @param agentId the agent identifier of the MBeanServer to retrieve.
|
||||
* If this parameter is <code>null</code>, all registered MBeanServers are
|
||||
* considered.
|
||||
* If this parameter is <code>null</code>, all registered MBeanServers are considered.
|
||||
* If the empty String is given, the platform MBeanServer will be returned.
|
||||
* @return the <code>MBeanServer</code> if found
|
||||
* @throws org.springframework.jmx.MBeanServerNotFoundException
|
||||
* if no <code>MBeanServer</code> could be found
|
||||
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
|
||||
*/
|
||||
public static MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException {
|
||||
List servers = MBeanServerFactory.findMBeanServer(agentId);
|
||||
|
||||
MBeanServer server = null;
|
||||
if (servers != null && servers.size() > 0) {
|
||||
// Check to see if an MBeanServer is registered.
|
||||
if (servers.size() > 1 && logger.isWarnEnabled()) {
|
||||
logger.warn("Found more than one MBeanServer instance" +
|
||||
(agentId != null ? " with agent id [" + agentId + "]" : "") +
|
||||
". Returning first from list.");
|
||||
|
||||
// null means any registered server, but "" specifically means the platform server
|
||||
if (!"".equals(agentId)) {
|
||||
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId);
|
||||
if (servers != null && servers.size() > 0) {
|
||||
// Check to see if an MBeanServer is registered.
|
||||
if (servers.size() > 1 && logger.isWarnEnabled()) {
|
||||
logger.warn("Found more than one MBeanServer instance" +
|
||||
(agentId != null ? " with agent id [" + agentId + "]" : "") +
|
||||
". Returning first from list.");
|
||||
}
|
||||
server = servers.get(0);
|
||||
}
|
||||
server = (MBeanServer) servers.get(0);
|
||||
}
|
||||
|
||||
if (server == null && agentId == null) {
|
||||
if (server == null && !StringUtils.hasLength(agentId)) {
|
||||
// Attempt to load the PlatformMBeanServer.
|
||||
try {
|
||||
server = ManagementFactory.getPlatformMBeanServer();
|
||||
|
||||
@@ -84,6 +84,7 @@ public class MBeanServerFactoryBean implements FactoryBean<MBeanServer>, Initial
|
||||
* and (importantly) if said MBeanServer cannot be located no
|
||||
* attempt will be made to create a new MBeanServer (and an
|
||||
* MBeanServerNotFoundException will be thrown at resolution time).
|
||||
* <p>Specifying the empty String indicates the platform MBeanServer.
|
||||
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
|
||||
*/
|
||||
public void setAgentId(String agentId) {
|
||||
|
||||
Reference in New Issue
Block a user