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 /** a "watched" file */
21 public class WatchedFile extends File {
23 private static Vec files = new Vec();
25 private long lastModified = 0;
27 public void deleted() { }
28 public void modified() { }
30 public WatchedFile(String s) throws IOException {
32 if (!this.exists()) throw new IOException("file " + this + " does not exist");
33 lastModified = lastModified();
34 //lastSize = length();
38 private static Thread watcherThread = new ImmortalThread(2000) {
40 public void cycle() throws Exception {
41 while(i<files.size()) {
42 final WatchedFile f = (WatchedFile)files.get(i++);
45 new ResponseThread() { public void run2() throws Exception { f.deleted(); } }.start();
47 } else if (f.lastModified()!=f.lastModified) {
48 f.lastModified = f.lastModified();
49 new ResponseThread() { public void run2() throws Exception { f.modified(); } }.start();
55 static { watcherThread.start(); }
57 // FIXME: throttle these somehow?
58 private abstract static class ResponseThread extends Thread {
59 public abstract void run2() throws Exception;
63 } catch (Exception e) { Log.error(this, e); }