java类javax.management.MBeanServerInvocationHandler的实例源码

MXBeanLookup.java 文件源码 项目:OpenJSharp 阅读 26 收藏 0 点赞 0 评论 0
synchronized ObjectName mxbeanToObjectName(Object mxbean)
throws OpenDataException {
    String wrong;
    if (mxbean instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
        if (ih instanceof MBeanServerInvocationHandler) {
            MBeanServerInvocationHandler mbsih =
                    (MBeanServerInvocationHandler) ih;
            if (mbsih.getMBeanServerConnection().equals(mbsc))
                return mbsih.getObjectName();
            else
                wrong = "proxy for a different MBeanServer";
        } else
            wrong = "not a JMX proxy";
    } else {
        ObjectName name = mxbeanToObjectName.get(mxbean);
        if (name != null)
            return name;
        wrong = "not an MXBean registered in this MBeanServer";
    }
    String s = (mxbean == null) ?
        "null" : "object of type " + mxbean.getClass().getName();
    throw new OpenDataException(
            "Could not convert " + s + " to an ObjectName: " + wrong);
    // Message will be strange if mxbean is null but it is not
    // supposed to be.
}
TestUtils.java 文件源码 项目:jdk8u-jdk 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Returns the ObjectName of the MBean that a proxy object
 * is proxying.
 **/
public static ObjectName getObjectName(Object proxy) {
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (handler instanceof MBeanServerInvocationHandler)
        return ((MBeanServerInvocationHandler)handler).getObjectName();
    throw new IllegalArgumentException("not a JMX Proxy");
}
MXBeanLookup.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
synchronized ObjectName mxbeanToObjectName(Object mxbean)
throws OpenDataException {
    String wrong;
    if (mxbean instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
        if (ih instanceof MBeanServerInvocationHandler) {
            MBeanServerInvocationHandler mbsih =
                    (MBeanServerInvocationHandler) ih;
            if (mbsih.getMBeanServerConnection().equals(mbsc))
                return mbsih.getObjectName();
            else
                wrong = "proxy for a different MBeanServer";
        } else
            wrong = "not a JMX proxy";
    } else {
        ObjectName name = mxbeanToObjectName.get(mxbean);
        if (name != null)
            return name;
        wrong = "not an MXBean registered in this MBeanServer";
    }
    String s = (mxbean == null) ?
        "null" : "object of type " + mxbean.getClass().getName();
    throw new OpenDataException(
            "Could not convert " + s + " to an ObjectName: " + wrong);
    // Message will be strange if mxbean is null but it is not
    // supposed to be.
}
MXBeanTest.java 文件源码 项目:jdk8u-jdk 阅读 27 收藏 0 点赞 0 评论 0
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) {
        if (o1 == o2)
            return true;
        if (o1 == null || o2 == null)
            return false;
        if (o1.getClass().isArray()) {
            if (!o2.getClass().isArray())
                return false;
            return deepEqual(o1, o2, namedMXBeans);
        }
        if (o1 instanceof Map) {
            if (!(o2 instanceof Map))
                return false;
            return equalMap((Map) o1, (Map) o2, namedMXBeans);
        }
        if (o1 instanceof CompositeData && o2 instanceof CompositeData) {
            return compositeDataEqual((CompositeData) o1, (CompositeData) o2,
                                      namedMXBeans);
        }
        if (Proxy.isProxyClass(o1.getClass())) {
            if (Proxy.isProxyClass(o2.getClass()))
                return proxyEqual(o1, o2, namedMXBeans);
            InvocationHandler ih = Proxy.getInvocationHandler(o1);
//            if (ih instanceof MXBeanInvocationHandler) {
//                return proxyEqualsObject((MXBeanInvocationHandler) ih,
//                                         o2, namedMXBeans);
            if (ih instanceof MBeanServerInvocationHandler) {
                return true;
            } else if (ih instanceof CompositeDataInvocationHandler) {
                return o2.equals(o1);
                // We assume the other object has a reasonable equals method
            }
        } else if (Proxy.isProxyClass(o2.getClass()))
            return equal(o2, o1, namedMXBeans);
        return o1.equals(o2);
    }
