KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > registry > spi > reconfig > MonitoringConfigurationHandler


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 /* MonitoringConfigurationHandler.java
25  * $Id: MonitoringConfigurationHandler.java,v 1.3 2005/12/25 03:43:40 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:43:40 $
28  * Indentation Information:
29  * 0. Please (try to) preserve these settings.
30  * 1. Tabs are preferred over spaces.
31  * 2. In vi/vim -
32  * :set tabstop=4 :set shiftwidth=4 :set softtabstop=4
33  * 3. In S1 Studio -
34  * 1. Tools->Options->Editor Settings->Java Editor->Tab Size = 4
35  * 2. Tools->Options->Indentation Engines->Java Indentation Engine->Expand Tabs to Spaces = False.
36  * 3. Tools->Options->Indentation Engines->Java Indentation Engine->Number of Spaces per Tab = 4.
37  */

38
39 package com.sun.enterprise.admin.monitor.registry.spi.reconfig;
40
41 import java.util.Collection JavaDoc;
42 import java.util.Map JavaDoc;
43 import java.util.HashMap JavaDoc;
44 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
45 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener;
46 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType;
47 import javax.management.ObjectName JavaDoc;
48 import javax.management.MBeanServer JavaDoc;
49 import javax.management.MalformedObjectNameException JavaDoc;
50 import java.util.logging.Logger JavaDoc;
51 //old way of getting the config information
52
import com.sun.enterprise.config.serverbeans.*;
53 import com.sun.enterprise.server.ServerContext;
54 import com.sun.enterprise.server.ApplicationServer;
55 import com.sun.enterprise.admin.event.AdminEvent;
56 import com.sun.enterprise.config.ConfigContext;
57 //old way of getting the config information
58

59 import com.sun.enterprise.admin.common.constant.AdminConstants;
60 import com.sun.enterprise.util.i18n.StringManager;
61 /**
62  * @author <a HREF="mailto:Kedar.Mhaswade@sun.com">Kedar Mhaswade</a>
63  * @since S1AS8.0
64  * @version $Revision: 1.3 $
65  */

