X-Git-Url: http://git.megacz.com/?p=org.ibex.jinetd.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FWatcher.java;fp=src%2Forg%2Fibex%2Fjinetd%2FWatcher.java;h=980f864180a0b2c582015c3e5bfbb6fcbe3708ad;hp=19a33d60b83643fbb35610e0e69f86e09043d167;hb=501b9089d3cf777fc417d9bcddba9bc542a086f9;hpb=583587a3f34a3d2939bcc2b7bcab51b871f2b0c7 diff --git a/src/org/ibex/jinetd/Watcher.java b/src/org/ibex/jinetd/Watcher.java index 19a33d6..980f864 100644 --- a/src/org/ibex/jinetd/Watcher.java +++ b/src/org/ibex/jinetd/Watcher.java @@ -7,9 +7,29 @@ import org.ibex.util.*; import java.io.*; import java.util.*; -public abstract class Watcher extends Watched { +public abstract class Watcher extends File { + protected Watcher(String path) { super(path); } - public Watcher watcher() { return this; } - public abstract void changed(Watched w); - public synchronized void scan() throws IOException { super.scan(); } + + public abstract void changed(File f) throws IOException; + + private Vec watched = new Vec(); + + public void watch(File f) { watched.addElement(new Watched(f.getAbsolutePath())); } + public void watch(String s) { watch(getAbsolutePath() + File.separatorChar + s); } + + public void scan() throws IOException { + for(int i=watched.size()-1; i>=0; i--) + ((Watched)(watched.elementAt(i))).scan(); + } + + private class Watched extends File { + long lastModifiedAtLastScan = -1; + public Watched(String s) { super(s); } + public void scan() throws IOException { + // FIXME + //if (!exists()) { Watcher.this.changed(this); Watcher.this.watched.remove(this); return; } + if (lastModifiedAtLastScan != lastModified()) { Watcher.this.changed(this); lastModifiedAtLastScan = lastModified(); } + } + } }