1 23 24 38 39 package com.sun.enterprise.admin.monitor.registry.spi.reconfig; 40 41 import java.util.Collection ; 42 import java.util.Map ; 43 import java.util.HashMap ; 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 ; 48 import javax.management.MBeanServer ; 49 import javax.management.MalformedObjectNameException ; 50 import java.util.logging.Logger ; 51 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 59 import com.sun.enterprise.admin.common.constant.AdminConstants; 60 import com.sun.enterprise.util.i18n.StringManager; 61 66 public class MonitoringConfigurationHandler { 67 68 private static Logger 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; 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); 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); else if (objType == MonitoredObjectType.SERVLET) 103 level = getLevelFor(MonitoringConfigChangeListener.WEB_CONTAINER); else if (objType == MonitoredObjectType.WEBMODULE) 105 level = getLevelFor(MonitoringConfigChangeListener.WEB_CONTAINER); else if (objType == MonitoredObjectType.CONNECTOR_CONN_POOL || 107 objType == MonitoredObjectType.CONNECTOR_WORKMGMT || 108 objType == MonitoredObjectType.JMS_SERVICE) 109 level = getLevelFor(MonitoringConfigChangeListener.CONNECTOR_SERVICE); else if (objType == MonitoredObjectType.JDBC_CONN_POOL) 111 level = getLevelFor(MonitoringConfigChangeListener.JDBC_CONN_POOL); 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); else if (objType == MonitoredObjectType.THREAD_POOL) 119 level = getLevelFor(MonitoringConfigChangeListener.THREAD_POOL); else if (objType == MonitoredObjectType.TRANSACTION_SERVICE) 121 level = getLevelFor(MonitoringConfigChangeListener.TRANSACTION_SERVICE); 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 141 private static MonitoringLevel getLevelFor(String 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 return MonitoringLevel.LOW; 168 } 169 logger.finer("No configuration in domain.xml for the string: " + name); 170 return ( null ); 171 } 172 173 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 e) { 190 return ( null ); 191 } 193 } 194 static MonitoringLevel string2Level(String s) { 195 final MonitoringLevel l = MonitoringLevel.instance(s); 196 if (s == null) { 197 final String msg = sm.getString("mch.invalid_monitoring_level", s); 198 throw new RuntimeException (msg); 199 } 200 return ( l ); 201 } 202 static MonitoringLevel getEjbContainerLevel() { 203 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getEjbContainer(); 204 logger.finer("EjbContainer monitoring-level = " + l); 205 return ( string2Level(l) ); 206 } 207 static MonitoringLevel getWebContainerLevel() { 208 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getWebContainer(); 209 logger.finer("WebContainer monitoring-level = " + l); 210 return ( string2Level(l) ); 211 } 212 static MonitoringLevel getJdbcConnectionPoolLevel() { 213 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getJdbcConnectionPool(); 214 logger.finer("JdbcConnectionPoolLevel monitoring-level = " + l); 215 return ( string2Level(l) ); 216 } 217 static MonitoringLevel getConnectorConnectionPoolLevel() { 218 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getConnectorConnectionPool(); 219 logger.finer("ConnectorConnectionPoolLevel monitoring-level = " + l); 220 return ( string2Level(l) ); 221 } 222 static MonitoringLevel getTransactionServiceLevel() { 223 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getTransactionService(); 224 logger.finer("TransactionService monitoring-level = " + l); 225 return ( string2Level(l) ); 226 } 227 static MonitoringLevel getHttpServiceLevel() { 228 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getHttpService(); 229 logger.finer("HttpService monitoring-level = " + l); 230 return ( string2Level(l) ); 231 } 232 static MonitoringLevel getOrbLevel() { 233 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getOrb(); 234 logger.finer("Orb monitoring-level = " + l); 235 return ( string2Level(l) ); 236 } 237 static MonitoringLevel getThreadPoolLevel() { 238 final String 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 l = getCfg().getMonitoringService().getModuleMonitoringLevels().getConnectorService(); 244 logger.finer("ConnectorServiceLevel monitoring-level = " + l); 245 return ( string2Level(l) ); 246 } 247 static MonitoringLevel getJvmLevel() { 248 final String l = getCfg().getMonitoringService().getModuleMonitoringLevels().getJvm(); 249 logger.finer("Jvm monitoring-level = " + l); 250 return ( string2Level(l) ); 251 } 252 } 253 254 } 255 | Popular Tags |