KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > GenericMonitorMBean


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.monitor;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import javax.management.AttributeList JavaDoc;
39 import javax.management.AttributeNotFoundException JavaDoc;
40 import javax.management.InstanceAlreadyExistsException JavaDoc;
41 import javax.management.MBeanInfo JavaDoc;
42 import javax.management.MBeanRegistrationException JavaDoc;
43 import javax.management.ObjectName JavaDoc;
44
45 import com.sun.enterprise.admin.common.ObjectNames;
46 import com.sun.enterprise.admin.monitor.types.MonitoredAttributeType;
47 import com.sun.enterprise.admin.server.core.AdminService;
48
49 //i18n import
50
import com.sun.enterprise.util.i18n.StringManager;
51
52 /**
53  * A simple monitoring MBean. This monitoring MBean does not expose any
54  * monitorable attributes but is used only to group other monitoring MBeans
55  * that expose monitorable properties.
56  */

57 public class GenericMonitorMBean extends BaseMonitorMBean {
58
59     /**
60      * Root monitoring MBean.
61      */

62     private static GenericMonitorMBean root;
63
64     /**
65      * MBeanInfo for all generic MBeans, exposes no attributes.
66      */

67     private static MBeanInfo JavaDoc genericMBeanInfo = null;
68
69     // i18n StringManager
70
private static StringManager localStrings =
71         StringManager.getManager( GenericMonitorMBean.class );
72
73     /**
74      * Creates a new instance of GenericMonitorMBean
75      */

76     public GenericMonitorMBean() {
77     }
78
79     /**
80      * Get value of specified attribute. As there are no attributes exposed by
81      * this object, the method always throws AttributeNotFoundException.
82      * @throws AttributeNotFoundException always
83      */

84     public Object JavaDoc getAttribute(String JavaDoc str) throws AttributeNotFoundException JavaDoc {
85         String JavaDoc msg = localStrings.getString( "admin.monitor.unknown_attribute", str );
86         throw new AttributeNotFoundException JavaDoc( msg );
87     }
88
89     /**
90      * Get type of specified monitored attribute. As there are no attributes
91      * exposed by this object, the method always throws
92      * UnsupportedOperationException.
93      * @throws UnsupportedOperationException always.
94      */

95     public MonitoredAttributeType getAttributeType(String JavaDoc str) {
96         String JavaDoc msg = localStrings.getString( "admin.monitor.unsupported_getattributetype" );
97         throw new UnsupportedOperationException JavaDoc( msg );
98     }
99
100     /**
101      * Get the values of several attributes of the monitoring MBean. As there
102      * are no attributes exposed by this MBean, the method always returns a
103      * empty AttributeList.
104      * @param attributes A list of the attributes to be retrieved.
105      * @returns The list of attributes retrieved.
106      */

107     public AttributeList JavaDoc getAttributes(String JavaDoc[] str) {
108         return new AttributeList JavaDoc();
109     }
110
111     /**
112      * Provides the exposed attributes and actions of the monitoring MBean using
113      * an MBeanInfo object.
114      * @returns An instance of MBeanInfo with all attributes and actions exposed
115      * by this monitoring MBean.
116      */

117     public MBeanInfo JavaDoc getMBeanInfo() {
118         if (genericMBeanInfo == null) {
119             genericMBeanInfo = createMBeanInfo(new HashMap JavaDoc());
120         }
121         return genericMBeanInfo;
122     }
123
124     /**
125      * Get a map of monitored attribute names and their types. The keys in
126      * the map are names of the attribute and the values are their types. The
127      * type value are instances of class
128      * com.iplanet.ias.monitor.type.MonitoredAttributeType (or its sub-classes).
129      * As no attributes are exposed by this MBean, it always returns a empty
130      * map.
131      *
132      * @return map of names and types of all monitored attributes
133      */

134     public Map JavaDoc getMonitoringMetaData() {
135         return new HashMap JavaDoc();
136     }
137
138     /**
139      * Start monitoring on the resource represented by this MBean. This method
140      * starts monitoring on all child monitoring MBeans of this MBean by calling
141      * startMonitoring on them one after another.
142      */

143     public void startMonitoring() {
144         Iterator JavaDoc iter = childList.iterator();
145         while (iter.hasNext()) {
146             BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
147             mBean.startMonitoring();
148         }
149     }
150
151     /**
152      * Stop monitoring on the resource represented by this MBean. This method
153      * stops monitoring on all child monitoring MBeans of this MBean by calling
154      * stopMonitoring on them one after another.
155      */

156     public void stopMonitoring() {
157         Iterator JavaDoc iter = childList.iterator();
158         while (iter.hasNext()) {
159             BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
160             mBean.stopMonitoring();
161         }
162     }
163
164     /**
165      * Start monitoring on the resource represented by this MBean, if the type
166      * of this MBean is included in the type list. The method will also result
167      * in call to startMonitoring() of all child MBeans of the type included in
168      * the type list.
169      * @param typeList list of monitored object types on which monitoring is to
170      * be enabled.
171      */

172     public void startMonitoring(MonitoredObjectType[] typeList) {
173         HashMap JavaDoc typeMap = getMonitoredObjectTypeMap(typeList);
174         startMonitoring(typeMap);
175     }
176
177     /**
178      * Stop monitoring on the resource represented by this MBean, if the type
179      * of this MBean is included in the type list. The method will also result
180      * in call to startMonitoring() of all child MBeans of the type included in
181      * the type list.
182      * @param typeList list of monitored object types on which monitoring is to
183      * be enabled.
184      */

185     public void stopMonitoring(MonitoredObjectType[] typeList) {
186         HashMap JavaDoc typeMap = getMonitoredObjectTypeMap(typeList);
187         stopMonitoring(typeMap);
188     }
189
190     /**
191      * Start monitoring on all child mbeans whose type is included in the
192      * specified typeMap.
193      * @param typeName a map of type string and MonitoredObjectType instance
194      */

195     private void startMonitoring(HashMap JavaDoc typeMap) {
196         Iterator JavaDoc iter = childList.iterator();
197         while (iter.hasNext()) {
198             BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
199             if (typeMap.containsKey(mBean.getNodeType())) {
200                 if (mBean.getClass() == GenericMonitorMBean.class) {
201                     ((GenericMonitorMBean)mBean).startMonitoring(typeMap);
202                 } else {
203                     mBean.startMonitoring();
204                 }
205             }
206         }
207     }
208
209     /**
210      * Stop monitoring on all child mbeans whose type is included in the
211      * specified typeMap.
212      * @param typeName a map of type string and MonitoredObjectType instance
213      */

214     private void stopMonitoring(HashMap JavaDoc typeMap) {
215         Iterator JavaDoc iter = childList.iterator();
216         while (iter.hasNext()) {
217             BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
218             if (typeMap.containsKey(mBean.getNodeType())) {
219                 if (mBean.getClass() == GenericMonitorMBean.class) {
220                     ((GenericMonitorMBean)mBean).stopMonitoring(typeMap);
221                 } else {
222                     mBean.stopMonitoring();
223                 }
224             }
225         }
226     }
227
228     /**
229      * Get a map of type and MonitoredObjectType instances from the array of
230      * MonitoredObjectType instances.
231      */

232     private HashMap JavaDoc getMonitoredObjectTypeMap(MonitoredObjectType[] typeList) {
233         HashMap JavaDoc map = new HashMap JavaDoc();
234         int size = (typeList != null) ? typeList.length : 0;
235         for (int i = 0; i < size; i++) {
236             map.put(typeList[i].getTypeName(), typeList[i]);
237         }
238         return map;
239     }
240
241     /**
242      * Get root monitoring MBean. The root MBean is initialized when the
243      * server starts up and is available thereafter.
244      */

245     public static GenericMonitorMBean getRoot() {
246         if (root == null) {
247             root = new GenericMonitorMBean();
248             root.setNodeName(ObjectNames.kMonitoringRootClass);
249             root.setNodeType(ObjectNames.kMonitoringRootClass);
250             String JavaDoc instName = AdminService.getAdminService().getInstanceName();
251             ObjectName JavaDoc objName = ObjectNames.getRootMonitorMBeanName(instName);
252             objectNameMap.put(objName, root);
253             root.setObjectName(objName);
254         }
255         return root;
256     }
257
258 }
259
Popular Tags