home *** CD-ROM | disk | FTP | other *** search
- package org.xbill.DNS;
-
- import java.lang.ref.Reference;
- import java.lang.ref.WeakReference;
- import java.util.ConcurrentModificationException;
- import java.util.Iterator;
-
- class Cache$CacheCleaner extends Thread {
- private Reference cacheref;
- private long interval;
-
- public Cache$CacheCleaner(Cache cache, int cleanInterval) {
- this.cacheref = new WeakReference(cache);
- this.interval = (long)(cleanInterval * 60 * 1000);
- this.setDaemon(true);
- this.setName("org.xbill.DNS.Cache.CacheCleaner");
- this.start();
- }
-
- private boolean clean(Cache cache) {
- Iterator it = cache.names();
-
- while(it.hasNext()) {
- Name name;
- try {
- name = (Name)it.next();
- } catch (ConcurrentModificationException var7) {
- return false;
- }
-
- Object[] elements = cache.findExactSets(name);
-
- for(int i = 0; i < elements.length; ++i) {
- Cache.Element element = (Cache.Element)elements[i];
- if (element.expired()) {
- cache.removeSet(name, element.getType(), element);
- }
- }
- }
-
- return true;
- }
-
- public void run() {
- while(true) {
- long now = System.currentTimeMillis();
-
- for(long next = now + this.interval; now < next; now = System.currentTimeMillis()) {
- try {
- Thread.sleep(next - now);
- } catch (InterruptedException var7) {
- return;
- }
- }
-
- Cache cache = (Cache)this.cacheref.get();
- if (cache == null) {
- return;
- }
-
- for(int i = 0; i < 4 && !this.clean(cache); ++i) {
- }
- }
- }
- }
-