66 public class MonitoringConfigurationHandler {
67     
68     private static Logger JavaDoc logger = Logger.getLogger(AdminConstants.kLoggerName);
69     private static StringManager sm = StringManager.getManager(MonitoringConfigurationHandler.class);
70     private MonitoringConfigurationHandler() {
71     }
72     
73     public static MonitoringLevel getLevel(MonitoredObjectType objType) {
74         MonitoringLevel level = null;
75         if (objType == MonitoredObjectType.APPLICATION ||
76         objType == MonitoredObjectType.EJBMODULE ||
77         objType == MonitoredObjectType.ROOT ||
78         objType == MonitoredObjectType.STANDALONE_EJBMODULE ||
79         objType == MonitoredObjectType.STANDALONE_WEBMODULE)
80             level = MonitoringLevel.HIGH; //actually does not matter
81
else if (objType == MonitoredObjectType.ENTITY_BEAN ||
82         objType == MonitoredObjectType.BEAN_CACHE ||
83         objType == MonitoredObjectType.BEAN_METHOD ||
84         objType == MonitoredObjectType.BEAN_POOL ||
85         objType == MonitoredObjectType.STATEFUL_BEAN ||
86         objType == MonitoredObjectType.STATELESS_BEAN ||
87         objType == MonitoredObjectType.MESSAGE_DRIVEN_BEAN ||
88         objType == MonitoredObjectType.BEAN_METHODS ||
89         objType == MonitoredObjectType.SESSION_STORE ||
90         objType == MonitoredObjectType.TIMERS)
91             level = getLevelFor(MonitoringConfigChangeListener.EJB_CONTAINER); // depends on config of ejb-container
92
else if (objType == MonitoredObjectType.HTTP_LISTENER ||
93         objType == MonitoredObjectType.VIRTUAL_SERVER ||
94         objType == MonitoredObjectType.REQUEST ||
95         objType == MonitoredObjectType.FILE_CACHE ||
96         objType == MonitoredObjectType.PWC_THREAD_POOL ||
97         objType == MonitoredObjectType.KEEP_ALIVE ||
98         objType == MonitoredObjectType.DNS ||
99         objType == MonitoredObjectType.CONNECTION_QUEUE ||
100         objType == MonitoredObjectType.HTTP_SERVICE)
101             return getLevelFor(MonitoringConfigChangeListener.HTTP_SERVICE); // depends on config of http-service
102
else if (objType == MonitoredObjectType.SERVLET)
103             level = getLevelFor(MonitoringConfigChangeListener.WEB_CONTAINER); // depends on config of web-container
104
else if (objType == MonitoredObjectType.WEBMODULE)
105             level = getLevelFor(MonitoringConfigChangeListener.WEB_CONTAINER); // depends on config of web-container
106
else if (objType == MonitoredObjectType.CONNECTOR_CONN_POOL ||
107                  objType == MonitoredObjectType.CONNECTOR_WORKMGMT ||
108                  objType == MonitoredObjectType.JMS_SERVICE)
109             level = getLevelFor(MonitoringConfigChangeListener.CONNECTOR_SERVICE); // depends on config connector-service
110
else if (objType == MonitoredObjectType.JDBC_CONN_POOL)
111             level = getLevelFor(MonitoringConfigChangeListener.JDBC_CONN_POOL); // depends on config of jdbc-pool
112
else if (objType == MonitoredObjectType.JVM)
113             level = getLevelFor(MonitoringConfigChangeListener.JVM);
114         else if (objType == MonitoredObjectType.ORB ||
115         objType == MonitoredObjectType.CONNECTION_MANAGERS ||
116         objType == MonitoredObjectType.CONNECTION_MANAGER)
117             level = getLevelFor(MonitoringConfigChangeListener.ORB); // depends on config of orb
118
else if (objType == MonitoredObjectType.THREAD_POOL)
119             level = getLevelFor(MonitoringConfigChangeListener.THREAD_POOL); // depends on config of threa-pool
120
else if (objType == MonitoredObjectType.TRANSACTION_SERVICE)
121             level = getLevelFor(MonitoringConfigChangeListener.TRANSACTION_SERVICE); // depends on config
122
else if (objType == MonitoredObjectType.JNDI)
123             level = getLevelFor(MonitoringConfigChangeListener.JNDI);
124         else if (objType == MonitoredObjectType.WEBSERVICE_ENDPOINT)
125             level =
126             getLevelFor(MonitoringConfigChangeListener.WEBSERVICE_ENDPOINT);
127         else
128             logger.finer("Received a MonitoringObjectType: " + objType + " for which there is no configuration in domain.xml - Returning NULL");
129         return ( level );
130     }
131
132     public static boolean shouldRegisterMBean(MonitoredObjectType type) {
133         final MonitoringLevel levelFromConfig = getLevel(type);
134
135         return ( levelFromConfig == MonitoringLevel.LOW || levelFromConfig == MonitoringLevel.HIGH );
136     }
137     /**
138      * Gets the MonitoringLevel the "old way" i.e. from Config Beans. This will
139      * have to change.
140      */

141     private static MonitoringLevel getLevelFor(String JavaDoc name) {
142         if (MonitoringConfigChangeListener.EJB_CONTAINER.equals(name))
143             return ( ConfigGetter.getEjbContainerLevel() );
144         else if (MonitoringConfigChangeListener.WEB_CONTAINER.equals(name))
145             return ( ConfigGetter.getWebContainerLevel() );
146         else if (MonitoringConfigChangeListener.HTTP_SERVICE.equals(name))
147             return ( ConfigGetter.getHttpServiceLevel() );
148         else if (MonitoringConfigChangeListener.TRANSACTION_SERVICE.equals(name))
149             return ( ConfigGetter.getTransactionServiceLevel() );
150         else if (MonitoringConfigChangeListener.ORB.equals(name))
151             return ( ConfigGetter.getOrbLevel() );
152         else if (MonitoringConfigChangeListener.THREAD_POOL.equals(name))
153             return ( ConfigGetter.getThreadPoolLevel() );
154         else if (MonitoringConfigChangeListener.JDBC_CONN_POOL.equals(name))
155             return ( ConfigGetter.getJdbcConnectionPoolLevel() );
156         else if (MonitoringConfigChangeListener.CONNECTOR_CONN_POOL.equals(name))
157             return ConfigGetter.getConnectorServiceLevel();
158         else if (MonitoringConfigChangeListener.CONNECTOR_SERVICE.equals(name))
159             return ConfigGetter.getConnectorServiceLevel();
160         else if (MonitoringConfigChangeListener.JMS_SERVICE.equals(name))
161             return ConfigGetter.getConnectorServiceLevel();
162         else if (MonitoringConfigChangeListener.JVM.equals(name))
163             return ConfigGetter.getJvmLevel();
164         else if (MonitoringConfigChangeListener.WEBSERVICE_ENDPOINT.equals(name)) {
165             // XXX read the config for this particular web service endpoint
166
// and return its monitoring level.
167
return MonitoringLevel.LOW;
168         }
169         logger.finer("No configuration in domain.xml for the string: " + name);
170         return ( null );
171     }
172     
173     /* Remove this entire inner class later - when (and if) we don't get the config from ConfigBeans */
174     private static final class ConfigGetter {
175         private static com.sun.enterprise.config.serverbeans.Config getCfg() {
176             try {
177                 AdminEvent event =
178                     MonitoringThreadContext.getEventFromThreadLocal();
179                 ConfigContext ctx = null;
180                 if (event != null) {
181                     ctx = event.getConfigContext();
182                 } else {
183                     ctx=ApplicationServer.getServerContext().getConfigContext();
184                 }
185                 final com.sun.enterprise.config.serverbeans.Config cfg =
186                                         ServerBeansFactory.getConfigBean(ctx);
187                 return ( cfg );
188             }
189             catch(Exception JavaDoc e) {
190                 return ( null );
191                 //squelch it?
192
}
193         }
194         static MonitoringLevel string2Level(String JavaDoc s) {
195             final MonitoringLevel l = MonitoringLevel.instance(s);
196             if (s == null) {
197                 final String JavaDoc msg = sm.getString("mch.invalid_monitoring_level", s);
198                 throw new RuntimeException JavaDoc(msg);
199             }
200             return ( l );
201         }
202         static MonitoringLevel getEjbContainerLevel() {
203             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getEjbContainer();
204             logger.finer("EjbContainer monitoring-level = " + l);
205             return ( string2Level(l) );
206         }
207         static MonitoringLevel getWebContainerLevel() {
208             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getWebContainer();
209             logger.finer("WebContainer monitoring-level = " + l);
210             return ( string2Level(l) );
211         }
212         static MonitoringLevel getJdbcConnectionPoolLevel() {
213             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getJdbcConnectionPool();
214             logger.finer("JdbcConnectionPoolLevel monitoring-level = " + l);
215             return ( string2Level(l) );
216         }
217         static MonitoringLevel getConnectorConnectionPoolLevel() {
218             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getConnectorConnectionPool();
219             logger.finer("ConnectorConnectionPoolLevel monitoring-level = " + l);
220             return ( string2Level(l) );
221         }
222         static MonitoringLevel getTransactionServiceLevel() {
223             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getTransactionService();
224             logger.finer("TransactionService monitoring-level = " + l);
225             return ( string2Level(l) );
226         }
227         static MonitoringLevel getHttpServiceLevel() {
228             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getHttpService();
229             logger.finer("HttpService monitoring-level = " + l);
230             return ( string2Level(l) );
231         }
232         static MonitoringLevel getOrbLevel() {
233             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getOrb();
234             logger.finer("Orb monitoring-level = " + l);
235             return ( string2Level(l) );
236         }
237         static MonitoringLevel getThreadPoolLevel() {
238             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getThreadPool();
239             logger.finer("Thread pool monitoring-level = " + l);
240             return ( string2Level(l) );
241         }
242         static MonitoringLevel getConnectorServiceLevel() {
243             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getConnectorService();
244             logger.finer("ConnectorServiceLevel monitoring-level = " + l);
245             return ( string2Level(l) );
246         }
247         static MonitoringLevel getJvmLevel() {
248             final String JavaDoc l = getCfg().getMonitoringService().getModuleMonitoringLevels().getJvm();
249             logger.finer("Jvm monitoring-level = " + l);
250             return ( string2Level(l) );
251         }
252     }
253     /* Remove this entire inner class later - when (and if) we don't get the config from ConfigBeans */
254 }
255
Popular Tags