Spring's JMX support can rely on native MXBean detection on Java 6+
Issue: SPR-12574
This commit is contained in:
parent
d4a5059097
commit
0919a15f91
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -263,20 +263,13 @@ public class MBeanClientInterceptor
|
|||
}
|
||||
this.invocationHandler = null;
|
||||
if (this.useStrictCasing) {
|
||||
// Use the JDK's own MBeanServerInvocationHandler,
|
||||
// in particular for native MXBean support on Java 6.
|
||||
if (JmxUtils.isMXBeanSupportAvailable()) {
|
||||
this.invocationHandler =
|
||||
new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
|
||||
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
|
||||
}
|
||||
else {
|
||||
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
|
||||
}
|
||||
// Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support.
|
||||
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
|
||||
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
|
||||
}
|
||||
else {
|
||||
// Non-strict casing can only be achieved through custom
|
||||
// invocation handling. Only partial MXBean support available!
|
||||
// Non-strict casing can only be achieved through custom invocation handling.
|
||||
// Only partial MXBean support available!
|
||||
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");
|
||||
* 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.List;
|
||||
import javax.management.DynamicMBean;
|
||||
import javax.management.JMX;
|
||||
import javax.management.MBeanParameterInfo;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerFactory;
|
||||
import javax.management.MXBean;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
|
|
@ -59,16 +59,6 @@ public abstract class JmxUtils {
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
@ -304,14 +294,7 @@ public abstract class JmxUtils {
|
|||
}
|
||||
Class<?>[] implementedInterfaces = clazz.getInterfaces();
|
||||
for (Class<?> iface : implementedInterfaces) {
|
||||
boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX);
|
||||
if (mxBeanAnnotationAvailable) {
|
||||
Boolean checkResult = MXBeanChecker.evaluateMXBeanAnnotation(iface);
|
||||
if (checkResult != null) {
|
||||
isMxBean = checkResult;
|
||||
}
|
||||
}
|
||||
if (isMxBean) {
|
||||
if (JMX.isMXBeanInterface(iface)) {
|
||||
return iface;
|
||||
}
|
||||
}
|
||||
|
|
@ -322,21 +305,11 @@ public abstract class JmxUtils {
|
|||
* Check whether MXBean support is available, i.e. whether we're running
|
||||
* on Java 6 or above.
|
||||
* @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() {
|
||||
return mxBeanAnnotationAvailable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue