1 // Copyright 2000-2006 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.
10 import java.util.zip.*;
11 import org.ibex.util.*;
14 // FIXME: this needs to be robust against a getLastModified() call
15 // that hangs forever... what we need is a "watcher watcher" thread
16 // that spawns a new watcher and leaves a note for the old watcher
17 // telling him he's been left behind.
20 // FIXME: use cronjob api
22 /** a "watched" file */
23 public class WatchedFile extends File {
25 private static Vec files = new Vec();
27 private long lastModified = 0;
29 public void deleted() { }
30 public void modified() { }
32 public WatchedFile(String s) throws IOException {
34 if (!this.exists()) throw new IOException("file " + this + " does not exist");
35 lastModified = lastModified();
36 //lastSize = length();
40 private static Thread watcherThread = new ImmortalThread(2000) {
42 public void cycle() throws Exception {
43 while(i<files.size()) {
44 final WatchedFile f = (WatchedFile)files.get(i++);
47 new ResponseThread() { public void run2() throws Exception { f.deleted(); } }.start();
49 } else if (f.lastModified()!=f.lastModified) {
50 f.lastModified = f.lastModified();
51 new ResponseThread() { public void run2() throws Exception { f.modified(); } }.start();
57 static { watcherThread.start(); }
59 // FIXME: throttle these somehow?
60 private abstract static class ResponseThread extends Thread {
61 public abstract void run2() throws Exception;
65 } catch (Exception e) { Log.error(this, e); }