1 23 24 38 39 package com.sun.enterprise.admin.monitor.registry.spi; 40 import javax.management.*; 42 import javax.management.j2ee.statistics.Stats ; 43 import javax.management.j2ee.statistics.*; 44 import java.util.*; 45 import java.util.logging.*; 46 import java.lang.reflect.*; 47 import java.lang.*; 48 49 54 public class GeneratedMonitoringMBeanImpl implements DynamicMBean { 55 MBeanInfo mbeanInfo; 56 Stats resourceInstance; 57 public static final String LOGGER_NAME="this.is.console"; 58 final Logger logger; 59 Hashtable attributeMap; 60 64 public GeneratedMonitoringMBeanImpl(Stats stats) { 65 logger = Logger.getLogger(LOGGER_NAME); 66 this.resourceInstance=stats; 67 attributeMap=new Hashtable(); 68 } 69 70 77 MBeanInfo introspect(){ 78 ManagedResourceIntrospector mri = new ManagedResourceIntrospector(this); 79 mbeanInfo = mri.introspect(this.resourceInstance); 80 setUpAttributeMap(); 81 return mbeanInfo; 82 } 83 87 private void setUpAttributeMap(){ 88 MBeanAttributeInfo[] attrInfo = mbeanInfo.getAttributes(); 89 String attr =null; 90 for(int i=0;i<attrInfo.length;i++){ 91 attr = attrInfo[i].getName(); 92 attributeMap.put(attr,attr); 93 } 94 } 95 96 112 public Object getAttribute(String str) 113 throws javax.management.AttributeNotFoundException , 114 javax.management.MBeanException , javax.management.ReflectionException { 115 if(str == null){ 116 throw new NullPointerException ("An attribute needs to be specified to get value"); 117 } 118 if(mbeanInfo == null){ 119 introspect(); 120 } 121 if(!isValidAttribute(str)){ 122 throw new AttributeNotFoundException("The requested attribute is not recognized"); 123 } 124 Statistic a = null; 125 Object retval=null; 126 String [] attrParts = AttributeStringHelper.splitAttribute(str); 127 logger.log(Level.INFO,"accessing the Stats object with attr="+attrParts[0]); 128 a = (Statistic)resourceInstance.getStatistic(attrParts[0]); 129 if(a == null){ 130 try{ 131 a = (Statistic)resourceInstance.getClass(). 132 getMethod("get"+str). 133 invoke(resourceInstance); 134 } 135 catch(Exception e){ 136 logger.log(Level.INFO,e.getLocalizedMessage()); 137 } 138 } 139 if(a != null){ 141 try{ 142 retval = a.getClass().getMethod("get"+attrParts[1]).invoke(a); 143 } 144 catch(Exception e){ 145 logger.log(Level.INFO,e.getLocalizedMessage()); 146 logger.log(Level.FINE,e.getStackTrace().toString()); 147 } 148 } 149 return retval; 150 } 151 152 157 private boolean isValidAttribute(String str){ 158 if(attributeMap.containsValue(str)) 159 return true; 160 return false; 161 } 162 163 169 public javax.management.AttributeList getAttributes(String [] str) { 170 if(mbeanInfo == null) 171 introspect(); 172 AttributeList list = new AttributeList(); 173 try{ 174 for(int i=0; i<str.length;i++){ 175 list.add(i, new Attribute(str[i],getAttribute(str[i]))); 176 } 177 } 178 catch(Exception e){ 179 logger.log(Level.INFO,e.getMessage()+"\n"+e.getCause().toString()); 180 } 181 return list; 182 } 183 184 190 public javax.management.MBeanInfo getMBeanInfo() { 191 if(mbeanInfo== null){ 192 introspect(); 193 } 194 return mbeanInfo; 195 } 196 197 public Object invoke(String str, Object [] obj, String [] str2) throws 198 javax.management.MBeanException , javax.management.ReflectionException { 199 if(mbeanInfo == null) 200 introspect(); 201 Object a =null; 202 Class [] c = new Class []{}; 203 for(int i=0; i<str2.length;i++){ 204 c[i] = str2[i].getClass(); 205 } 206 try{ 207 a = (Object ) resourceInstance.getClass().getMethod(str, c).invoke(resourceInstance, obj); 208 } 209 catch(Exception e){ 210 logger.log(Level.INFO,e.getLocalizedMessage()); 211 logger.log(Level.FINE,e.getStackTrace().toString()); 212 } 213 return a; 214 } 215 216 224 public void setAttribute(javax.management.Attribute attribute) throws 225 javax.management.AttributeNotFoundException , 226 javax.management.InvalidAttributeValueException , 227 javax.management.MBeanException , 228 javax.management.ReflectionException { } 229 230 236 public javax.management.AttributeList setAttributes( 237 javax.management.AttributeList attributeList) { 238 return new AttributeList(); 239 } 240 241 245 public String [] listAttributes(){ 246 return (String []) attributeMap.values().toArray(); 247 } 248 } 249 | Popular Tags |