1 7 package com.sun.jmx.mbeanserver; 8 9 import javax.management.ObjectName ; 10 import javax.management.MBeanServer ; 11 import javax.management.MBeanRegistration ; 12 import javax.management.DynamicMBean ; 13 import javax.management.AttributeNotFoundException ; 14 import javax.management.MBeanException ; 15 import javax.management.ReflectionException ; 16 import javax.management.MBeanAttributeInfo ; 17 import javax.management.MBeanInfo ; 18 import javax.management.MBeanNotificationInfo ; 19 import javax.management.JMRuntimeException ; 20 import javax.management.InvalidAttributeValueException ; 21 import javax.management.Attribute ; 22 import javax.management.AttributeList ; 23 import javax.management.RuntimeOperationsException ; 24 25 26 import com.sun.jmx.defaults.ServiceName; 27 import com.sun.jmx.trace.Trace; 28 29 34 final class MBeanServerDelegateImpl 35 extends javax.management.MBeanServerDelegate 36 implements DynamicMBean , MBeanRegistration { 37 38 39 private final static String dbgTag = "MBeanServerDelegateImpl"; 40 41 final private static String [] attributeNames = new String [] { 42 "MBeanServerId", 43 "SpecificationName", 44 "SpecificationVersion", 45 "SpecificationVendor", 46 "ImplementationName", 47 "ImplementationVersion", 48 "ImplementationVendor" 49 }; 50 51 private static final MBeanAttributeInfo [] attributeInfos = 52 new MBeanAttributeInfo [] { 53 new MBeanAttributeInfo ("MBeanServerId","java.lang.String", 54 "The MBean server agent identification", 55 true,false,false), 56 new MBeanAttributeInfo ("SpecificationName","java.lang.String", 57 "The full name of the JMX specification "+ 58 "implemented by this product.", 59 true,false,false), 60 new MBeanAttributeInfo ("SpecificationVersion","java.lang.String", 61 "The version of the JMX specification "+ 62 "implemented by this product.", 63 true,false,false), 64 new MBeanAttributeInfo ("SpecificationVendor","java.lang.String", 65 "The vendor of the JMX specification "+ 66 "implemented by this product.", 67 true,false,false), 68 new MBeanAttributeInfo ("ImplementationName","java.lang.String", 69 "The JMX implementation name "+ 70 "(the name of this product)", 71 true,false,false), 72 new MBeanAttributeInfo ("ImplementationVersion","java.lang.String", 73 "The JMX implementation version "+ 74 "(the version of this product).", 75 true,false,false), 76 new MBeanAttributeInfo ("ImplementationVendor","java.lang.String", 77 "the JMX implementation vendor "+ 78 "(the vendor of this product).", 79 true,false,false) 80 }; 81 82 private final MBeanInfo delegateInfo; 83 84 public MBeanServerDelegateImpl () { 85 super(); 86 delegateInfo = 87 new MBeanInfo ("javax.management.MBeanServerDelegate", 88 "Represents the MBean server from the management "+ 89 "point of view.", 90 MBeanServerDelegateImpl.attributeInfos, null, 91 null,getNotificationInfo()); 92 } 93 94 final public ObjectName preRegister (MBeanServer server, ObjectName name) 95 throws java.lang.Exception { 96 if (name == null) return new ObjectName (ServiceName.DELEGATE); 97 else return name; 98 } 99 100 final public void postRegister (Boolean registrationDone) { 101 } 102 103 final public void preDeregister() 104 throws java.lang.Exception { 105 throw new IllegalArgumentException ( 106 "The MBeanServerDelegate MBean cannot be unregistered"); 107 } 108 109 final public void postDeregister() { 110 } 111 112 124 public Object getAttribute(String attribute) 125 throws AttributeNotFoundException , 126 MBeanException , ReflectionException { 127 try { 128 if (attribute == null) 131 throw new AttributeNotFoundException ("null"); 132 133 if (attribute.equals("MBeanServerId")) 136 return getMBeanServerId(); 137 else if (attribute.equals("SpecificationName")) 138 return getSpecificationName(); 139 else if (attribute.equals("SpecificationVersion")) 140 return getSpecificationVersion(); 141 else if (attribute.equals("SpecificationVendor")) 142 return getSpecificationVendor(); 143 else if (attribute.equals("ImplementationName")) 144 return getImplementationName(); 145 else if (attribute.equals("ImplementationVersion")) 146 return getImplementationVersion(); 147 else if (attribute.equals("ImplementationVendor")) 148 return getImplementationVendor(); 149 150 else 153 throw new AttributeNotFoundException ("null"); 154 155 } catch (AttributeNotFoundException x) { 156 throw x; 157 } catch (JMRuntimeException j) { 158 throw j; 159 } catch (SecurityException s) { 160 throw s; 161 } catch (Exception x) { 162 throw new MBeanException (x,"Failed to get " + attribute); 163 } 164 } 165 166 175 public void setAttribute(Attribute attribute) 176 throws AttributeNotFoundException , InvalidAttributeValueException , 177 MBeanException , ReflectionException { 178 179 final String attname = (attribute==null?null:attribute.getName()); 184 if (attname == null) { 185 final RuntimeException r = 186 new IllegalArgumentException ("Attribute name cannot be null"); 187 throw new RuntimeOperationsException (r, 188 "Exception occured trying to invoke the setter on the MBean"); 189 } 190 191 Object val = getAttribute(attname); 195 196 throw new AttributeNotFoundException (attname + " not accessible"); 201 } 202 203 212 public AttributeList getAttributes(String [] attributes) { 213 final String [] attn = (attributes==null?attributeNames:attributes); 216 217 final int len = attn.length; 220 final AttributeList list = new AttributeList (len); 221 222 for (int i=0;i<len;i++) { 225 try { 226 final Attribute a = 227 new Attribute (attn[i],getAttribute(attn[i])); 228 list.add(a); 229 } catch (Exception x) { 230 debug("getAttributes","Attribute " + attn[i] + 233 " not found."); 234 } 235 } 236 237 return list; 240 } 241 242 253 public AttributeList setAttributes(AttributeList attributes) { 254 return new AttributeList (0); 255 } 256 257 274 public Object invoke(String actionName, Object params[], 275 String signature[]) 276 throws MBeanException , ReflectionException { 277 if (actionName == null) { 280 final RuntimeException r = 281 new IllegalArgumentException ("Operation name cannot be null"); 282 throw new RuntimeOperationsException (r, 283 "Exception occured trying to invoke the operation on the MBean"); 284 } 285 286 throw new ReflectionException ( 287 new NoSuchMethodException (actionName), 288 "The operation with name " + actionName + 289 " could not be found"); 290 } 291 292 298 public MBeanInfo getMBeanInfo() { 299 return delegateInfo; 300 } 301 302 305 private final static boolean isTraceOn() { 306 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER); 307 } 308 309 private final static void trace(String clz, String func, String info) { 310 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func, info); 311 } 312 313 private final static void trace(String func, String info) { 314 trace(dbgTag, func, info); 315 } 316 317 private final static boolean isDebugOn() { 318 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER); 319 } 320 321 private final static void debug(String clz, String func, String info) { 322 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func, info); 323 } 324 325 private final static void debug(String func, String info) { 326 debug(dbgTag, func, info); 327 } 328 329 330 } 331 | Popular Tags |