站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.1.0 API 文档英文版

MBeanClientInterceptor (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.jmx.access
Class MBeanClientInterceptor

java.lang.Object
  extended by org.springframework.jmx.access.MBeanClientInterceptor
All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, DisposableBean, InitializingBean
Direct Known Subclasses:
MBeanProxyFactoryBean

public class MBeanClientInterceptor
extends Object
implements MethodInterceptor, InitializingBean, DisposableBean

MethodInterceptor implementation 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.

Requires JMX 1.2's MBeanServerConnection feature. As a consequence, this class will not work on JMX 1.0.

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

Since:
1.2
Author:
Rob Harrop, Juergen Hoeller
See Also:
MBeanProxyFactoryBean, setConnectOnStartup(boolean)

Field Summary
protected  Log logger
          Logger available to subclasses
 
Constructor Summary
MBeanClientInterceptor()
           
 
Method Summary
 void afterPropertiesSet()
          Ensures that an MBeanServerConnection is configured and attempts to detect a local connection if one is not supplied.
 void destroy()
          Closes any JMXConnector that may be managed by this interceptor.
 Object invoke(MethodInvocation invocation)
          Route the invocation to the configured managed resource.
protected  MBeanServer locateMBeanServer(String agentId)
          Attempt to locate an existing MBeanServer.
 void setAgentId(String agentId)
          Set the agent id of the MBeanServer to locate.
 void setConnectOnStartup(boolean connectOnStartup)
          Set whether or not the proxy should connect to the MBeanServer at creation time ("true") or the first time it is invoked ("false").
 void setObjectName(Object objectName)
          Set the ObjectName of the MBean which calls are routed to, as ObjectName instance or as String.
 void setServer(MBeanServerConnection server)
          Set the MBeanServerConnection used to connect to the MBean which all invocations are routed to.
 void setServiceUrl(String url)
          Set the service URL of the remote MBeanServer.
 void setUseStrictCasing(boolean useStrictCasing)
          Set whether to use strict casing for attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Logger available to subclasses

Constructor Detail

MBeanClientInterceptor

public MBeanClientInterceptor()
Method Detail

setServer

public void setServer(MBeanServerConnection server)
Set the MBeanServerConnection used to connect to the MBean which all invocations are routed to.


setServiceUrl

public void setServiceUrl(String url)
                   throws MalformedURLException
Set the service URL of the remote MBeanServer.

Throws:
MalformedURLException

setAgentId

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:
MBeanServerFactory.findMBeanServer(String)

setConnectOnStartup

public void setConnectOnStartup(boolean connectOnStartup)
Set whether or not the proxy should connect to the MBeanServer at creation time ("true") or the first time it is invoked ("false"). Default is "true".


setObjectName

public void setObjectName(Object objectName)
                   throws MalformedObjectNameException
Set the ObjectName of the MBean which calls are routed to, as ObjectName instance or as String.

Throws:
MalformedObjectNameException

setUseStrictCasing

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.


afterPropertiesSet

public void afterPropertiesSet()
                        throws MBeanServerNotFoundException,
                               MBeanInfoRetrievalException
Ensures that an MBeanServerConnection is configured and attempts to detect a local connection if one is not supplied.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
MBeanServerNotFoundException
MBeanInfoRetrievalException

locateMBeanServer

protected MBeanServer locateMBeanServer(String agentId)
                                 throws MBeanServerNotFoundException
Attempt to locate an existing MBeanServer. Called if no "serviceUrl" was specified.

The default implementation attempts to find an MBeanServer using a standard lookup. Subclasses may override to add additional location logic.

Parameters:
agentId - the agent identifier of the MBeanServer to retrieve. If this parameter is null, all registered MBeanServers are considered.
Returns:
the MBeanServer if found
Throws:
MBeanServerNotFoundException - if no MBeanServer could be found
See Also:
JmxUtils.locateMBeanServer(String), MBeanServerFactory.findMBeanServer(String)

invoke

public Object invoke(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. Any attempt to invoke a method that does not correspond to an attribute or operation defined in the management interface of the managed resource results in an InvalidInvocationException.

Specified by:
invoke in interface MethodInterceptor
Parameters:
invocation - the MethodInvocation to re-route.
Returns:
the value returned as a result of the re-routed invocation.
Throws:
InvocationFailureException - if the invocation does not match an attribute or operation on the management interface of the resource.
Throwable - typically as the result of an error during invocation

destroy

public void destroy()
             throws Exception
Closes any JMXConnector that may be managed by this interceptor.

Specified by:
destroy in interface DisposableBean
Throws:
Exception - in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources too.

The Spring Framework

Copyright © 2002-2007 The Spring Framework.