View Javadoc

1   // Copyright 2003-2005 Arthur van Hoff, Rick Blair
2   // Licensed under Apache License version 2.0
3   // Original license LGPL
4   
5   package javax.jmdns.impl.tasks;
6   
7   import java.util.Timer;
8   import java.util.logging.Level;
9   import java.util.logging.Logger;
10  
11  import javax.jmdns.impl.JmDNSImpl;
12  import javax.jmdns.impl.constants.DNSConstants;
13  
14  /**
15   * Periodically removes expired entries from the cache.
16   */
17  public class RecordReaper extends DNSTask {
18      static Logger logger = Logger.getLogger(RecordReaper.class.getName());
19  
20      /**
21       * @param jmDNSImpl
22       */
23      public RecordReaper(JmDNSImpl jmDNSImpl) {
24          super(jmDNSImpl);
25      }
26  
27      /*
28       * (non-Javadoc)
29       * @see javax.jmdns.impl.tasks.DNSTask#getName()
30       */
31      @Override
32      public String getName() {
33          return "RecordReaper(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
34      }
35  
36      /*
37       * (non-Javadoc)
38       * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer)
39       */
40      @Override
41      public void start(Timer timer) {
42          if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) {
43              timer.schedule(this, DNSConstants.RECORD_REAPER_INTERVAL, DNSConstants.RECORD_REAPER_INTERVAL);
44          }
45      }
46  
47      @Override
48      public void run() {
49          if (this.getDns().isCanceling() || this.getDns().isCanceled()) {
50              return;
51          }
52          if (logger.isLoggable(Level.FINEST)) {
53              logger.finest(this.getName() + ".run() JmDNS reaping cache");
54          }
55  
56          // Remove expired answers from the cache
57          // -------------------------------------
58          this.getDns().cleanCache();
59      }
60  
61  }