1 23 24 31 package com.sun.enterprise.admin.monitor; 32 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 import java.util.Map ; 37 38 import javax.management.AttributeList ; 39 import javax.management.AttributeNotFoundException ; 40 import javax.management.InstanceAlreadyExistsException ; 41 import javax.management.MBeanInfo ; 42 import javax.management.MBeanRegistrationException ; 43 import javax.management.ObjectName ; 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 import com.sun.enterprise.util.i18n.StringManager; 51 52 57 public class GenericMonitorMBean extends BaseMonitorMBean { 58 59 62 private static GenericMonitorMBean root; 63 64 67 private static MBeanInfo genericMBeanInfo = null; 68 69 private static StringManager localStrings = 71 StringManager.getManager( GenericMonitorMBean.class ); 72 73 76 public GenericMonitorMBean() { 77 } 78 79 84 public Object getAttribute(String str) throws AttributeNotFoundException { 85 String msg = localStrings.getString( "admin.monitor.unknown_attribute", str ); 86 throw new AttributeNotFoundException ( msg ); 87 } 88 89 95 public MonitoredAttributeType getAttributeType(String str) { 96 String msg = localStrings.getString( "admin.monitor.unsupported_getattributetype" ); 97 throw new UnsupportedOperationException ( msg ); 98 } 99 100 107 public AttributeList getAttributes(String [] str) { 108 return new AttributeList (); 109 } 110 111 117 public MBeanInfo getMBeanInfo() { 118 if (genericMBeanInfo == null) { 119 genericMBeanInfo = createMBeanInfo(new HashMap ()); 120 } 121 return genericMBeanInfo; 122 } 123 124 134 public Map getMonitoringMetaData() { 135 return new HashMap (); 136 } 137 138 143 public void startMonitoring() { 144 Iterator iter = childList.iterator(); 145 while (iter.hasNext()) { 146 BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next(); 147 mBean.startMonitoring(); 148 } 149 } 150 151 156 public void stopMonitoring() { 157 Iterator iter = childList.iterator(); 158 while (iter.hasNext()) { 159 BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next(); 160 mBean.stopMonitoring(); 161 } 162 } 163 164 172 public void startMonitoring(MonitoredObjectType[] typeList) { 173 HashMap typeMap = getMonitoredObjectTypeMap(typeList); 174 startMonitoring(typeMap); 175 } 176 177 185 public void stopMonitoring(MonitoredObjectType[] typeList) { 186 HashMap typeMap = getMonitoredObjectTypeMap(typeList); 187 stopMonitoring(typeMap); 188 } 189 190 195 private void startMonitoring(HashMap typeMap) { 196 Iterator 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 214 private void stopMonitoring(HashMap typeMap) { 215 Iterator 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 232 private HashMap getMonitoredObjectTypeMap(MonitoredObjectType[] typeList) { 233 HashMap map = new HashMap (); 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 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 instName = AdminService.getAdminService().getInstanceName(); 251 ObjectName objName = ObjectNames.getRootMonitorMBeanName(instName); 252 objectNameMap.put(objName, root); 253 root.setObjectName(objName); 254 } 255 return root; 256 } 257 258 } 259 | Popular Tags |