| Method from org.springframework.jmx.access.MBeanClientInterceptor Detail: |
public void afterPropertiesSet() {
if (this.connectOnStartup) {
prepare();
}
}
Prepares the MBeanServerConnection if the "connectOnStartup"
is turned on (which it is by default). |
protected Object convertResultValueIfNecessary(Object result,
Class targetClass) {
try {
if (result == null) {
return null;
}
if (ClassUtils.isAssignableValue(targetClass, result)) {
return result;
}
if (result instanceof CompositeData) {
Method fromMethod = targetClass.getMethod("from", new Class[] {CompositeData.class});
return ReflectionUtils.invokeMethod(fromMethod, null, new Object[] {result});
}
else if (result instanceof TabularData) {
Method fromMethod = targetClass.getMethod("from", new Class[] {TabularData.class});
return ReflectionUtils.invokeMethod(fromMethod, null, new Object[] {result});
}
else {
throw new InvocationFailureException(
"Incompatible result value [" + result + "] for target type [" + targetClass.getName() + "]");
}
}
catch (NoSuchMethodException ex) {
throw new InvocationFailureException(
"Could not obtain 'find(CompositeData)' / 'find(TabularData)' method on target type [" +
targetClass.getName() + "] for conversion of MXBean data structure [" + result + "]");
}
}
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() {
this.connector.close();
}
|
protected final Class getManagementInterface() {
return this.managementInterface;
}
Return the management interface of the target MBean,
or null if none specified. |
public Object invoke(MethodInvocation invocation) throws Throwable {
// Lazily connect to MBeanServer if necessary.
synchronized (this.preparationMonitor) {
if (!isPrepared()) {
prepare();
}
}
Method method = invocation.getMethod();
try {
Object result = null;
if (this.invocationHandler != null) {
result = this.invocationHandler.invoke(invocation.getThis(), method, invocation.getArguments());
}
else {
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
if (pd != null) {
result = invokeAttribute(pd, invocation);
}
else {
result = invokeOperation(method, invocation.getArguments());
}
}
return convertResultValueIfNecessary(result, method.getReturnType());
}
catch (MBeanException ex) {
throw ex.getTargetException();
}
catch (RuntimeMBeanException ex) {
throw ex.getTargetException();
}
catch (RuntimeErrorException ex) {
throw ex.getTargetError();
}
catch (RuntimeOperationsException ex) {
// This one is only thrown by the JMX 1.2 RI, not by the JDK 1.5 JMX code.
RuntimeException rex = ex.getTargetException();
if (rex instanceof RuntimeMBeanException) {
throw ((RuntimeMBeanException) rex).getTargetException();
}
else if (rex instanceof RuntimeErrorException) {
throw ((RuntimeErrorException) rex).getTargetError();
}
else {
throw rex;
}
}
catch (OperationsException ex) {
if (ReflectionUtils.declaresException(method, ex.getClass())) {
throw ex;
}
else {
throw new InvalidInvocationException(ex.getMessage());
}
}
catch (JMException ex) {
if (ReflectionUtils.declaresException(method, ex.getClass())) {
throw ex;
}
else {
throw new InvocationFailureException("JMX access failed", ex);
}
}
catch (IOException ex) {
if (ReflectionUtils.declaresException(method, ex.getClass())) {
throw ex;
}
else {
throw new InvocationFailureException("I/O failure during JMX access", ex);
}
}
}
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. |
protected boolean isPrepared() {
synchronized (this.preparationMonitor) {
return (this.invocationHandler != null || this.allowedAttributes != null);
}
}
Return whether this client interceptor has already been prepared,
i.e. has already looked up the server and cached all metadata. |
public void prepare() {
synchronized (this.preparationMonitor) {
if (this.server == null) {
this.server = this.connector.connect(this.serviceUrl, this.agentId);
}
this.invocationHandler = null;
if (this.useStrictCasing) {
// Use the JDK's own MBeanServerInvocationHandler,
// in particular for native MXBean support on Java 6.
if (JdkVersion.isAtLeastJava16()) {
this.invocationHandler =
new MBeanServerInvocationHandler(this.server, this.objectName,
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
}
else {
this.invocationHandler = new MBeanServerInvocationHandler(this.server, this.objectName);
}
}
else {
// Non-strict asing can only be achieved through custom
// invocation handling. Only partial MXBean support available!
retrieveMBeanInfo();
}
}
}
Ensures that an MBeanServerConnection is configured and attempts
to detect a local connection if one is not supplied. |
public void setAgentId(String agentId) {
this.agentId = 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. |
public void setBeanClassLoader(ClassLoader beanClassLoader) {
this.beanClassLoader = beanClassLoader;
}
|
public void setConnectOnStartup(boolean connectOnStartup) {
this.connectOnStartup = 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". |
public void setManagementInterface(Class managementInterface) {
this.managementInterface = 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) throws MalformedObjectNameException {
this.objectName = ObjectNameManager.getInstance(objectName);
}
Set the ObjectName of the MBean which calls are routed to,
as ObjectName instance or as String. |
public void setServer(MBeanServerConnection server) {
this.server = server;
}
Set the MBeanServerConnection used to connect to the
MBean which all invocations are routed to. |
public void setServiceUrl(String url) throws MalformedURLException {
this.serviceUrl = new JMXServiceURL(url);
}
Set the service URL of the remote MBeanServer. |
public void setUseStrictCasing(boolean useStrictCasing) {
this.useStrictCasing = 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. |