Top Description Inners Fields Constructors Methods
org.springframework.jmx.access

public Class MBeanClientInterceptor

extends Object
implements MethodInterceptor, BeanClassLoaderAware, InitializingBean, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.Aware, org.aopalliance.intercept.MethodInterceptor, org.aopalliance.intercept.Interceptor, org.aopalliance.aop.Advice
Known Direct Subclasses
org.springframework.jmx.access.MBeanProxyFactoryBean
Imports
java.beans.PropertyDescriptor, java.io.IOException, java.lang.reflect.Array, .Method, java.net.MalformedURLException, java.util.Arrays, .Collection, .Collections, .HashMap, .Map, javax.management.Attribute, .InstanceNotFoundException, .IntrospectionException, .JMException, .JMX, .MBeanAttributeInfo, .MBeanException, .MBeanInfo, .MBeanOperationInfo, .MBeanServerConnection, .MBeanServerInvocationHandler, .MalformedObjectNameException, .ObjectName, .OperationsException, .ReflectionException, .RuntimeErrorException, .RuntimeMBeanException, .RuntimeOperationsException, javax.management.openmbean.CompositeData, .TabularData, javax.management.remote.JMXServiceURL, org.aopalliance.intercept.MethodInterceptor, .MethodInvocation, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.BeanUtils, org.springframework.beans.factory.BeanClassLoaderAware, .DisposableBean, .InitializingBean, org.springframework.core.CollectionFactory, .MethodParameter, .ResolvableType, org.springframework.jmx.support.JmxUtils, .ObjectNameManager, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, .ReflectionUtils, .StringUtils

org.aopalliance.intercept.MethodInterceptor that routes calls to an MBean running on the supplied MBeanServerConnection. Works for both local and remote MBeanServerConnections.

By default, the MBeanClientInterceptor will connect to the MBeanServer and cache MBean metadata at startup. This can be undesirable when running against a remote MBeanServer that may not be running when the application starts. Through setting the connectOnStartup property to "false", you can defer this process until the first invocation against the proxy.

This functionality is usually used through MBeanProxyFactoryBean. See the javadoc of that class for more information.

Authors
Rob Harrop, Juergen Hoeller
Since
1.2
See Also
MBeanProxyFactoryBean, setConnectOnStartup

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MBeanClientInterceptor.MethodCacheKey

Simple wrapper class around a method name and its signature.

Field Summary

Modifier and TypeField and Description
private String
private Map<String, MBeanAttributeInfo>
private Map<MBeanClientInterceptor.MethodCacheKey, MBeanOperationInfo>
private ClassLoader
private boolean
private final ConnectorDelegate
private Map<String, ?>
private MBeanServerInvocationHandler
protected final Log
logger

Logger available to subclasses.

private Class<?>
private ObjectName
private final Object
private boolean
private MBeanServerConnection
private MBeanServerConnection
private JMXServiceURL
private final Map<Method, String[]>
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Prepares the MBeanServerConnection if the "connectOnStartup" is turned on (which it is by default).

private Object
convertDataArrayToTargetArray(Object[] array, Class<?> targetClass)

private Collection<?>
convertDataArrayToTargetCollection(Object[] array, Class<?> collectionType, Class<?> elementType)

protected Object

Returns:

the converted result object, or the passed-in object if no conversion is necessary
convertResultValueIfNecessary
(Object
the result object as returned by the MBeanServer
result
,
MethodParameter
the method parameter of the proxy method that's been invoked
parameter
)

Convert the given result object (from attribute access or operation invocation) to the specified target class for returning from the proxy method.

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.

protected Object

Returns:

the value returned as a result of the re-routed invocation
doInvoke
(MethodInvocation
the MethodInvocation to re-route
invocation
)

Route the invocation to the configured managed resource.

public Map<String, ?>
getEnvironment()

Allow Map access to the environment to be set for the connector, with the option to add or override specific entries.

protected final Class<?>
getManagementInterface()

Return the management interface of the target MBean, or null if none specified.

protected Object

Returns:

the result value of the new invocation, if succeeded
handleConnectFailure
(MethodInvocation
the invocation that failed
invocation
,
Exception
the exception raised on remote invocation
ex
)

Refresh the connection and retry the MBean invocation if possible.

public Object

Returns:

the value returned as a result of the re-routed invocation
invoke
(MethodInvocation
the MethodInvocation to re-route
invocation
)

Implements org.aopalliance.intercept.MethodInterceptor.invoke.

Route the invocation to the configured managed resource.

private Object
private Object

Returns:

the value returned by the method invocation.
invokeOperation
(Method
the method corresponding to operation on the managed resource.
method
,
Object[]
the invocation arguments
args
)

Routes a method invocation (not a property get/set) to the corresponding operation on the managed resource.

protected boolean
isPrepared()

Return whether this client interceptor has already been prepared, i.e. has already looked up the server and cached all metadata.

public void
prepare()

Ensures that an MBeanServerConnection is configured and attempts to detect a local connection if one is not supplied.

private void
retrieveMBeanInfo(MBeanServerConnection server)

Loads the management interface info for the configured MBean into the caches.

