X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FWatcher.java;h=265073c0da6edc74e11737841d4f2c3e609bbfb5;hb=c28d954263d3a9b5f8ea3ff37368ae811ff48f6c;hp=39edb17f7ac6c555244532616177f8b1685d9cd1;hpb=ac27342830d303ba1043db68f295875fe3a1ef4d;p=org.ibex.jinetd.git diff --git a/src/org/ibex/jinetd/Watcher.java b/src/org/ibex/jinetd/Watcher.java index 39edb17..265073c 100644 --- a/src/org/ibex/jinetd/Watcher.java +++ b/src/org/ibex/jinetd/Watcher.java @@ -1,11 +1,35 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.jinetd; 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(new File(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(); } + } + } }