コード例 #1
0
  /**
   * Start watching at a given polling rate
   *
   * @param pollFrequency The poll rate
   */
  public void start(final Duration pollFrequency) {
    // Construct task with the given polling frequency
    task = new Task("ModificationWatcher");

    task.run(
        pollFrequency,
        new ICode() {
          public void run(final Log log) {
            // Iterate over a copy of the list of entries to avoid
            // concurrent
            // modification problems without the associated liveness issues
            // of holding a lock while potentially polling file times!
            for (final Iterator<Entry> iterator =
                    new ArrayList<Entry>(modifiableToEntry.values()).iterator();
                iterator.hasNext(); ) {
              // Get next entry
              final Entry entry = iterator.next();

              // If the modifiable has been modified after the last known
              // modification time
              final Time modifiableLastModified = entry.modifiable.lastModifiedTime();

              if (modifiableLastModified.after(entry.lastModifiedTime)) {
                // Notify all listeners that the modifiable was modified
                entry.listeners.notifyListeners();

                // Update timestamp
                entry.lastModifiedTime = modifiableLastModified;
              }
            }
          }
        });
  }
コード例 #2
0
 /** stops the modification watcher from watching. */
 public void destroy() {
   if (task != null) {
     task.stop();
   }
 }