/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>This implementation checks for {@link javax.management.DynamicMBean} * classes as well as classes with corresponding "*MBean" interface * (Standard MBeans) or corresponding "*MXBean" interface (Java 6 MXBeans). * @param clazz the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.export.MBeanExporter#isMBean(Class) */ public static boolean isMBean(@Nullable Class<?> clazz) { return (clazz != null && (DynamicMBean.class.isAssignableFrom(clazz) || (getMBeanInterface(clazz) != null || getMXBeanInterface(clazz) != null))); }
/** * Return the Standard MBean interface for the given class, if any * (that is, an interface whose name matches the class name of the * given class but with suffix "MBean"). * @param clazz the class to check * @return the Standard MBean interface for the given class */ @Nullable public static Class<?> getMBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } String mbeanInterfaceName = clazz.getName() + MBEAN_SUFFIX; Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (iface.getName().equals(mbeanInterfaceName)) { return iface; } } return getMBeanInterface(clazz.getSuperclass()); }
/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>This implementation checks for {@link javax.management.DynamicMBean} * classes as well as classes with corresponding "*MBean" interface * (Standard MBeans) or corresponding "*MXBean" interface (Java 6 MXBeans). * @param clazz the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.export.MBeanExporter#isMBean(Class) */ public static boolean isMBean(@Nullable Class<?> clazz) { return (clazz != null && (DynamicMBean.class.isAssignableFrom(clazz) || (getMBeanInterface(clazz) != null || getMXBeanInterface(clazz) != null))); }
/** * Return the Standard MBean interface for the given class, if any * (that is, an interface whose name matches the class name of the * given class but with suffix "MBean"). * @param clazz the class to check * @return the Standard MBean interface for the given class */ @Nullable public static Class<?> getMBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } String mbeanInterfaceName = clazz.getName() + MBEAN_SUFFIX; Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (iface.getName().equals(mbeanInterfaceName)) { return iface; } } return getMBeanInterface(clazz.getSuperclass()); }
ifc = JmxUtils.getMBeanInterface(targetClass); if (ifc != null) { if (!ifc.isInstance(bean)) {
ifc = JmxUtils.getMBeanInterface(targetClass); if (ifc != null) { if (!ifc.isInstance(bean)) {
/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>This implementation checks for {@link javax.management.DynamicMBean} * classes as well as classes with corresponding "*MBean" interface * (Standard MBeans) or corresponding "*MXBean" interface (Java 6 MXBeans). * @param clazz the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.export.MBeanExporter#isMBean(Class) */ public static boolean isMBean(@Nullable Class<?> clazz) { return (clazz != null && (DynamicMBean.class.isAssignableFrom(clazz) || (getMBeanInterface(clazz) != null || getMXBeanInterface(clazz) != null))); }
/** * Return the Standard MBean interface for the given class, if any * (that is, an interface whose name matches the class name of the * given class but with suffix "MBean"). * @param clazz the class to check * @return the Standard MBean interface for the given class */ @Nullable public static Class<?> getMBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } String mbeanInterfaceName = clazz.getName() + MBEAN_SUFFIX; Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (iface.getName().equals(mbeanInterfaceName)) { return iface; } } return getMBeanInterface(clazz.getSuperclass()); }
private Class findJmxInterface(String beanKey, Class<?> beanClass) { Class cachedInterface = interfaceCache.get(beanKey); if (cachedInterface != null) { return cachedInterface; } Class mbeanInterface = JmxUtils.getMBeanInterface(beanClass); if (mbeanInterface != null) { // found with MBean ending interfaceCache.put(beanKey, mbeanInterface); return mbeanInterface; } Class[] ifaces = ClassUtils.getAllInterfacesForClass(beanClass); for (Class ifc : ifaces) { ManagedResource metadata = attributeSource.getManagedResource(ifc); if (metadata != null) { // found with @ManagedResource annotation interfaceCache.put(beanKey, ifc); return ifc; } } throw new IllegalArgumentException(String.format( "Bean %s doesn't implement management interfaces. Management interface should either follow naming scheme or be annotated by @ManagedResource", beanKey)); }
ifc = JmxUtils.getMBeanInterface(targetClass); if (ifc != null) { if (!ifc.isInstance(bean)) {