本文整理汇总了Java中com.sun.jmx.mbeanserver.MXBeanProxy.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java MXBeanProxy.invoke方法的具体用法?Java MXBeanProxy.invoke怎么用?Java MXBeanProxy.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jmx.mbeanserver.MXBeanProxy
的用法示例。
在下文中一共展示了MXBeanProxy.invoke方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.sun.jmx.mbeanserver.MXBeanProxy; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
final Class<?> methodClass = method.getDeclaringClass();
if (methodClass.equals(NotificationBroadcaster.class)
|| methodClass.equals(NotificationEmitter.class))
return invokeBroadcasterMethod(proxy, method, args);
// local or not: equals, toString, hashCode
if (shouldDoLocally(proxy, method))
return doLocally(proxy, method, args);
try {
if (isMXBean()) {
MXBeanProxy p = findMXBeanProxy(methodClass);
return p.invoke(connection, objectName, method, args);
} else {
final String methodName = method.getName();
final Class<?>[] paramTypes = method.getParameterTypes();
final Class<?> returnType = method.getReturnType();
/* Inexplicably, InvocationHandler specifies that args is null
when the method takes no arguments rather than a
zero-length array. */
final int nargs = (args == null) ? 0 : args.length;
if (methodName.startsWith("get")
&& methodName.length() > 3
&& nargs == 0
&& !returnType.equals(Void.TYPE)) {
return connection.getAttribute(objectName,
methodName.substring(3));
}
if (methodName.startsWith("is")
&& methodName.length() > 2
&& nargs == 0
&& (returnType.equals(Boolean.TYPE)
|| returnType.equals(Boolean.class))) {
return connection.getAttribute(objectName,
methodName.substring(2));
}
if (methodName.startsWith("set")
&& methodName.length() > 3
&& nargs == 1
&& returnType.equals(Void.TYPE)) {
Attribute attr = new Attribute(methodName.substring(3), args[0]);
connection.setAttribute(objectName, attr);
return null;
}
final String[] signature = new String[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++)
signature[i] = paramTypes[i].getName();
return connection.invoke(objectName, methodName,
args, signature);
}
} catch (MBeanException e) {
throw e.getTargetException();
} catch (RuntimeMBeanException re) {
throw re.getTargetException();
} catch (RuntimeErrorException rre) {
throw rre.getTargetError();
}
/* The invoke may fail because it can't get to the MBean, with
one of the these exceptions declared by
MBeanServerConnection.invoke:
- RemoteException: can't talk to MBeanServer;
- InstanceNotFoundException: objectName is not registered;
- ReflectionException: objectName is registered but does not
have the method being invoked.
In all of these cases, the exception will be wrapped by the
proxy mechanism in an UndeclaredThrowableException unless
it happens to be declared in the "throws" clause of the
method being invoked on the proxy.
*/
}