AbstractMBeanServerExecutor implements MBeanServerExecutor, NotificationListener { public void each(ObjectName pObjectName, MBeanEachCallback pCallback) throws IOException, ReflectionException, MBeanException { try { Set<ObjectName> visited = new HashSet<ObjectName>(); for (MBeanServerConnection server : getMBeanServers()) { for (ObjectName nameObject : server.queryNames(pObjectName, null)) { if (!visited.contains(nameObject)) { pCallback.callback(server, nameObject); visited.add(nameObject); } } } } catch (InstanceNotFoundException exp) { throw new IllegalArgumentException("Cannot find MBean " + (pObjectName != null ? "(MBean " + pObjectName + ")" : "") + ": " + exp,exp); } }  void each(ObjectName pObjectName, MBeanEachCallback pCallback); T call(ObjectName pObjectName, MBeanAction<T> pMBeanAction, Object ... pExtraArgs); Set<ObjectName> queryNames(ObjectName pObjectName); void unregisterFromMBeanNotifications(); void handleNotification(Notification pNotification, Object pHandback); boolean hasMBeansListChangedSince(long pTimestamp);  }
@Test public void eachNull() throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException, IOException, ReflectionException { executor.each(null, new MBeanServerExecutor.MBeanEachCallback() { public void callback(MBeanServerConnection pConn, ObjectName pName) throws ReflectionException, InstanceNotFoundException, IOException, MBeanException { checkHiddenMBeans(pConn, pName); } }); }
@Test public void eachObjectName() throws MalformedObjectNameException, MBeanException, IOException, ReflectionException, NotCompliantMBeanException, InstanceAlreadyExistsException { for (final ObjectName name : new ObjectName[] { new ObjectName("test:type=one"), new ObjectName("test:type=two") }) { executor.each(name,new MBeanServerExecutor.MBeanEachCallback() { public void callback(MBeanServerConnection pConn, ObjectName pName) throws ReflectionException, InstanceNotFoundException, IOException, MBeanException { assertEquals(pName,name); checkHiddenMBeans(pConn,pName); } }); } }