Polishing
Issue: SPR-8045
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -25,7 +25,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.DynamicMBean;
|
||||
import javax.management.JMException;
|
||||
import javax.management.MBeanException;
|
||||
@@ -82,8 +81,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* via the {@link #setListeners(MBeanExporterListener[]) listeners} property, allowing
|
||||
* application code to be notified of MBean registration and unregistration events.
|
||||
*
|
||||
* <p>This exporter is compatible with JMX 1.2 on Java 5 and above.
|
||||
* As of Spring 2.5, it also autodetects and exports Java 6 MXBeans.
|
||||
* <p>This exporter is compatible with MBeans and MXBeans on Java 6 and above.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
@@ -97,8 +95,8 @@ import org.springframework.util.ObjectUtils;
|
||||
* @see org.springframework.jmx.export.assembler.MBeanInfoAssembler
|
||||
* @see MBeanExporterListener
|
||||
*/
|
||||
public class MBeanExporter extends MBeanRegistrationSupport
|
||||
implements MBeanExportOperations, BeanClassLoaderAware, BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExportOperations,
|
||||
BeanClassLoaderAware, BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
|
||||
/**
|
||||
* Autodetection mode indicating that no autodetection should be used.
|
||||
@@ -147,6 +145,12 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
/** Whether to eagerly initialize candidate beans when autodetecting MBeans */
|
||||
private boolean allowEagerInit = false;
|
||||
|
||||
/** Stores the MBeanInfoAssembler to use for this exporter */
|
||||
private MBeanInfoAssembler assembler = new SimpleReflectiveMBeanInfoAssembler();
|
||||
|
||||
/** The strategy to use for creating ObjectNames for an object */
|
||||
private ObjectNamingStrategy namingStrategy = new KeyNamingStrategy();
|
||||
|
||||
/** Indicates whether Spring should modify generated ObjectNames */
|
||||
private boolean ensureUniqueRuntimeObjectNames = true;
|
||||
|
||||
@@ -166,12 +170,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
private final Map<NotificationListenerBean, ObjectName[]> registeredNotificationListeners =
|
||||
new LinkedHashMap<NotificationListenerBean, ObjectName[]>();
|
||||
|
||||
/** Stores the MBeanInfoAssembler to use for this exporter */
|
||||
private MBeanInfoAssembler assembler = new SimpleReflectiveMBeanInfoAssembler();
|
||||
|
||||
/** The strategy to use for creating ObjectNames for an object */
|
||||
private ObjectNamingStrategy namingStrategy = new KeyNamingStrategy();
|
||||
|
||||
/** Stores the ClassLoader to use for generating lazy-init proxies */
|
||||
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
|
||||
|
||||
@@ -284,22 +282,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
this.namingStrategy = namingStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@code MBeanExporterListener}s that should be notified
|
||||
* of MBean registration and unregistration events.
|
||||
* @see MBeanExporterListener
|
||||
*/
|
||||
public void setListeners(MBeanExporterListener[] listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of names for beans that should be excluded from autodetection.
|
||||
*/
|
||||
public void setExcludedBeans(String[] excludedBeans) {
|
||||
this.excludedBeans = (excludedBeans != null ? new HashSet<String>(Arrays.asList(excludedBeans)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether Spring should ensure that {@link ObjectName ObjectNames}
|
||||
* generated by the configured {@link ObjectNamingStrategy} for
|
||||
@@ -325,6 +307,22 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
this.exposeManagedResourceClassLoader = exposeManagedResourceClassLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of names for beans that should be excluded from autodetection.
|
||||
*/
|
||||
public void setExcludedBeans(String... excludedBeans) {
|
||||
this.excludedBeans = (excludedBeans != null ? new HashSet<String>(Arrays.asList(excludedBeans)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@code MBeanExporterListener}s that should be notified
|
||||
* of MBean registration and unregistration events.
|
||||
* @see MBeanExporterListener
|
||||
*/
|
||||
public void setListeners(MBeanExporterListener... listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link NotificationListenerBean NotificationListenerBeans}
|
||||
* containing the
|
||||
@@ -333,7 +331,7 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
* @see #setNotificationListenerMappings(java.util.Map)
|
||||
* @see NotificationListenerBean
|
||||
*/
|
||||
public void setNotificationListeners(NotificationListenerBean[] notificationListeners) {
|
||||
public void setNotificationListeners(NotificationListenerBean... notificationListeners) {
|
||||
this.notificationListeners = notificationListeners;
|
||||
}
|
||||
|
||||
@@ -401,17 +399,18 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Start bean registration automatically when deployed in an
|
||||
* Kick off bean registration automatically when deployed in an
|
||||
* {@code ApplicationContext}.
|
||||
* @see #registerBeans()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
// If no server was provided then try to find one. This is useful in an environment
|
||||
// such as JDK 1.5, Tomcat or JBoss where there is already an MBeanServer loaded.
|
||||
// where there is already an MBeanServer loaded.
|
||||
if (this.server == null) {
|
||||
this.server = JmxUtils.locateMBeanServer();
|
||||
}
|
||||
|
||||
try {
|
||||
logger.info("Registering beans for JMX exposure on startup");
|
||||
registerBeans();
|
||||
@@ -520,7 +519,7 @@ public class MBeanExporter extends MBeanRegistrationSupport
|
||||
}
|
||||
if (mode == AUTODETECT_MBEAN || mode == AUTODETECT_ALL) {
|
||||
// Autodetect any beans that are already MBeans.
|
||||
this.logger.debug("Autodetecting user-defined JMX MBeans");
|
||||
logger.debug("Autodetecting user-defined JMX MBeans");
|
||||
autodetectMBeans();
|
||||
}
|
||||
// Allow the assembler a chance to vote for bean inclusion.
|
||||
|
||||
Reference in New Issue
Block a user