1 15 package org.apache.hivemind.management.mbeans; 16 17 import javax.management.Attribute ; 18 import javax.management.AttributeNotFoundException ; 19 import javax.management.InvalidAttributeValueException ; 20 import javax.management.MBeanAttributeInfo ; 21 import javax.management.MBeanConstructorInfo ; 22 import javax.management.MBeanException ; 23 import javax.management.MBeanNotificationInfo ; 24 import javax.management.MBeanOperationInfo ; 25 import javax.management.MBeanParameterInfo ; 26 import javax.management.ReflectionException ; 27 28 33 public class ConcreteMBean extends AbstractDynamicMBean 34 { 35 private String attribute1 = "value1"; 36 37 private String attribute2 = "value2"; 38 39 public boolean isSetAttribute1Called; 40 41 public boolean isSetAttribute2Called; 42 43 public ConcreteMBean() 44 { 45 } 46 47 protected MBeanAttributeInfo [] createMBeanAttributeInfo() 48 { 49 MBeanAttributeInfo att1 = new MBeanAttributeInfo ("attribute1", "String", "", true, 50 true, false); 51 MBeanAttributeInfo att2 = new MBeanAttributeInfo ("attribute2", "String", "", true, 52 true, false); 53 return new MBeanAttributeInfo [] 54 { att1, att2 }; 55 } 56 57 protected MBeanConstructorInfo [] createMBeanConstructorInfo() 58 { 59 MBeanConstructorInfo constructor = new MBeanConstructorInfo ("constructor", "", 60 new MBeanParameterInfo [] {}); 61 return new MBeanConstructorInfo [] 62 { constructor }; 63 } 64 65 protected MBeanNotificationInfo [] createMBeanNotificationInfo() 66 { 67 MBeanNotificationInfo notification = new MBeanNotificationInfo (new String [0], 68 "notification", ""); 69 return new MBeanNotificationInfo [] 70 { notification }; 71 } 72 73 protected MBeanOperationInfo [] createMBeanOperationInfo() 74 { 75 MBeanOperationInfo operation = new MBeanOperationInfo ("operation", "", 76 new MBeanParameterInfo [0], "String", 0); 77 return new MBeanOperationInfo [] 78 { operation }; 79 } 80 81 public Object getAttribute(String name) throws AttributeNotFoundException , MBeanException , 82 ReflectionException 83 { 84 if (name.equals("attribute1")) 85 return attribute1; 86 if (name.equals("attribute2")) 87 return attribute2; 88 throw new AttributeNotFoundException (); 89 } 90 91 public void setAttribute(Attribute attribute) throws AttributeNotFoundException , 92 InvalidAttributeValueException , MBeanException , ReflectionException 93 { 94 if (attribute.getName().equals("attribute1")) 95 attribute1 = (String ) attribute.getValue(); 96 if (attribute.getName().equals("attribute2")) 97 attribute2 = (String ) attribute.getValue(); 98 throw new AttributeNotFoundException (); 99 } 100 } 101 | Popular Tags |