private Message getCached(Message query) { Cache cache = getCache(); if (cache == null) return null; Record question = query.getQuestion(); RRset[] rrsets = cache.findAnyRecords(question.getName(), question.getType()); if (rrsets == null) return null; Message msg = new Message(); for (RRset rrset : rrsets) { @SuppressWarnings("unchecked") Iterator<Record> recordsIter = rrset.rrs(); while (recordsIter.hasNext()) { msg.addRecord(recordsIter.next(), Section.ANSWER); } } return msg; }
public DNSCacheManager() { setProperty(new CollectionProperty(SERVERS, new ArrayList<String>())); //disabling cache lookupCache = new Cache(); lookupCache.setMaxCache(0); lookupCache.setMaxEntries(0); }
/** * Overloaded constructor taking as argument Cache size and TTL. * * @param cacheSize Unsigned <code>int</code> defining the Cache size * @param cacheTTL Unsigned <code>int</code> defining the Cache TTL */ public DnsServicesDiscovery(int cacheSize, int cacheTTL) { this.anyClassCache = new Cache(DClass.ANY); this.anyClassCache.setMaxEntries(cacheSize); this.anyClassCache.setMaxNCache(cacheTTL); this.helper = this.new ServicesLookupHelper(); this.errorsTrace = new ThreadLocal<Map<String, StatusCode>>() { @Override protected Map<String, StatusCode> initialValue() { return new LinkedHashMap<>(); } }; }
private Lookup doLookup(final SimpleResolver resolver, String hostname) throws TextParseException { final Cache cache = new Cache(); final Lookup lookup = new Lookup(new Name(hostname), org.xbill.DNS.Type.SRV); lookup.setResolver(resolver); lookup.setCache(cache); return lookup; }
private void addCached(Message msg) { Cache cache = getCache(); if (cache != null) cache.addMessage(msg); }
@PostConstruct public void init() throws Exception { logger.debug("DNSService init..."); // If no DNS servers were configured, default to local host if (dnsServers.isEmpty()) { try { dnsServers.add(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException ue) { dnsServers.add("127.0.0.1"); } } // Create the extended resolver... final String[] serversArray = (String[]) dnsServers.toArray(new String[0]); if (logger.isInfoEnabled()) { for (int c = 0; c < serversArray.length; c++) { logger.info("DNS Server is: " + serversArray[c]); } } try { resolver = new ExtendedResolver(serversArray); } catch (UnknownHostException uhe) { logger.error("DNS service could not be initialized. The DNS servers specified are not recognized hosts.", uhe); throw uhe; } cache = new Cache(DClass.IN); cache.setMaxEntries(maxCacheSize); if (setAsDNSJavaDefault) { Lookup.setDefaultResolver(resolver); Lookup.setDefaultCache(cache, DClass.IN); Lookup.setDefaultSearchPath(searchPaths); logger.info("Registered cache, resolver and search paths as DNSJava defaults"); } // Cache the local hostname and local address. This is needed because // the following issues: // JAMES-787 // JAMES-302 InetAddress addr = getLocalHost(); localCanonicalHostName = addr.getCanonicalHostName(); localHostName = addr.getHostName(); localAddress = addr.getHostAddress(); logger.debug("DNSService ...init end"); }
public void setCache(Cache c) { cache = c; }