1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.jinetd;
6 import org.ibex.util.*;
10 public abstract class Watcher extends File {
12 protected Watcher(String path) { super(path); }
14 public abstract void changed(File f) throws IOException;
16 private Vec watched = new Vec();
18 public void watch(File f) { watched.addElement(new Watched(f.getAbsolutePath())); }
19 public void watch(String s) { watch(new File(getAbsolutePath() + File.separatorChar + s)); }
21 public void scan() throws IOException {
22 for(int i=watched.size()-1; i>=0; i--)
23 ((Watched)(watched.elementAt(i))).scan();
26 private class Watched extends File {
27 long lastModifiedAtLastScan = -1;
28 public Watched(String s) { super(s); }
29 public void scan() throws IOException {
31 //if (!exists()) { Watcher.this.changed(this); Watcher.this.watched.remove(this); return; }
32 if (lastModifiedAtLastScan != lastModified()) { Watcher.this.changed(this); lastModifiedAtLastScan = lastModified(); }