| Method from org.springframework.jmx.access.MBeanClientInterceptor Detail: |
public void afterPropertiesSet() {
if (this.server != null && this.refreshOnConnectFailure) {
throw new IllegalArgumentException("'refreshOnConnectFailure' does not work when setting " +
"a 'server' reference. Prefer 'serviceUrl' etc instead.");
}
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 Object doInvoke(MethodInvocation invocation) throws Throwable {
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 MBeanConnectFailureException("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. |
public Map getEnvironment() {
return this.environment;
}
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. |
protected final Class getManagementInterface() {
return this.managementInterface;
}
Return the management interface of the target MBean,
or null if none specified. |
protected Object handleConnectFailure(MethodInvocation invocation,
Exception ex) throws Throwable {
if (this.refreshOnConnectFailure) {
String msg = "Could not connect to JMX server - retrying";
if (logger.isDebugEnabled()) {
logger.warn(msg, ex);
}
else if (logger.isWarnEnabled()) {
logger.warn(msg);
}
prepare();
return doInvoke(invocation);
}
else {
throw ex;
}
}
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. |
public Object invoke(MethodInvocation invocation) throws Throwable {
// Lazily connect to MBeanServer if necessary.
synchronized (this.preparationMonitor) {
if (!isPrepared()) {
prepare();
}
}
try {
return doInvoke(invocation);
}
catch (MBeanConnectFailureException ex) {
return handleConnectFailure(invocation, ex);
}
catch (IOException ex) {
return handleConnectFailure(invocation, ex);
}
}
Route the invocation to the configured managed resource.. |
protected boolean isPrepared() {
synchronized (this.preparationMonitor) {
return (this.serverToUse != 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.serverToUse = this.server;
}
else {
this.serverToUse = null;
this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, 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.serverToUse, this.objectName,
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
}
else {
this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
}
}
else {
// Non-strict casing 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 setEnvironment(Map environment) {
this.environment = environment;
}
Specify the environment for the JMX connector. |
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 setRefreshOnConnectFailure(boolean refreshOnConnectFailure) {
this.refreshOnConnectFailure = 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. |
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. |