/** * Add a listener for a question. The listener will receive updates * of answers to the question as they arrive, or from the cache if they * are already available. */ void addListener(DNSListener listener, DNSQuestion question) { long now = System.currentTimeMillis(); // add the new listener synchronized (this) { listeners.add(listener); } // report existing matched records if (question != null) { for (DNSCache.CacheNode i = cache.find(question.name); i != null; i = i.next()) { DNSRecord c = (DNSRecord) i.getValue(); if (question.answeredBy(c) && !c.isExpired(now)) { listener.updateRecord(this, now, c); } } } }