@Override public void afterPropertiesSet() { // If no server was provided then try to find one. This is useful in an environment // where there is already an MBeanServer loaded. if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } }
/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>The default implementation delegates to {@link JmxUtils#isMBean}, * which 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 beanClass the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.support.JmxUtils#isMBean(Class) */ protected boolean isMBean(@Nullable Class<?> beanClass) { return JmxUtils.isMBean(beanClass); }
@Override public ObjectName registerManagedResource(Object managedResource) throws MBeanExportException { Assert.notNull(managedResource, "Managed resource must not be null"); ObjectName objectName; try { objectName = getObjectName(managedResource, null); if (this.ensureUniqueRuntimeObjectNames) { objectName = JmxUtils.appendIdentityToObjectName(objectName, managedResource); } } catch (Throwable ex) { throw new MBeanExportException("Unable to generate ObjectName for MBean [" + managedResource + "]", ex); } registerManagedResource(managedResource, objectName); return objectName; }
/** * 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))); }
String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing); MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
/** * 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()); }
/** * Return the class or interface to expose for the given bean class. * This is the class that will be searched for attributes and operations * @param beanClass the bean class (might be an AOP proxy class) * @return the bean class to expose * @see JmxUtils#getClassToExpose(Class) */ protected Class<?> getClassToExpose(Class<?> beanClass) { return JmxUtils.getClassToExpose(beanClass); }
/** * Convert an array of {@code MBeanParameterInfo} into an array of * {@code Class} instances corresponding to the parameters. * @param paramInfo the JMX parameter info * @return the parameter types as classes * @throws ClassNotFoundException if a parameter type could not be resolved */ @Nullable public static Class<?>[] parameterInfoToTypes(@Nullable MBeanParameterInfo[] paramInfo) throws ClassNotFoundException { return parameterInfoToTypes(paramInfo, ClassUtils.getDefaultClassLoader()); }
/** * Return the Java 6 MXBean interface exists for the given class, if any * (that is, an interface whose name ends with "MXBean" and/or * carries an appropriate MXBean annotation). * @param clazz the class to check * @return whether there is an MXBean interface for the given class */ @Nullable public static Class<?> getMXBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (JMX.isMXBeanInterface(iface)) { return iface; } } return getMXBeanInterface(clazz.getSuperclass()); }
/** * Routes a method invocation (not a property get/set) to the corresponding * operation on the managed resource. * @param method the method corresponding to operation on the managed resource. * @param args the invocation arguments * @return the value returned by the method invocation. */ private Object invokeOperation(Method method, Object[] args) throws JMException, IOException { Assert.state(this.serverToUse != null, "No MBeanServerConnection available"); MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes()); MBeanOperationInfo info = this.allowedOperations.get(key); if (info == null) { throw new InvalidInvocationException("Operation '" + method.getName() + "' is not exposed on the management interface"); } String[] signature; synchronized (this.signatureCache) { signature = this.signatureCache.get(method); if (signature == null) { signature = JmxUtils.getMethodSignature(method); this.signatureCache.put(method, signature); } } return this.serverToUse.invoke(this.objectName, method.getName(), args, signature); }
/** * 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))); }
String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing); MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
/** * 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()); }
/** * Return the class or interface to expose for the given bean. * This is the class that will be searched for attributes and operations * (for example, checked for annotations). * @param managedBean the bean instance (might be an AOP proxy) * @return the bean class to expose * @see JmxUtils#getClassToExpose(Object) */ protected Class<?> getClassToExpose(Object managedBean) { return JmxUtils.getClassToExpose(managedBean); }
/** * Convert an array of {@code MBeanParameterInfo} into an array of * {@code Class} instances corresponding to the parameters. * @param paramInfo the JMX parameter info * @return the parameter types as classes * @throws ClassNotFoundException if a parameter type could not be resolved */ @Nullable public static Class<?>[] parameterInfoToTypes(@Nullable MBeanParameterInfo[] paramInfo) throws ClassNotFoundException { return parameterInfoToTypes(paramInfo, ClassUtils.getDefaultClassLoader()); }
/** * Return the Java 6 MXBean interface exists for the given class, if any * (that is, an interface whose name ends with "MXBean" and/or * carries an appropriate MXBean annotation). * @param clazz the class to check * @return whether there is an MXBean interface for the given class */ @Nullable public static Class<?> getMXBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (JMX.isMXBeanInterface(iface)) { return iface; } } return getMXBeanInterface(clazz.getSuperclass()); }
/** * Routes a method invocation (not a property get/set) to the corresponding * operation on the managed resource. * @param method the method corresponding to operation on the managed resource. * @param args the invocation arguments * @return the value returned by the method invocation. */ private Object invokeOperation(Method method, Object[] args) throws JMException, IOException { Assert.state(this.serverToUse != null, "No MBeanServerConnection available"); MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes()); MBeanOperationInfo info = this.allowedOperations.get(key); if (info == null) { throw new InvalidInvocationException("Operation '" + method.getName() + "' is not exposed on the management interface"); } String[] signature; synchronized (this.signatureCache) { signature = this.signatureCache.get(method); if (signature == null) { signature = JmxUtils.getMethodSignature(method); this.signatureCache.put(method, signature); } } return this.serverToUse.invoke(this.objectName, method.getName(), args, signature); }
/** * Attempt to find a locally running {@code MBeanServer}. Fails if no * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @return the {@code MBeanServer} if found * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer */ public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException { return locateMBeanServer(null); }
/** * Determine whether the given bean class qualifies as an MBean as-is. * <p>The default implementation delegates to {@link JmxUtils#isMBean}, * which 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 beanClass the bean class to analyze * @return whether the class qualifies as an MBean * @see org.springframework.jmx.support.JmxUtils#isMBean(Class) */ protected boolean isMBean(@Nullable Class<?> beanClass) { return JmxUtils.isMBean(beanClass); }
Class<?> targetClass = AopUtils.getTargetClass(bean); if (targetClass != bean.getClass()) { Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass); if (ifc != null) { if (!ifc.isInstance(bean)) { ifc = JmxUtils.getMBeanInterface(targetClass); if (ifc != null) { if (!ifc.isInstance(bean)) {