1 7 8 package javax.management; 9 10 import com.sun.jmx.mbeanserver.Introspector; 11 import java.lang.reflect.InvocationHandler ; 12 import java.lang.reflect.Proxy ; 13 14 19 public class JMX { 20 23 static final JMX proof = new JMX (); 24 25 private JMX() {} 26 27 31 public static final String DEFAULT_VALUE_FIELD = "defaultValue"; 32 33 37 public static final String IMMUTABLE_INFO_FIELD = "immutableInfo"; 38 39 43 public static final String INTERFACE_CLASS_NAME_FIELD = "interfaceClassName"; 44 45 49 public static final String LEGAL_VALUES_FIELD = "legalValues"; 50 51 55 public static final String MAX_VALUE_FIELD = "maxValue"; 56 57 61 public static final String MIN_VALUE_FIELD = "minValue"; 62 63 67 public static final String MXBEAN_FIELD = "mxbean"; 68 69 73 public static final String OPEN_TYPE_FIELD = "openType"; 74 75 79 public static final String ORIGINAL_TYPE_FIELD = "originalType"; 80 81 144 public static <T> T newMBeanProxy(MBeanServerConnection connection, 145 ObjectName objectName, 146 Class <T> interfaceClass) { 147 return newMBeanProxy(connection, objectName, interfaceClass, false); 148 } 149 150 184 public static <T> T newMBeanProxy(MBeanServerConnection connection, 185 ObjectName objectName, 186 Class <T> interfaceClass, 187 boolean notificationBroadcaster) { 188 return MBeanServerInvocationHandler.newProxyInstance( 189 connection, 190 objectName, 191 interfaceClass, 192 notificationBroadcaster); 193 } 194 195 286 public static <T> T newMXBeanProxy(MBeanServerConnection connection, 287 ObjectName objectName, 288 Class <T> interfaceClass) { 289 return newMXBeanProxy(connection, objectName, interfaceClass, false); 290 } 291 292 326 public static <T> T newMXBeanProxy(MBeanServerConnection connection, 327 ObjectName objectName, 328 Class <T> interfaceClass, 329 boolean notificationBroadcaster) { 330 try { 333 Introspector.testComplianceMXBeanInterface(interfaceClass); 334 } catch (NotCompliantMBeanException e) { 335 throw new IllegalArgumentException (e); 336 } 337 InvocationHandler handler = new MBeanServerInvocationHandler ( 338 connection, objectName, true); 339 final Class [] interfaces; 340 if (notificationBroadcaster) { 341 interfaces = 342 new Class <?>[] {interfaceClass, NotificationEmitter .class}; 343 } else 344 interfaces = new Class [] {interfaceClass}; 345 Object proxy = Proxy.newProxyInstance( 346 interfaceClass.getClassLoader(), 347 interfaces, 348 handler); 349 return interfaceClass.cast(proxy); 350 } 351 352 366 public static boolean isMXBeanInterface(Class <?> interfaceClass) { 367 if (!interfaceClass.isInterface()) 368 return false; 369 MXBean a = interfaceClass.getAnnotation(MXBean .class); 370 if (a != null) 371 return a.value(); 372 return interfaceClass.getName().endsWith("MXBean"); 373 } 377 } 378 | Popular Tags |