1 22 package org.jboss.mx.mxbean; 23 24 import javax.management.Attribute ; 25 import javax.management.AttributeList ; 26 import javax.management.AttributeNotFoundException ; 27 import javax.management.DynamicMBean ; 28 import javax.management.InvalidAttributeValueException ; 29 import javax.management.ListenerNotFoundException ; 30 import javax.management.MBeanException ; 31 import javax.management.MBeanInfo ; 32 import javax.management.MBeanNotificationInfo ; 33 import javax.management.MBeanRegistration ; 34 import javax.management.MBeanServer ; 35 import javax.management.NotificationEmitter ; 36 import javax.management.NotificationFilter ; 37 import javax.management.NotificationListener ; 38 import javax.management.ObjectName ; 39 import javax.management.ReflectionException ; 40 41 47 public class MXBeanSupport implements DynamicMBean , MBeanRegistration , NotificationEmitter 48 { 49 50 private static final MBeanNotificationInfo [] NO_NOTIFICATIONS = new MBeanNotificationInfo [0]; 51 52 53 private DynamicMBean delegate; 54 55 56 private MBeanRegistration registration; 57 58 59 private NotificationEmitter emitter; 60 61 64 protected MXBeanSupport() 65 { 66 init(MXBeanUtils.createMXBean(this, null)); 67 } 68 69 74 protected MXBeanSupport(Class <?> mxbeanInterface) 75 { 76 init(MXBeanUtils.createMXBean(this, mxbeanInterface)); 77 } 78 79 public MBeanInfo getMBeanInfo() 80 { 81 return delegate.getMBeanInfo(); 82 } 83 84 public Object getAttribute(String attribute) throws AttributeNotFoundException , MBeanException , ReflectionException 85 { 86 return delegate.getAttribute(attribute); 87 } 88 89 public AttributeList getAttributes(String [] attributes) 90 { 91 return delegate.getAttributes(attributes); 92 } 93 94 public void setAttribute(Attribute attribute) throws AttributeNotFoundException , InvalidAttributeValueException , MBeanException , ReflectionException 95 { 96 delegate.setAttribute(attribute); 97 } 98 99 public AttributeList setAttributes(AttributeList attributes) 100 { 101 return delegate.setAttributes(attributes); 102 } 103 104 public Object invoke(String actionName, Object [] params, String [] signature) throws MBeanException , ReflectionException 105 { 106 return delegate.invoke(actionName, params, signature); 107 } 108 109 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception 110 { 111 return registration.preRegister(server, name); 112 } 113 114 public void postRegister(Boolean registrationDone) 115 { 116 registration.postDeregister(); 117 } 118 119 public void preDeregister() throws Exception 120 { 121 registration.preDeregister(); 122 } 123 124 public void postDeregister() 125 { 126 registration.postDeregister(); 127 } 128 129 public MBeanNotificationInfo [] getNotificationInfo() 130 { 131 return NO_NOTIFICATIONS; 132 } 133 134 public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException 135 { 136 emitter.addNotificationListener(listener, filter, handback); 137 138 } 139 140 public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException 141 { 142 emitter.removeNotificationListener(listener); 143 } 144 145 public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException 146 { 147 emitter.removeNotificationListener(listener, filter, handback); 148 } 149 150 155 private void init(DynamicMBean delegate) 156 { 157 this.delegate = delegate; 158 this.registration = (MBeanRegistration ) delegate; 159 this.emitter = (NotificationEmitter ) delegate; 160 } 161 } 162 | Popular Tags |