Spring's JMX support can rely on native MXBean detection on Java 6+
Issue: SPR-12574
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -263,20 +263,13 @@ public class MBeanClientInterceptor
|
|||||||
}
|
}
|
||||||
this.invocationHandler = null;
|
this.invocationHandler = null;
|
||||||
if (this.useStrictCasing) {
|
if (this.useStrictCasing) {
|
||||||
// Use the JDK's own MBeanServerInvocationHandler,
|
// Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support.
|
||||||
// in particular for native MXBean support on Java 6.
|
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
|
||||||
if (JmxUtils.isMXBeanSupportAvailable()) {
|
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
|
||||||
this.invocationHandler =
|
|
||||||
new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
|
|
||||||
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Non-strict casing can only be achieved through custom
|
// Non-strict casing can only be achieved through custom invocation handling.
|
||||||
// invocation handling. Only partial MXBean support available!
|
// Only partial MXBean support available!
|
||||||
retrieveMBeanInfo();
|
retrieveMBeanInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,10 +22,10 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.management.DynamicMBean;
|
import javax.management.DynamicMBean;
|
||||||
|
import javax.management.JMX;
|
||||||
import javax.management.MBeanParameterInfo;
|
import javax.management.MBeanParameterInfo;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
import javax.management.MXBean;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import javax.management.MalformedObjectNameException;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
@@ -59,16 +59,6 @@ public abstract class JmxUtils {
|
|||||||
*/
|
*/
|
||||||
private static final String MBEAN_SUFFIX = "MBean";
|
private static final String MBEAN_SUFFIX = "MBean";
|
||||||
|
|
||||||
/**
|
|
||||||
* Suffix used to identify a Java 6 MXBean interface.
|
|
||||||
*/
|
|
||||||
private static final String MXBEAN_SUFFIX = "MXBean";
|
|
||||||
|
|
||||||
private static final String MXBEAN_ANNOTATION_CLASS_NAME = "javax.management.MXBean";
|
|
||||||
|
|
||||||
|
|
||||||
private static final boolean mxBeanAnnotationAvailable =
|
|
||||||
ClassUtils.isPresent(MXBEAN_ANNOTATION_CLASS_NAME, JmxUtils.class.getClassLoader());
|
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(JmxUtils.class);
|
private static final Log logger = LogFactory.getLog(JmxUtils.class);
|
||||||
|
|
||||||
@@ -304,14 +294,7 @@ public abstract class JmxUtils {
|
|||||||
}
|
}
|
||||||
Class<?>[] implementedInterfaces = clazz.getInterfaces();
|
Class<?>[] implementedInterfaces = clazz.getInterfaces();
|
||||||
for (Class<?> iface : implementedInterfaces) {
|
for (Class<?> iface : implementedInterfaces) {
|
||||||
boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX);
|
if (JMX.isMXBeanInterface(iface)) {
|
||||||
if (mxBeanAnnotationAvailable) {
|
|
||||||
Boolean checkResult = MXBeanChecker.evaluateMXBeanAnnotation(iface);
|
|
||||||
if (checkResult != null) {
|
|
||||||
isMxBean = checkResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isMxBean) {
|
|
||||||
return iface;
|
return iface;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,21 +305,11 @@ public abstract class JmxUtils {
|
|||||||
* Check whether MXBean support is available, i.e. whether we're running
|
* Check whether MXBean support is available, i.e. whether we're running
|
||||||
* on Java 6 or above.
|
* on Java 6 or above.
|
||||||
* @return {@code true} if available; {@code false} otherwise
|
* @return {@code true} if available; {@code false} otherwise
|
||||||
|
* @deprecated as of Spring 4.0, since Java 6 is required anyway now
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean isMXBeanSupportAvailable() {
|
public static boolean isMXBeanSupportAvailable() {
|
||||||
return mxBeanAnnotationAvailable;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inner class to avoid a Java 6 dependency.
|
|
||||||
*/
|
|
||||||
private static class MXBeanChecker {
|
|
||||||
|
|
||||||
public static Boolean evaluateMXBeanAnnotation(Class<?> iface) {
|
|
||||||
MXBean mxBean = iface.getAnnotation(MXBean.class);
|
|
||||||
return (mxBean != null ? mxBean.value() : null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user