类 MBeanClientInterceptor
- java.lang.Object
- org.springframework.jmx.access.MBeanClientInterceptor
- 所有已实现的接口:
Advice,Interceptor,MethodInterceptor,Aware,BeanClassLoaderAware,DisposableBean,InitializingBean
- 直接已知子类:
MBeanProxyFactoryBean
public class MBeanClientInterceptor extends Object implements MethodInterceptor, BeanClassLoaderAware, InitializingBean, DisposableBean
MethodInterceptorthat routes calls to an MBean running on the suppliedMBeanServerConnection. Works for both local and remoteMBeanServerConnections.By default, the
MBeanClientInterceptorwill connect to theMBeanServerand cache MBean metadata at startup. This can be undesirable when running against a remoteMBeanServerthat may not be running when the application starts. Through setting theconnectOnStartupproperty 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.- 从以下版本开始:
- 1.2
- 作者:
- Rob Harrop, Juergen Hoeller
- 另请参阅:
MBeanProxyFactoryBean,setConnectOnStartup(boolean)
构造器概要
构造器 构造器 说明 MBeanClientInterceptor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Prepares theMBeanServerConnectionif the "connectOnStartup" is turned on (which it is by default).protected ObjectconvertResultValueIfNecessary(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.voiddestroy()Invoked by the containingBeanFactoryon destruction of a bean.protected ObjectdoInvoke(MethodInvocation invocation)Route the invocation to the configured managed resource.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 Class<?>getManagementInterface()Return the management interface of the target MBean, ornullif none specified.protected ObjecthandleConnectFailure(MethodInvocation invocation, Exception ex)Refresh the connection and retry the MBean invocation if possible.Objectinvoke(MethodInvocation invocation)Route the invocation to the configured managed resource..protected booleanisPrepared()Return whether this client interceptor has already been prepared, i.e. has already looked up the server and cached all metadata.voidprepare()Ensures that anMBeanServerConnectionis configured and attempts to detect a local connection if one is not supplied.voidsetAgentId(String agentId)Set the agent id of theMBeanServerto locate.voidsetBeanClassLoader(ClassLoader beanClassLoader)Callback that supplies the beanclass loaderto a bean instance.voidsetConnectOnStartup(boolean connectOnStartup)Set whether or not the proxy should connect to theMBeanServerat creation time ("true") or the first time it is invoked ("false").voidsetEnvironment(Map<String,?> environment)Specify the environment for the JMX connector.voidsetManagementInterface(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.voidsetObjectName(Object objectName)Set theObjectNameof the MBean which calls are routed to, asObjectNameinstance or asString.voidsetRefreshOnConnectFailure(boolean refreshOnConnectFailure)Set whether to refresh the MBeanServer connection on connect failure.voidsetServer(MBeanServerConnection server)Set theMBeanServerConnectionused to connect to the MBean which all invocations are routed to.voidsetServiceUrl(String url)Set the service URL of the remoteMBeanServer.voidsetUseStrictCasing(boolean useStrictCasing)Set whether to use strict casing for attributes.
构造器详细资料
MBeanClientInterceptor
public MBeanClientInterceptor()
方法详细资料
setServer
public void setServer(MBeanServerConnection server)
Set theMBeanServerConnectionused 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 remoteMBeanServer.
setEnvironment
public void setEnvironment(@Nullable Map<String,?> environment)
Specify the environment for the JMX connector.
getEnvironment
@Nullable 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.
setAgentId
public void setAgentId(String agentId)
Set the agent id of theMBeanServerto 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.
setConnectOnStartup
public void setConnectOnStartup(boolean connectOnStartup)
Set whether or not the proxy should connect to theMBeanServerat creation time ("true") or the first time it is invoked ("false"). Default is "true".
setRefreshOnConnectFailure
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.
setObjectName
public void setObjectName(Object objectName) throws MalformedObjectNameException
Set theObjectNameof the MBean which calls are routed to, asObjectNameinstance or asString.
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 calledFoo. With strict casing disabled,getFoo()would translate to justfoo.
setManagementInterface
public void setManagementInterface(@Nullable 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.
getManagementInterface
@Nullable protected final Class<?> getManagementInterface()
Return the management interface of the target MBean, ornullif none specified.
setBeanClassLoader
public void setBeanClassLoader(ClassLoader beanClassLoader)
从接口复制的说明:BeanClassLoaderAwareCallback that supplies the beanclass loaderto a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean'sInitializingBean.afterPropertiesSet()method or a custom init-method.- 指定者:
setBeanClassLoader在接口中BeanClassLoaderAware- 参数:
beanClassLoader- the owning class loader
afterPropertiesSet
public void afterPropertiesSet()
Prepares theMBeanServerConnectionif the "connectOnStartup" is turned on (which it is by default).- 指定者:
afterPropertiesSet在接口中InitializingBean
prepare
public void prepare()
Ensures that anMBeanServerConnectionis configured and attempts to detect a local connection if one is not supplied.
isPrepared
protected boolean isPrepared()
Return whether this client interceptor has already been prepared, i.e. has already looked up the server and cached all metadata.
invoke
@Nullable public Object invoke(MethodInvocation invocation) throws Throwable
Route the invocation to the configured managed resource..- 指定者:
invoke在接口中MethodInterceptor- 参数:
invocation- theMethodInvocationto re-route- 返回:
- the value returned as a result of the re-routed invocation
- 抛出:
Throwable- an invocation error propagated to the user- 另请参阅:
doInvoke(org.aopalliance.intercept.MethodInvocation),handleConnectFailure(org.aopalliance.intercept.MethodInvocation, java.lang.Exception)
handleConnectFailure
@Nullable 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.
- 参数:
invocation- the invocation that failedex- the exception raised on remote invocation- 返回:
- the result value of the new invocation, if succeeded
- 抛出:
Throwable- an exception raised by the new invocation, if it failed as well- 另请参阅:
setRefreshOnConnectFailure(boolean),doInvoke(org.aopalliance.intercept.MethodInvocation)
doInvoke
@Nullable protected Object doInvoke(MethodInvocation invocation) throws Throwable
Route the invocation to the configured managed resource. Correctly routes JavaBean property access toMBeanServerConnection.get/setAttributeand method invocation toMBeanServerConnection.invoke.- 参数:
invocation- theMethodInvocationto re-route- 返回:
- the value returned as a result of the re-routed invocation
- 抛出:
Throwable- an invocation error propagated to the user
convertResultValueIfNecessary
@Nullable protected Object convertResultValueIfNecessary(@Nullable 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.- 参数:
result- the result object as returned by theMBeanServerparameter- the method parameter of the proxy method that's been invoked- 返回:
- the converted result object, or the passed-in object if no conversion is necessary
destroy
public void destroy()
从接口复制的说明:DisposableBeanInvoked by the containingBeanFactoryon destruction of a bean.- 指定者:
destroy在接口中DisposableBean