1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
96
96
* @see org.springframework.jmx.export.assembler.MBeanInfoAssembler
97
97
* @see MBeanExporterListener
98
98
*/
99
- public class MBeanExporter extends MBeanRegistrationSupport
100
- implements MBeanExportOperations , BeanClassLoaderAware , BeanFactoryAware , InitializingBean , DisposableBean {
99
+ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExportOperations ,
100
+ BeanClassLoaderAware , BeanFactoryAware , InitializingBean , DisposableBean {
101
101
102
102
/**
103
103
* Autodetection mode indicating that no autodetection should be used.
@@ -146,6 +146,12 @@ public class MBeanExporter extends MBeanRegistrationSupport
146
146
/** Whether to eagerly initialize candidate beans when autodetecting MBeans */
147
147
private boolean allowEagerInit = false ;
148
148
149
+ /** Stores the MBeanInfoAssembler to use for this exporter */
150
+ private MBeanInfoAssembler assembler = new SimpleReflectiveMBeanInfoAssembler ();
151
+
152
+ /** The strategy to use for creating ObjectNames for an object */
153
+ private ObjectNamingStrategy namingStrategy = new KeyNamingStrategy ();
154
+
149
155
/** Indicates whether Spring should modify generated ObjectNames */
150
156
private boolean ensureUniqueRuntimeObjectNames = true ;
151
157
@@ -165,12 +171,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
165
171
private final Map <NotificationListenerBean , ObjectName []> registeredNotificationListeners =
166
172
new LinkedHashMap <NotificationListenerBean , ObjectName []>();
167
173
168
- /** Stores the MBeanInfoAssembler to use for this exporter */
169
- private MBeanInfoAssembler assembler = new SimpleReflectiveMBeanInfoAssembler ();
170
-
171
- /** The strategy to use for creating ObjectNames for an object */
172
- private ObjectNamingStrategy namingStrategy = new KeyNamingStrategy ();
173
-
174
174
/** Stores the ClassLoader to use for generating lazy-init proxies */
175
175
private ClassLoader beanClassLoader = ClassUtils .getDefaultClassLoader ();
176
176
@@ -283,22 +283,6 @@ public void setNamingStrategy(ObjectNamingStrategy namingStrategy) {
283
283
this .namingStrategy = namingStrategy ;
284
284
}
285
285
286
- /**
287
- * Set the {@code MBeanExporterListener}s that should be notified
288
- * of MBean registration and unregistration events.
289
- * @see MBeanExporterListener
290
- */
291
- public void setListeners (MBeanExporterListener [] listeners ) {
292
- this .listeners = listeners ;
293
- }
294
-
295
- /**
296
- * Set the list of names for beans that should be excluded from autodetection.
297
- */
298
- public void setExcludedBeans (String [] excludedBeans ) {
299
- this .excludedBeans = (excludedBeans != null ? new HashSet <String >(Arrays .asList (excludedBeans )) : null );
300
- }
301
-
302
286
/**
303
287
* Indicates whether Spring should ensure that {@link ObjectName ObjectNames}
304
288
* generated by the configured {@link ObjectNamingStrategy} for
@@ -324,6 +308,22 @@ public void setExposeManagedResourceClassLoader(boolean exposeManagedResourceCla
324
308
this .exposeManagedResourceClassLoader = exposeManagedResourceClassLoader ;
325
309
}
326
310
311
+ /**
312
+ * Set the list of names for beans that should be excluded from autodetection.
313
+ */
314
+ public void setExcludedBeans (String ... excludedBeans ) {
315
+ this .excludedBeans = (excludedBeans != null ? new HashSet <String >(Arrays .asList (excludedBeans )) : null );
316
+ }
317
+
318
+ /**
319
+ * Set the {@code MBeanExporterListener}s that should be notified
320
+ * of MBean registration and unregistration events.
321
+ * @see MBeanExporterListener
322
+ */
323
+ public void setListeners (MBeanExporterListener ... listeners ) {
324
+ this .listeners = listeners ;
325
+ }
326
+
327
327
/**
328
328
* Set the {@link NotificationListenerBean NotificationListenerBeans}
329
329
* containing the
@@ -332,7 +332,7 @@ public void setExposeManagedResourceClassLoader(boolean exposeManagedResourceCla
332
332
* @see #setNotificationListenerMappings(java.util.Map)
333
333
* @see NotificationListenerBean
334
334
*/
335
- public void setNotificationListeners (NotificationListenerBean [] notificationListeners ) {
335
+ public void setNotificationListeners (NotificationListenerBean ... notificationListeners ) {
336
336
this .notificationListeners = notificationListeners ;
337
337
}
338
338
@@ -398,16 +398,17 @@ public void setBeanFactory(BeanFactory beanFactory) {
398
398
//---------------------------------------------------------------------
399
399
400
400
/**
401
- * Start bean registration automatically when deployed in an
401
+ * Kick off bean registration automatically when deployed in an
402
402
* {@code ApplicationContext}.
403
403
* @see #registerBeans()
404
404
*/
405
405
public void afterPropertiesSet () {
406
406
// If no server was provided then try to find one. This is useful in an environment
407
- // such as JDK 1.5, Tomcat or JBoss where there is already an MBeanServer loaded.
407
+ // where there is already an MBeanServer loaded.
408
408
if (this .server == null ) {
409
409
this .server = JmxUtils .locateMBeanServer ();
410
410
}
411
+
411
412
try {
412
413
logger .info ("Registering beans for JMX exposure on startup" );
413
414
registerBeans ();
@@ -512,7 +513,7 @@ protected void registerBeans() {
512
513
}
513
514
if (mode == AUTODETECT_MBEAN || mode == AUTODETECT_ALL ) {
514
515
// Autodetect any beans that are already MBeans.
515
- this . logger .debug ("Autodetecting user-defined JMX MBeans" );
516
+ logger .debug ("Autodetecting user-defined JMX MBeans" );
516
517
autodetectMBeans ();
517
518
}
518
519
// Allow the assembler a chance to vote for bean inclusion.
@@ -739,7 +740,7 @@ protected ObjectName getObjectName(Object bean, String beanKey) throws Malformed
739
740
* @return whether the class qualifies as an MBean
740
741
* @see org.springframework.jmx.support.JmxUtils#isMBean(Class)
741
742
*/
742
- protected boolean isMBean (Class beanClass ) {
743
+ protected boolean isMBean (Class <?> beanClass ) {
743
744
return JmxUtils .isMBean (beanClass );
744
745
}
745
746
@@ -753,24 +754,24 @@ protected boolean isMBean(Class beanClass) {
753
754
*/
754
755
@ SuppressWarnings ("unchecked" )
755
756
protected DynamicMBean adaptMBeanIfPossible (Object bean ) throws JMException {
756
- Class targetClass = AopUtils .getTargetClass (bean );
757
+ Class <?> targetClass = AopUtils .getTargetClass (bean );
757
758
if (targetClass != bean .getClass ()) {
758
- Class ifc = JmxUtils .getMXBeanInterface (targetClass );
759
+ Class <?> ifc = JmxUtils .getMXBeanInterface (targetClass );
759
760
if (ifc != null ) {
760
- if (!( ifc .isInstance (bean ) )) {
761
+ if (!ifc .isInstance (bean )) {
761
762
throw new NotCompliantMBeanException ("Managed bean [" + bean +
762
763
"] has a target class with an MXBean interface but does not expose it in the proxy" );
763
764
}
764
- return new StandardMBean (bean , ifc , true );
765
+ return new StandardMBean (bean , (( Class < Object >) ifc ) , true );
765
766
}
766
767
else {
767
768
ifc = JmxUtils .getMBeanInterface (targetClass );
768
769
if (ifc != null ) {
769
- if (!( ifc .isInstance (bean ) )) {
770
+ if (!ifc .isInstance (bean )) {
770
771
throw new NotCompliantMBeanException ("Managed bean [" + bean +
771
772
"] has a target class with an MBean interface but does not expose it in the proxy" );
772
773
}
773
- return new StandardMBean (bean , ifc );
774
+ return new StandardMBean (bean , (( Class < Object >) ifc ) );
774
775
}
775
776
}
776
777
}
@@ -840,7 +841,7 @@ private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws J
840
841
*/
841
842
private void autodetectBeans (final AutodetectCapableMBeanInfoAssembler assembler ) {
842
843
autodetect (new AutodetectCallback () {
843
- public boolean include (Class beanClass , String beanName ) {
844
+ public boolean include (Class <?> beanClass , String beanName ) {
844
845
return assembler .includeBean (beanClass , beanName );
845
846
}
846
847
});
@@ -852,7 +853,7 @@ public boolean include(Class beanClass, String beanName) {
852
853
*/
853
854
private void autodetectMBeans () {
854
855
autodetect (new AutodetectCallback () {
855
- public boolean include (Class beanClass , String beanName ) {
856
+ public boolean include (Class <?> beanClass , String beanName ) {
856
857
return isMBean (beanClass );
857
858
}
858
859
});
@@ -874,7 +875,7 @@ private void autodetect(AutodetectCallback callback) {
874
875
for (String beanName : beanNames ) {
875
876
if (!isExcluded (beanName ) && !isBeanDefinitionAbstract (this .beanFactory , beanName )) {
876
877
try {
877
- Class beanClass = this .beanFactory .getType (beanName );
878
+ Class <?> beanClass = this .beanFactory .getType (beanName );
878
879
if (beanClass != null && callback .include (beanClass , beanName )) {
879
880
boolean lazyInit = isBeanDefinitionLazyInit (this .beanFactory , beanName );
880
881
Object beanInstance = (!lazyInit ? this .beanFactory .getBean (beanName ) : null );
@@ -1060,7 +1061,7 @@ private static interface AutodetectCallback {
1060
1061
* @param beanClass the class of the bean
1061
1062
* @param beanName the name of the bean
1062
1063
*/
1063
- boolean include (Class beanClass , String beanName );
1064
+ boolean include (Class <?> beanClass , String beanName );
1064
1065
}
1065
1066
1066
1067
0 commit comments