synchronized <T> T objectNameToMXBean(ObjectName name, Class<T> 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; }
<T> MBeanSupport(T resource, Class<T> mbeanInterface) throws NotCompliantMBeanException { if (mbeanInterface == null) throw new NotCompliantMBeanException("Null MBean interface"); if (!mbeanInterface.isInstance(resource)) { final String msg = "Resource class " + resource.getClass().getName() + " is not an instance of " + mbeanInterface.getName(); throw new NotCompliantMBeanException(msg); } this.resource = resource; MBeanIntrospector introspector = getMBeanIntrospector(); this.perInterface = introspector.getPerInterface(mbeanInterface); this.mbeanInfo = introspector.getMBeanInfo(resource, perInterface); }