public void
setAgentId(String agentId)

Set the agent id of the MBeanServer to locate.

public void
setBeanClassLoader(ClassLoader
the owning class loader
beanClassLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

public void
setConnectOnStartup(boolean connectOnStartup)

Set whether the proxy should connect to the MBeanServer at creation time (true) or the first time it is invoked (false).

public void
setEnvironment(Map<String, ?> environment)

Specify the environment for the JMX connector.

public void
setManagementInterface(Class<?> managementInterface)

Set the management interface of the target MBean, exposing bean property setters and getters for MBean attributes and conventional Java methods for MBean operations.

public void
setObjectName(Object objectName)

Set the ObjectName of the MBean which calls are routed to, as ObjectName instance or as String.

public void
setRefreshOnConnectFailure(boolean refreshOnConnectFailure)

Set whether to refresh the MBeanServer connection on connect failure.

public void
setServer(MBeanServerConnection server)

Set the MBeanServerConnection used to connect to the MBean which all invocations are routed to.

public void
setServiceUrl(String url)

Set the service URL of the remote MBeanServer.

public void
setUseStrictCasing(boolean useStrictCasing)

Set whether to use strict casing for attributes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

agentIdback to summary
private String agentId
Annotations
@Nullable
allowedAttributesback to summary
private Map<String, MBeanAttributeInfo> allowedAttributes
allowedOperationsback to summary
private Map<MBeanClientInterceptor.MethodCacheKey, MBeanOperationInfo> allowedOperations
beanClassLoaderback to summary
private ClassLoader beanClassLoader
Annotations
@Nullable
connectOnStartupback to summary
private boolean connectOnStartup
connectorback to summary
private final ConnectorDelegate connector
environmentback to summary
private Map<String, ?> environment
Annotations
@Nullable
invocationHandlerback to summary
private MBeanServerInvocationHandler invocationHandler
Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

managementInterfaceback to summary
private Class<?> managementInterface
Annotations
@Nullable
objectNameback to summary
private ObjectName objectName
Annotations
@Nullable
preparationMonitorback to summary
private final Object preparationMonitor
refreshOnConnectFailureback to summary
private boolean refreshOnConnectFailure
serverback to summary
private MBeanServerConnection server
Annotations
@Nullable
serverToUseback to summary
private MBeanServerConnection serverToUse
Annotations
@Nullable
serviceUrlback to summary
private JMXServiceURL serviceUrl
Annotations
@Nullable
signatureCacheback to summary
private final Map<Method, String[]> signatureCache
useStrictCasingback to summary
private boolean useStrictCasing

Constructor Detail

MBeanClientInterceptorback to summary
public MBeanClientInterceptor()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Prepares the MBeanServerConnection if the "connectOnStartup" is turned on (which it is by default).

Annotations
@Override
convertDataArrayToTargetArrayback to summary
private Object convertDataArrayToTargetArray(Object[] array, Class<?> targetClass) throws NoSuchMethodException
convertDataArrayToTargetCollectionback to summary
private Collection<?> convertDataArrayToTargetCollection(Object[] array, Class<?> collectionType, Class<?> elementType) throws NoSuchMethodException
convertResultValueIfNecessaryback to summary
protected Object convertResultValueIfNecessary(Object result, MethodParameter parameter)

Convert the given result object (from attribute access or operation invocation) to the specified target class for returning from the proxy method.

Parameters
result:Object

the result object as returned by the MBeanServer

parameter:MethodParameter

the method parameter of the proxy method that's been invoked

Returns:Object

the converted result object, or the passed-in object if no conversion is necessary

Annotations
@Nullable
destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Doc from org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.

Annotations
@Override
doInvokeback to summary
protected Object doInvoke(MethodInvocation invocation) throws Throwable

Route the invocation to the configured managed resource. Correctly routes JavaBean property access to MBeanServerConnection.get/setAttribute and method invocation to MBeanServerConnection.invoke.

Parameters
invocation:MethodInvocation

the MethodInvocation to re-route

Returns:Object

the value returned as a result of the re-routed invocation

Annotations
@Nullable
Exceptions
Throwable:
an invocation error propagated to the user
getEnvironmentback to summary
public Map<String, ?> getEnvironment()

Allow Map access to the environment to be set for the connector, with the option to add or override specific entries.

Useful for specifying entries directly, for example via environment[myKey]. This is particularly useful for adding or overriding entries in child bean definitions.

Annotations
@Nullable
getManagementInterfaceback to summary
protected final Class<?> getManagementInterface()

Return the management interface of the target MBean, or null if none specified.

Annotations
@Nullable
handleConnectFailureback to summary
protected Object handleConnectFailure(MethodInvocation invocation, Exception ex) throws Throwable

Refresh the connection and retry the MBean invocation if possible.

If not configured to refresh on connect failure, this method simply rethrows the original exception.

Parameters
invocation:MethodInvocation

the invocation that failed

ex:Exception

the exception raised on remote invocation

Returns:Object

the result value of the new invocation, if succeeded

Annotations
@Nullable
Exceptions
Throwable:
an exception raised by the new invocation, if it failed as well
See Also
setRefreshOnConnectFailure, doInvoke
invokeback to summary
public Object invoke(MethodInvocation invocation) throws Throwable

Implements org.aopalliance.intercept.MethodInterceptor.invoke.

Route the invocation to the configured managed resource.

Parameters
invocation:MethodInvocation

the MethodInvocation to re-route

Returns:Object

the value returned as a result of the re-routed invocation

Annotations
@Override
@Nullable
Exceptions
Throwable:
an invocation error propagated to the user
See Also
doInvoke, handleConnectFailure
invokeAttributeback to summary
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException
Annotations
@Nullable
invokeOperationback to summary
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException

Routes a method invocation (not a property get/set) to the corresponding operation on the managed resource.

Parameters
method:Method

the method corresponding to operation on the managed resource.

args:Object[]

the invocation arguments

Returns:Object

the value returned by the method invocation.

isPreparedback to summary
protected boolean isPrepared()

Return whether this client interceptor has already been prepared, i.e. has already looked up the server and cached all metadata.

prepareback to summary
public void prepare()

Ensures that an MBeanServerConnection is configured and attempts to detect a local connection if one is not supplied.

retrieveMBeanInfoback to summary
private void retrieveMBeanInfo(MBeanServerConnection server) throws MBeanInfoRetrievalException

Loads the management interface info for the configured MBean into the caches. This information is used by the proxy when determining whether an invocation matches a valid operation or attribute on the management interface of the managed resource.

setAgentIdback to summary
public void setAgentId(String agentId)

Set the agent id of the MBeanServer to locate.

Default is none. If specified, this will result in an attempt being made to locate the attendant MBeanServer, unless the "serviceUrl" property has been set.

See Also
<p>Specifying the empty String indicates the platform MBeanServer.
setBeanClassLoaderback to summary
public void setBeanClassLoader(ClassLoader beanClassLoader)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Doc from org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's InitializingBean#afterPropertiesSet() method or a custom init-method.

Parameters
beanClassLoader:ClassLoader

the owning class loader

Annotations
@Override
setConnectOnStartupback to summary
public void setConnectOnStartup(boolean connectOnStartup)

Set whether the proxy should connect to the MBeanServer at creation time (true) or the first time it is invoked (false). Default is true.

setEnvironmentback to summary
public void setEnvironment(Map<String, ?> environment)

Specify the environment for the JMX connector.

See Also
javax.management.remote.JMXConnectorFactory#connect(javax.management.remote.JMXServiceURL, java.util.Map)
setManagementInterfaceback to summary
public void setManagementInterface(Class<?> managementInterface)

Set the management interface of the target MBean, exposing bean property setters and getters for MBean attributes and conventional Java methods for MBean operations.

setObjectNameback to summary
public void setObjectName(Object objectName) throws MalformedObjectNameException

Set the ObjectName of the MBean which calls are routed to, as ObjectName instance or as String.

setRefreshOnConnectFailureback to summary
public void setRefreshOnConnectFailure(boolean refreshOnConnectFailure)

Set whether to refresh the MBeanServer connection on connect failure. Default is false.

Can be turned on to allow for hot restart of the JMX server, automatically reconnecting and retrying in case of an IOException.

setServerback to summary
public void setServer(MBeanServerConnection server)

Set the MBeanServerConnection used to connect to the MBean which all invocations are routed to.

setServiceUrlback to summary
public void setServiceUrl(String url) throws MalformedURLException

Set the service URL of the remote MBeanServer.

setUseStrictCasingback to summary
public void setUseStrictCasing(boolean useStrictCasing)

Set whether to use strict casing for attributes. Enabled by default.

When using strict casing, a JavaBean property with a getter such as getFoo() translates to an attribute called Foo. With strict casing disabled, getFoo() would translate to just foo.

org.springframework.jmx.access back to summary

private final Class MBeanClientInterceptor.MethodCacheKey

extends Object
implements Comparable<MBeanClientInterceptor.MethodCacheKey>
Class Inheritance
  • java.lang.Object
  • org.springframework.jmx.access.MBeanClientInterceptor.MethodCacheKey
All Implemented Interfaces
java.lang.Comparable

Simple wrapper class around a method name and its signature. Used as the key when caching methods.

Field Summary

Modifier and TypeField and Description
private final String
private final Class<?>[]

Constructor Summary

AccessConstructor and Description
public
MethodCacheKey(String
the name of the method
name
,
Class<?>[]
the arguments in the method signature
parameterTypes
)

Create a new instance of MethodCacheKey with the supplied method name and parameter list.

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(MBeanClientInterceptor.MethodCacheKey
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nameback to summary
private final String name
parameterTypesback to summary
private final Class<?>[] parameterTypes

Constructor Detail

MethodCacheKeyback to summary
public MethodCacheKey(String name, Class<?>[] parameterTypes)

Create a new instance of MethodCacheKey with the supplied method name and parameter list.

Parameters
name:String

the name of the method

parameterTypes:Class<?>[]

the arguments in the method signature

Method Detail

compareToback to summary
public int compareTo(MBeanClientInterceptor.MethodCacheKey other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:MBeanClientInterceptor.MethodCacheKey

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override