1 15 package org.apache.hivemind.management.mbeans; 16 17 import javax.management.Attribute ; 18 import javax.management.AttributeList ; 19 import javax.management.AttributeNotFoundException ; 20 import javax.management.DynamicMBean ; 21 import javax.management.InvalidAttributeValueException ; 22 import javax.management.MBeanAttributeInfo ; 23 import javax.management.MBeanConstructorInfo ; 24 import javax.management.MBeanException ; 25 import javax.management.MBeanInfo ; 26 import javax.management.MBeanNotificationInfo ; 27 import javax.management.MBeanOperationInfo ; 28 import javax.management.MBeanRegistration ; 29 import javax.management.MBeanServer ; 30 import javax.management.ObjectName ; 31 import javax.management.ReflectionException ; 32 33 40 public abstract class AbstractDynamicMBean implements MBeanRegistration , DynamicMBean 41 { 42 43 private MBeanInfo _mBeanInfo; 44 45 private MBeanServer _mbeanServer; 46 47 50 public MBeanInfo getMBeanInfo() 51 { 52 if (_mBeanInfo == null) 53 setMBeanInfo(createMBeanInfo()); 54 return _mBeanInfo; 55 } 56 57 63 protected void setMBeanInfo(MBeanInfo info) 64 { 65 _mBeanInfo = info; 66 } 67 68 73 private MBeanInfo createMBeanInfo() 74 { 75 MBeanAttributeInfo attrs[] = createMBeanAttributeInfo(); 76 MBeanConstructorInfo ctors[] = createMBeanConstructorInfo(); 77 MBeanOperationInfo opers[] = createMBeanOperationInfo(); 78 MBeanNotificationInfo notifs[] = createMBeanNotificationInfo(); 79 String className = getMBeanClassName(); 80 String description = getMBeanDescription(); 81 return new MBeanInfo (className, description, attrs, ctors, opers, notifs); 82 } 83 84 87 protected MBeanAttributeInfo [] createMBeanAttributeInfo() 88 { 89 return null; 90 } 91 92 95 protected MBeanConstructorInfo [] createMBeanConstructorInfo() 96 { 97 return null; 98 } 99 100 104 protected MBeanOperationInfo [] createMBeanOperationInfo() 105 { 106 return null; 107 } 108 109 113 protected MBeanNotificationInfo [] createMBeanNotificationInfo() 114 { 115 return null; 116 } 117 118 protected String getMBeanClassName() 119 { 120 return getClass().getName(); 121 } 122 123 126 protected String getMBeanDescription() 127 { 128 return null; 129 } 130 131 134 public Object getAttribute(String name) throws AttributeNotFoundException , MBeanException , 135 ReflectionException 136 { 137 return null; 138 } 139 140 143 public void setAttribute(Attribute attribute) throws AttributeNotFoundException , 144 InvalidAttributeValueException , MBeanException , ReflectionException 145 { 146 } 147 148 153 public AttributeList getAttributes(String [] attributes) 154 { 155 AttributeList list = new AttributeList (); 156 if (attributes != null) 157 { 158 for (int i = 0; i < attributes.length; i++) 159 { 160 String attribute = attributes[i]; 161 try 162 { 163 Object result = getAttribute(attribute); 164 list.add(new Attribute (attribute, result)); 165 } 166 catch (AttributeNotFoundException ignored) 167 { 168 } 169 catch (MBeanException ignored) 170 { 171 } 172 catch (ReflectionException ignored) 173 { 174 } 175 } 176 177 } 178 return list; 179 } 180 181 184 public AttributeList setAttributes(AttributeList attributes) 185 { 186 AttributeList list = new AttributeList (); 187 188 if (attributes != null) 189 { 190 for (int i = 0; i < attributes.size(); ++i) 191 { 192 Attribute attribute = (Attribute ) attributes.get(i); 193 try 194 { 195 setAttribute(attribute); 196 list.add(attribute); 197 } 198 catch (AttributeNotFoundException ignored) 199 { 200 } 201 catch (InvalidAttributeValueException ignored) 202 { 203 } 204 catch (MBeanException ignored) 205 { 206 } 207 catch (ReflectionException ignored) 208 { 209 } 210 } 211 } 212 213 return list; 214 } 215 216 220 public Object invoke(String method, Object [] arguments, String [] params) throws MBeanException , 221 ReflectionException 222 { 223 return null; 224 } 225 226 public ObjectName preRegister(MBeanServer mbeanserver, ObjectName objectname) 227 { 228 _mbeanServer = mbeanserver; 229 return objectname; 230 } 231 232 public void postRegister(Boolean registrationDone) 233 { 234 } 235 236 public void preDeregister() throws Exception 237 { 238 } 239 240 public void postDeregister() 241 { 242 } 243 244 protected MBeanServer getMBeanServer() 245 { 246 return _mbeanServer; 247 } 248 249 250 } 251 | Popular Tags |