Ex4Service.java 文件源码 项目:DevoxxFr2017 阅读 19 收藏 0 点赞 0 评论 0
public Ex4Service() throws URISyntaxException {
  CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");

  CacheManager cacheManager = cachingProvider.getCacheManager(
      getClass().getResource("/ehcache-ex4.xml").toURI(),
      getClass().getClassLoader());
  cache = cacheManager.getCache("someCache4", Long.class, Person.class);

  try {
    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics,CacheManager="
        + getClass().getResource("/ehcache-ex4.xml")
        .toURI()
        .toString()
        .replace(":", ".") + ",Cache=someCache4");
    cacheStatisticsMXBean = MBeanServerInvocationHandler.newProxyInstance(beanServer, objectName, CacheStatisticsMXBean.class, false);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
MXBeanLookup.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
synchronized ObjectName mxbeanToObjectName(Object mxbean)
throws OpenDataException {
    String wrong;
    if (mxbean instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
        if (ih instanceof MBeanServerInvocationHandler) {
            MBeanServerInvocationHandler mbsih =
                    (MBeanServerInvocationHandler) ih;
            if (mbsih.getMBeanServerConnection().equals(mbsc))
                return mbsih.getObjectName();
            else
                wrong = "proxy for a different MBeanServer";
        } else
            wrong = "not a JMX proxy";
    } else {
        ObjectName name = mxbeanToObjectName.get(mxbean);
        if (name != null)
            return name;
        wrong = "not an MXBean registered in this MBeanServer";
    }
    String s = (mxbean == null) ?
        "null" : "object of type " + mxbean.getClass().getName();
    throw new OpenDataException(
            "Could not convert " + s + " to an ObjectName: " + wrong);
    // Message will be strange if mxbean is null but it is not
    // supposed to be.
}
MXBeanTest.java 文件源码 项目:openjdk-jdk10 阅读 28 收藏 0 点赞 0 评论 0
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) {
        if (o1 == o2)
            return true;
        if (o1 == null || o2 == null)
            return false;
        if (o1.getClass().isArray()) {
            if (!o2.getClass().isArray())
                return false;
            return deepEqual(o1, o2, namedMXBeans);
        }
        if (o1 instanceof Map) {
            if (!(o2 instanceof Map))
                return false;
            return equalMap((Map) o1, (Map) o2, namedMXBeans);
        }
        if (o1 instanceof CompositeData && o2 instanceof CompositeData) {
            return compositeDataEqual((CompositeData) o1, (CompositeData) o2,
                                      namedMXBeans);
        }
        if (Proxy.isProxyClass(o1.getClass())) {
            if (Proxy.isProxyClass(o2.getClass()))
                return proxyEqual(o1, o2, namedMXBeans);
            InvocationHandler ih = Proxy.getInvocationHandler(o1);
//            if (ih instanceof MXBeanInvocationHandler) {
//                return proxyEqualsObject((MXBeanInvocationHandler) ih,
//                                         o2, namedMXBeans);
            if (ih instanceof MBeanServerInvocationHandler) {
                return true;
            } else if (ih instanceof CompositeDataInvocationHandler) {
                return o2.equals(o1);
                // We assume the other object has a reasonable equals method
            }
        } else if (Proxy.isProxyClass(o2.getClass()))
            return equal(o2, o1, namedMXBeans);
        return o1.equals(o2);
    }
MXBeanLookup.java 文件源码 项目:openjdk9 阅读 25 收藏 0 点赞 0 评论 0
synchronized ObjectName mxbeanToObjectName(Object mxbean)
throws OpenDataException {
    String wrong;
    if (mxbean instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
        if (ih instanceof MBeanServerInvocationHandler) {
            MBeanServerInvocationHandler mbsih =
                    (MBeanServerInvocationHandler) ih;
            if (mbsih.getMBeanServerConnection().equals(mbsc))
                return mbsih.getObjectName();
            else
                wrong = "proxy for a different MBeanServer";
        } else
            wrong = "not a JMX proxy";
    } else {
        ObjectName name = mxbeanToObjectName.get(mxbean);
        if (name != null)
            return name;
        wrong = "not an MXBean registered in this MBeanServer";
    }
    String s = (mxbean == null) ?
        "null" : "object of type " + mxbean.getClass().getName();
    throw new OpenDataException(
            "Could not convert " + s + " to an ObjectName: " + wrong);
    // Message will be strange if mxbean is null but it is not
    // supposed to be.
}
TestUtils.java 文件源码 项目:openjdk9 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Returns the ObjectName of the MBean that a proxy object
 * is proxying.
 **/
public static ObjectName getObjectName(Object proxy) {
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (handler instanceof MBeanServerInvocationHandler)
        return ((MBeanServerInvocationHandler)handler).getObjectName();
    throw new IllegalArgumentException("not a JMX Proxy");
}
MXBeanTest.java 文件源码 项目:openjdk9 阅读 31 收藏 0 点赞 0 评论 0
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) {
        if (o1 == o2)
            return true;
        if (o1 == null || o2 == null)
            return false;
        if (o1.getClass().isArray()) {
            if (!o2.getClass().isArray())
                return false;
            return deepEqual(o1, o2, namedMXBeans);
        }
        if (o1 instanceof Map) {
            if (!(o2 instanceof Map))
                return false;
            return equalMap((Map) o1, (Map) o2, namedMXBeans);
        }
        if (o1 instanceof CompositeData && o2 instanceof CompositeData) {
            return compositeDataEqual((CompositeData) o1, (CompositeData) o2,
                                      namedMXBeans);
        }
        if (Proxy.isProxyClass(o1.getClass())) {
            if (Proxy.isProxyClass(o2.getClass()))
                return proxyEqual(o1, o2, namedMXBeans);
            InvocationHandler ih = Proxy.getInvocationHandler(o1);
//            if (ih instanceof MXBeanInvocationHandler) {
//                return proxyEqualsObject((MXBeanInvocationHandler) ih,
//                                         o2, namedMXBeans);
            if (ih instanceof MBeanServerInvocationHandler) {
                return true;
            } else if (ih instanceof CompositeDataInvocationHandler) {
                return o2.equals(o1);
                // We assume the other object has a reasonable equals method
            }
        } else if (Proxy.isProxyClass(o2.getClass()))
            return equal(o2, o1, namedMXBeans);
        return o1.equals(o2);
    }


问题


面经


文章

微信
公众号

扫码关注公众号