当前位置: 首页>>代码示例>>Java>>正文


Java MXBeanProxy类代码示例

本文整理汇总了Java中com.sun.jmx.mbeanserver.MXBeanProxy的典型用法代码示例。如果您正苦于以下问题:Java MXBeanProxy类的具体用法?Java MXBeanProxy怎么用?Java MXBeanProxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MXBeanProxy类属于com.sun.jmx.mbeanserver包,在下文中一共展示了MXBeanProxy类的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.
     */
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:79,代码来源:MBeanServerInvocationHandler.java


注:本文中的com.sun.jmx.mbeanserver.MXBeanProxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。