|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jmx.access.MBeanClientInterceptor
public class MBeanClientInterceptor
MethodInterceptor
that routes calls to an
MBean running on the supplied MBeanServerConnection
.
Works for both local and remote MBeanServerConnection
s.
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.
MBeanProxyFactoryBean
,
setConnectOnStartup(boolean)
Field Summary | |
---|---|
protected Log |
logger
Logger available to subclasses |
Constructor Summary | |
---|---|
MBeanClientInterceptor()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Prepares the MBeanServerConnection if the "connectOnStartup"
is turned on (which it is by default). |
protected Object |
convertResultValueIfNecessary(Object result,
Class targetClass)
Convert the given result object (from attribute access or operation invocation) to the specified target class for returning from the proxy method. |
void |
destroy()
Closes any JMXConnector that may be managed by this interceptor. |
protected Class |
getManagementInterface()
Return the management interface of the target MBean, or null if none specified. |
Object |
invoke(MethodInvocation invocation)
Route the invocation to the configured 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. |
protected MBeanServer |
locateMBeanServer(String agentId)
Attempt to locate an existing MBeanServer . |
void |
prepare()
Ensures that an MBeanServerConnection is configured and attempts
to detect a local connection if one is not supplied. |
void |
setAgentId(String agentId)
Set the agent id of the MBeanServer to locate. |
void |
setBeanClassLoader(ClassLoader beanClassLoader)
Callback that supplies the bean class loader to
a bean instance. |
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 |
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. |
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 |
---|
protected final Log logger
Constructor Detail |
---|
public MBeanClientInterceptor()
Method Detail |
---|
public void setServer(MBeanServerConnection server)
MBeanServerConnection
used to connect to the
MBean which all invocations are routed to.
public void setServiceUrl(String url) throws MalformedURLException
MBeanServer
.
MalformedURLException
public void setAgentId(String agentId)
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.
MBeanServerFactory.findMBeanServer(String)
public void setConnectOnStartup(boolean connectOnStartup)
MBeanServer
at creation time ("true") or the first time it is invoked ("false").
Default is "true".
public void setObjectName(Object objectName) throws MalformedObjectNameException
ObjectName
of the MBean which calls are routed to,
as ObjectName
instance or as String
.
MalformedObjectNameException
public void setUseStrictCasing(boolean useStrictCasing)
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
.
public void setManagementInterface(Class managementInterface)
protected final Class getManagementInterface()
null
if none specified.
public void setBeanClassLoader(ClassLoader beanClassLoader)
BeanClassLoaderAware
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.
setBeanClassLoader
in interface BeanClassLoaderAware
beanClassLoader
- the owning class loader; may be null
in
which case a default ClassLoader
must be used, for example
the ClassLoader
obtained via
ClassUtils.getDefaultClassLoader()
public void afterPropertiesSet()
MBeanServerConnection
if the "connectOnStartup"
is turned on (which it is by default).
afterPropertiesSet
in interface InitializingBean
public void prepare()
MBeanServerConnection
is configured and attempts
to detect a local connection if one is not supplied.
protected MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException
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.
agentId
- the agent identifier of the MBeanServer to retrieve.
If this parameter is null
, all registered MBeanServers are
considered.
MBeanServer
if found
MBeanServerNotFoundException
- if no MBeanServer
could be foundJmxUtils.locateMBeanServer(String)
,
MBeanServerFactory.findMBeanServer(String)
protected boolean isPrepared()
public Object invoke(MethodInvocation invocation) throws Throwable
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
.
invoke
in interface MethodInterceptor
invocation
- the MethodInvocation
to re-route.
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 invocationprotected Object convertResultValueIfNecessary(Object result, Class targetClass)
result
- the result object as returned by the MBeanServer
targetClass
- the result type of the proxy method that's been invoked
public void destroy() throws Exception
JMXConnector
that may be managed by this interceptor.
destroy
in interface DisposableBean
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 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |