public static List<SrvRecord> srvLookup(@Nonnull final String service, @Nonnull final String proto, @Nonnull final String name) {
        logger.debug("DNS SRV Lookup for service '{}', protocol '{}' and name '{}'", service, proto, name);

        final String lookup = constructLookup(service, proto, name);

        final CacheableOptional<SrvRecord[]> optional = LOOKUP_CACHE.get(lookup);
        SrvRecord[] result;
        if (optional != null) {
            // Return a cached result.
            if (optional.isAbsent()) {
                logger.debug("DNS SRV lookup previously failed for '{}' (negative cache result)", lookup);
                result = new SrvRecord[0];
            } else {
                result = optional.get();
                if ( result.length == 0 ) {
                    logger.debug("No SRV record found for '{}' (cached result)", lookup);
                } else {
                    logger.trace("{} SRV record(s) found for '{}' (cached result)", result.length, lookup);
                }
            }
        } else {
            // No result in cache. Query DNS and cache result.
            try {
                final Attributes dnsLookup = context.getAttributes(lookup, new String[]{"SRV"});
                final Attribute srvRecords = dnsLookup.get("SRV");
                if (srvRecords == null) {
                    logger.trace("No SRV record found for '{}'", lookup);
                    result = new SrvRecord[0];
                } else {
                    result = new SrvRecord[srvRecords.size()];
                    final boolean directTLS = lookup.startsWith("_xmpps-"); // XEP-0368
                    for (int i = 0; i < srvRecords.size(); i++) {
                        result[i] = SrvRecord.from(((String) srvRecords.get(i)).split(" "), directTLS);
                    }
                    logger.trace("{} SRV record(s) found for '{}':", result.length, lookup);
                    for (SrvRecord srvRecord : result) {
                        logger.trace(" - {}", srvRecord);
                    }
                }
                LOOKUP_CACHE.put(lookup, CacheableOptional.of(result));
            } catch (NameNotFoundException e) {
                logger.trace("No SRV record found for '{}'", lookup);
                LOOKUP_CACHE.put(lookup, CacheableOptional.of(new SrvRecord[0])); // Empty result (different from negative result!)
                result = new SrvRecord[0];
            } catch (NamingException e) {
                logger.debug("DNS SRV lookup was unsuccessful for '{}': {}", lookup, e);
                LOOKUP_CACHE.put(lookup, CacheableOptional.of(null)); // Negative result cache (different from empty result!)
                result = new SrvRecord[0];
            }
        }

        // Do not store _prioritized_ results in the cache, as there is a random element to the prioritization that needs to happen every time.
        return SrvRecord.prioritize(result).stream().flatMap(Set::stream).collect(Collectors.toList());
    }
Performs a DNS SRV lookup. Does not take into account any DNS overrides configured in this class.

The results returned by this method are ordered by priority (ascending), and order of equal priority entries is
randomized by weight, as defined in the DNS SRV specification.

@param service the symbolic name of the desired service.
@param proto the transport protocol of the desired service; this is usually either TCP or UDP.
@param name the domain name for which this record is valid.
@return An ordered list of results (possibly empty, never null).
xmppserver/src/main/java/org/jivesoftware/openfire/net/DNSUtil.java