private static Set<ObjectName> findObjects(JmxToolOptions options,
                                               MBeanServerConnection conn,
                                               List<ObjectName> queries,
                                               boolean hasPatternQueries) throws Exception {
        long waitTimeoutMs = 10_000;
        Set<ObjectName> result = new HashSet<>();
        Set<ObjectName> querySet = new HashSet<>(queries);
        BiPredicate<Set<ObjectName>, Set<ObjectName>> foundAllObjects = Set::equals;
        long start = System.currentTimeMillis();
        do {
            if (!result.isEmpty()) {
                System.err.println("Could not find all object names, retrying");
                TimeUnit.MILLISECONDS.sleep(100);
            }
            result.addAll(queryObjects(conn, queries));
        } while (!hasPatternQueries && options.hasWait() && System.currentTimeMillis() - start < waitTimeoutMs && !foundAllObjects.test(querySet, result));

        if (!hasPatternQueries && options.hasWait() && !foundAllObjects.test(querySet, result)) {
            querySet.removeAll(result);
            String missing = mkString(querySet.stream().map(Object::toString), ",");
            throw new TerseException(String.format("Could not find all requested object names after %d ms. Missing %s", waitTimeoutMs, missing));
        }
        return result;
    }
A program for reading JMX metrics from a given endpoint.
<p>
This tool only works reliably if the JmxServer is fully initialized prior to invoking the tool.
See KAFKA-4620 for details.
tools/src/main/java/org/apache/kafka/tools/JmxTool.java