Search in sources :

Example 6 with MBeanServerInvocationHandler

use of javax.management.MBeanServerInvocationHandler in project jdk8u_jdk by JetBrains.

the class MXBeanLookup method mxbeanToObjectName.

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.
}
Also used : Proxy(java.lang.reflect.Proxy) OpenDataException(javax.management.openmbean.OpenDataException) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServerInvocationHandler (javax.management.MBeanServerInvocationHandler)6 ObjectName (javax.management.ObjectName)4 InvocationHandler (java.lang.reflect.InvocationHandler)3 Proxy (java.lang.reflect.Proxy)3 MBeanServerConnection (javax.management.MBeanServerConnection)2 OpenDataException (javax.management.openmbean.OpenDataException)2 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Attribute (javax.management.Attribute)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanServer (javax.management.MBeanServer)1 MBeanServerDelegate (javax.management.MBeanServerDelegate)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotificationEmitter (javax.management.NotificationEmitter)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1