KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > StandardMBeanMetaDataImpl


1 /*
2  * @(#)StandardMBeanMetaDataImpl.java 1.2 05/05/27
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.jmx.mbeanserver;
9
10 import javax.management.MBeanInfo JavaDoc;
11 import javax.management.StandardMBean JavaDoc;
12
13 /**
14  * Override StandardMetaDataImpl in order to redefine the caching
15  * of MBean Information in StandardMBean.
16  *
17  * @since 1.6
18  */

19 public final class StandardMBeanMetaDataImpl extends StandardMetaDataImpl {
20
21     private final StandardMBean JavaDoc mbean;
22
23     /**
24      * Constructor.
25      */

26     public StandardMBeanMetaDataImpl(StandardMBean JavaDoc mbean) {
27         super(false);
28         this.mbean = mbean;
29     }
30
31     /**
32      * We need to override this method because some methods
33      * from BaseMetaDataImpl rely on MetaData#getMBeanInfo().
34      * <p>
35      * The default caching implemented in StandardMetaDataImpl
36      * will not work if two instances of class <var>c</var>
37      * can have different management interfaces, which is
38      * made possible by {@link javax.management.StandardMBean}.
39      *
40      * @return mbean.getMBeanInfo();
41      */

42     MBeanInfo JavaDoc getCachedMBeanInfo(Class JavaDoc beanClass) {
43
44         if (beanClass == null) return null;
45
46         // Need the synchronized block as long as implementation
47
// and mbeanInterface are not final.
48
//
49
synchronized (mbean) {
50             // Consistency checking: beanClass must be equal
51
// to mbean.getImplementationClass().
52
//
53
final Class JavaDoc implementationClass =
54                 mbean.getImplementationClass();
55             if (implementationClass == null) return null;
56             if (!beanClass.equals(implementationClass)) return null;
57
58             // Should always come here (null cases excepted)...
59
//
60
return mbean.getMBeanInfo();
61         }
62     }
63
64     /**
65      * We need to override this method because some methods
66      * from StandardMetaDataImpl rely on it.
67      * <p>
68      * The default caching implemented in StandardMetaDataImpl
69      * will not work if two instances of class <var>c</var>
70      * can have different management interfaces, which is
71      * made possible by {@link javax.management.StandardMBean}.
72      *
73      * @return mbean.getMBeanInterface();
74      */

75     Class JavaDoc getCachedMBeanInterface(Class JavaDoc beanClass) {
76         // Need the synchronized block as long as implementation
77
// and mbeanInterface are not final.
78
//
79
synchronized (mbean) {
80             // Consistency checking: beanClass must be equal
81
// to mbean.getImplementationClass().
82
//
83
final Class JavaDoc implementationClass =
84                 mbean.getImplementationClass();
85             if (implementationClass == null) return null;
86             if (!beanClass.equals(implementationClass)) return null;
87
88             // Should always come here (null cases excepted)...
89
//
90
return mbean.getMBeanInterface();
91         }
92     }
93
94     /**
95      * Need to override this method because default caching implemented
96      * in StandardMetaDataImpl will not work if two instances of class
97      * <var>c</var> can have different <var>mbeanInterface</var>.
98      * <p>
99      * The default caching mechanism in StandardMetaDataImpl uses
100      * class static {@link java.util.WeakHashMap WeakHashMaps} - and
101      * is common to all instance of StandardMetaData - hence to
102      * all MBeanServer.
103      * <p>
104      * As this default mechanism might not always work for
105      * StandardMBean objects (may have several instances of class
106      * <var>c</var> with different MBean interfaces), we disable
107      * this default caching by defining an empty
108      * <code>cacheMBeanInfo()</code> method.
109      * <p>
110      * Caching in our case is no longer performed by the MetaData
111      * object, but by the StandardMBean object.
112      */

113     void cacheMBeanInfo(Class JavaDoc c, Class JavaDoc mbeanInterface, MBeanInfo JavaDoc mbeanInfo) {
114     }
115 }
116
Popular Tags