1 23 24 package com.sun.enterprise.management.monitor; 25 26 import java.lang.reflect.Method ; 27 import java.lang.reflect.InvocationTargetException ; 28 29 import javax.management.ObjectName ; 30 import javax.management.MBeanServer ; 31 import javax.management.Attribute ; 32 import javax.management.MBeanAttributeInfo ; 33 import javax.management.MBeanException ; 34 import javax.management.ReflectionException ; 35 import javax.management.AttributeNotFoundException ; 36 import javax.management.InvalidAttributeValueException ; 37 import javax.management.monitor.Monitor ; 38 39 import com.sun.appserv.management.base.XTypes; 40 import com.sun.appserv.management.base.AMX; 41 import com.sun.appserv.management.base.Util; 42 import com.sun.appserv.management.monitor.JMXMonitorMgr; 43 44 import com.sun.enterprise.management.support.AMXImplBase; 45 import com.sun.enterprise.management.support.Delegate; 46 47 import com.sun.appserv.management.util.misc.ClassUtil; 48 import com.sun.appserv.management.util.jmx.JMXUtil; 49 50 51 54 public class JMXMonitorBase extends AMXImplBase 55 { 57 final Monitor mMonitor; 58 59 64 65 protected 66 JMXMonitorBase( final Monitor mon ) 67 { 68 mMonitor = mon; 69 } 70 71 72 73 public String 74 getGroup() 75 { 76 return( AMX.GROUP_UTILITY ); 77 } 78 79 80 protected Object 81 getAttributeManually( String name ) 82 throws AttributeNotFoundException 83 { 84 final MBeanAttributeInfo attrInfo = (MBeanAttributeInfo )getAttributeInfos().get( name ); 85 assert( attrInfo != null ); 87 final String prefix = attrInfo.isIs() ? JMXUtil.IS : JMXUtil.GET; 88 final String operationName = prefix + name; 89 90 Object result = null; 91 try 92 { 93 result = invokeManually( operationName, null, null ); 94 } 95 catch( Exception e ) 96 { 97 throw new AttributeNotFoundException ( name ); 98 } 99 100 return( result ); 101 } 102 103 protected void 104 setAttributeManually( final Attribute attr ) 105 throws AttributeNotFoundException , InvalidAttributeValueException 106 { 107 final String operationName = JMXUtil.SET + attr.getName(); 108 final MBeanAttributeInfo attrInfo = (MBeanAttributeInfo )getAttributeInfos().get( attr.getName() ); 109 110 Object result = null; 111 try 112 { 113 final Object value = attr.getValue(); 114 final Class theClass = ClassUtil.getClassFromName( attrInfo.getType() ); 116 117 result = invokeSig( operationName, 118 new Object [] { value }, new Class [] { theClass } ); 119 assert( result == null ); 120 } 121 catch( Exception e ) 122 { 123 throw new AttributeNotFoundException ( attr.getName() ); 124 } 125 } 126 127 private Object 128 invokeSig( 129 String operationName, 130 Object [] args, 131 Class [] sig ) 132 throws MBeanException , ReflectionException , NoSuchMethodException 133 { 134 Object result = null; 135 136 try 137 { 138 final Method m = mMonitor.getClass().getMethod( operationName, sig ); 139 140 result = m.invoke( mMonitor, args ); 141 } 142 catch( Exception e ) 143 { 144 throw new RuntimeException ( e ); 145 } 146 147 return( result ); 148 } 149 150 151 protected Object 152 invokeManually( 153 String operationName, 154 Object [] args, 155 String [] types ) 156 throws MBeanException , ReflectionException , NoSuchMethodException 157 { 158 Object result = null; 159 160 try 161 { 162 final Class [] sig = ClassUtil.signatureFromClassnames( types ); 163 164 result = invokeSig( operationName, args, sig ); 165 } 166 catch( Exception e ) 167 { 168 e.printStackTrace(); 169 throw new RuntimeException ( e ); 170 } 171 172 return( result ); 173 } 174 175 public void 176 preRegisterDone() 177 throws Exception 178 { 179 final ObjectName x = mMonitor.preRegister( getMBeanServer(), getObjectName() ); 180 } 181 182 public void 183 postRegisterHook( Boolean registrationDone ) 184 { 185 super.postRegisterHook( registrationDone ); 186 187 mMonitor.postRegister( registrationDone ); 188 } 189 190 public void 191 preDeregisterHook() 192 { 193 super.preDeregisterHook( ); 194 195 try 196 { 197 mMonitor.preDeregister( ); 198 } 199 catch( Exception e ) 200 { 201 throw new RuntimeException ( e ); 202 } 203 } 204 205 public void 206 postDeregisterHook() 207 { 208 super.postDeregisterHook( ); 209 210 mMonitor.postDeregister( ); 211 } 212 213 214 215 } 216 217 218 219 220 221 222 223 224 225 226 227 228 | Popular Tags |