1 8 9 package mx4j.server.interceptor; 10 11 import java.util.List ; 12 13 import javax.management.Attribute ; 14 import javax.management.AttributeList ; 15 import javax.management.AttributeNotFoundException ; 16 import javax.management.InvalidAttributeValueException ; 17 import javax.management.ListenerNotFoundException ; 18 import javax.management.MBeanException ; 19 import javax.management.MBeanInfo ; 20 import javax.management.MBeanRegistrationException ; 21 import javax.management.NotificationFilter ; 22 import javax.management.NotificationListener ; 23 import javax.management.ReflectionException ; 24 25 import mx4j.ImplementationException; 26 import mx4j.log.Log; 27 import mx4j.log.Logger; 28 import mx4j.server.MBeanMetaData; 29 30 36 public abstract class DefaultMBeanServerInterceptor implements MBeanServerInterceptor, DefaultMBeanServerInterceptorMBean 37 { 38 private boolean enabled = true; 39 private String logCategory; 40 private List chain; 41 42 protected DefaultMBeanServerInterceptor() 43 { 44 logCategory = getClass().getName() + "." + getType(); 46 } 47 48 52 public boolean isEnabled() 53 { 54 return enabled; 55 } 56 57 61 public void setEnabled(boolean enabled) 62 { 63 this.enabled = enabled; 64 } 65 66 69 public abstract String getType(); 70 71 protected synchronized MBeanServerInterceptor getNext() 72 { 73 int index = chain.indexOf(this); 74 MBeanServerInterceptor next = (MBeanServerInterceptor)chain.get(index + 1); 75 next.setChain(chain); 76 return next; 77 } 78 79 public synchronized void setChain(List chain) 80 { 81 this.chain = chain; 82 } 83 84 protected Logger getLogger() 85 { 86 return Log.getLogger(logCategory); 87 } 88 89 public void addNotificationListener(MBeanMetaData metadata, NotificationListener listener, NotificationFilter filter, Object handback) 90 { 91 getNext().addNotificationListener(metadata, listener, filter, handback); 92 } 93 94 public void removeNotificationListener(MBeanMetaData metadata, NotificationListener listener) throws ListenerNotFoundException 95 { 96 getNext().removeNotificationListener(metadata, listener); 97 } 98 99 public void removeNotificationListener(MBeanMetaData metadata, NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException 100 { 101 getNext().removeNotificationListener(metadata, listener, filter, handback); 102 } 103 104 public void instantiate(MBeanMetaData metadata, String className, String [] params, Object [] args) throws ReflectionException , MBeanException 105 { 106 getNext().instantiate(metadata, className, params, args); 107 } 108 109 public void registration(MBeanMetaData metadata, int operation) throws MBeanRegistrationException 110 { 111 getNext().registration(metadata, operation); 112 } 113 114 public MBeanInfo getMBeanInfo(MBeanMetaData metadata) 115 { 116 return getNext().getMBeanInfo(metadata); 117 } 118 119 public Object invoke(MBeanMetaData metadata, String method, String [] params, Object [] args) throws MBeanException , ReflectionException 120 { 121 return getNext().invoke(metadata, method, params, args); 122 } 123 124 public AttributeList getAttributes(MBeanMetaData metadata, String [] attributes) 125 { 126 return getNext().getAttributes(metadata, attributes); 127 } 128 129 public AttributeList setAttributes(MBeanMetaData metadata, AttributeList attributes) 130 { 131 return getNext().setAttributes(metadata, attributes); 132 } 133 134 public Object getAttribute(MBeanMetaData metadata, String attribute) throws MBeanException , AttributeNotFoundException , ReflectionException 135 { 136 return getNext().getAttribute(metadata, attribute); 137 } 138 139 public void setAttribute(MBeanMetaData metadata, Attribute attribute) throws MBeanException , AttributeNotFoundException , InvalidAttributeValueException , ReflectionException 140 { 141 getNext().setAttribute(metadata, attribute); 142 } 143 } 144 | Popular Tags |