/** * Helper method to query {@link ObjectName}s from an {@link MBeanServer} * based on {@link Predicate} * * @param server * @param predicate * @return */ public static Set<ObjectName> queryNames(MBeanServer server, final Predicate<ObjectName> predicate) { @SuppressWarnings("serial") Set<ObjectName> registered = server.queryNames(null, new QueryExp() { @Override public void setMBeanServer(MBeanServer s) { } @Override public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException { return predicate.test(name); } }); return registered; }