1 29 30 package com.caucho.jmx; 31 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import javax.management.*; 36 import java.util.logging.Logger ; 37 38 41 class MBeanWrapper implements DynamicMBean { 42 private static L10N L = new L10N(MBeanWrapper.class); 43 private static Logger log = Log.open(MBeanWrapper.class); 44 45 private MBeanContext _context; 46 47 private ObjectName _name; 48 49 protected Object _object; 50 protected DynamicMBean _mbean; 51 52 private ObjectInstance _instance; 53 54 protected MBeanWrapper(MBeanContext context, 55 ObjectName name, 56 Object object, 57 DynamicMBean mbean) 58 { 59 _context = context; 60 61 _name = name; 62 63 _object = object; 64 _mbean = mbean; 65 } 66 67 70 public ObjectInstance getObjectInstance() 71 { 72 if (_instance == null) 73 _instance = new ObjectInstance(_name, getMBeanInfo().getClassName()); 74 75 return _instance; 76 } 77 78 81 MBeanContext getContext() 82 { 83 return _context; 84 } 85 86 89 Object getObject() 90 { 91 return _object; 92 } 93 94 97 private NotificationBroadcaster getBroadcaster() 98 { 99 return (NotificationBroadcaster) _object; 100 } 101 102 105 private NotificationEmitter getEmitter() 106 { 107 return (NotificationEmitter) _object; 108 } 109 110 113 public ObjectName getObjectName() 114 { 115 return _name; 116 } 117 118 121 public ClassLoader getClassLoader() 122 { 123 return _context.getClassLoader(); 124 } 125 126 129 public MBeanInfo getMBeanInfo() 130 { 131 return _mbean.getMBeanInfo(); 132 } 133 134 137 public Object getAttribute(String name) 138 throws ReflectionException, AttributeNotFoundException, MBeanException 139 { 140 return _mbean.getAttribute(name); 141 } 142 143 146 public AttributeList getAttributes(String []names) 147 { 148 return _mbean.getAttributes(names); 149 } 150 151 154 public void setAttribute(Attribute attr) 155 throws ReflectionException, 156 AttributeNotFoundException, 157 InvalidAttributeValueException, 158 MBeanException 159 { 160 _mbean.setAttribute(attr); 161 } 162 163 166 public AttributeList setAttributes(AttributeList list) 167 { 168 return _mbean.setAttributes(list); 169 } 170 171 174 public Object invoke(String operation, 175 Object []params, 176 String []signature) 177 throws ReflectionException, MBeanException 178 { 179 return _mbean.invoke(operation, params, signature); 180 } 181 182 185 public NotificationListener getListener() 186 { 187 Object obj = getObject(); 188 189 if (obj instanceof NotificationListener) 190 return (NotificationListener) obj; 191 else 192 return null; 193 } 194 195 198 public void addNotificationListener(NotificationListener listener, 199 NotificationFilter filter, 200 Object handback) 201 { 202 getBroadcaster().addNotificationListener(listener, filter, handback); 203 } 204 205 208 public void removeNotificationListener(NotificationListener listener) 209 throws ListenerNotFoundException 210 { 211 getBroadcaster().removeNotificationListener(listener); 212 } 213 214 217 public void removeNotificationListener(NotificationListener listener, 218 NotificationFilter filter, 219 Object handback) 220 throws ListenerNotFoundException 221 { 222 Object obj = getObject(); 223 224 if (obj instanceof NotificationEmitter) 225 getEmitter().removeNotificationListener(listener, filter, handback); 226 else 227 getBroadcaster().removeNotificationListener(listener); 228 } 229 } 230 | Popular Tags |