FileDocCategorySizeDatePackage
MXBeanLookup.javaAPI DocJava SE 6 API5176Tue Jun 10 00:22:02 BST 2008com.sun.jmx.mbeanserver

MXBeanLookup

public class MXBeanLookup extends Object
since
1.6

Fields Summary
private final MBeanServerConnection
mbsc
private final WeakIdentityHashMap
mxbeanToObjectName
private final Map
objectNameToProxy
private static WeakIdentityHashMap
mbscToLookup
Constructors Summary
private MXBeanLookup(MBeanServerConnection mbsc)

	this.mbsc = mbsc;
    
Methods Summary
synchronized voidaddReference(javax.management.ObjectName name, java.lang.Object mxbean)

        mxbeanToObjectName.put(mxbean, name);
    
static com.sun.jmx.mbeanserver.MXBeanLookuplookupFor(javax.management.MBeanServerConnection mbsc)

        synchronized (mbscToLookup) {
            WeakReference<MXBeanLookup> weakLookup = mbscToLookup.get(mbsc);
            MXBeanLookup lookup = (weakLookup == null) ? null : weakLookup.get();
            if (lookup == null) {
                lookup = new MXBeanLookup(mbsc);
                mbscToLookup.put(mbsc, new WeakReference<MXBeanLookup>(lookup));
            }
            return lookup;
        }
    
synchronized javax.management.ObjectNamemxbeanToObjectName(java.lang.Object mxbean)

        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();
            }
            return null;
        } else
            return mxbeanToObjectName.get(mxbean);
    
synchronized TobjectNameToMXBean(javax.management.ObjectName name, java.lang.Class type)

        WeakReference<Object> wr = objectNameToProxy.get(name);
	if (wr != null) {
	    Object proxy = wr.get();
	    if (type.isInstance(proxy))
		return type.cast(proxy);
	}
	InvocationHandler handler =
	    new MBeanServerInvocationHandler(mbsc, name);
	T proxy = JMX.newMXBeanProxy(mbsc, name, type);
	objectNameToProxy.put(name, new WeakReference<Object>(proxy));
	return proxy;
    
synchronized booleanremoveReference(javax.management.ObjectName name, java.lang.Object mxbean)

        if (name.equals(mxbeanToObjectName.get(mxbean))) {
            mxbeanToObjectName.remove(mxbean);
            return true;
        } else
            return false;
        /* removeReference can be called when the above condition fails,
         * notably if you try to register the same MXBean twice.
         */