org.mmbase.util
Class FileWatcher

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.mmbase.util.FileWatcher
All Implemented Interfaces:
java.lang.Runnable

public abstract class FileWatcher
extends java.lang.Thread

This will run as a thread afer it has been started, it will check every interval if one of it's files has been changed. When one of them has been changed, the OnChange method will be called, with the file witch was changed. After that the thread will stop. To stop a running thread, call the method exit(); Example: class FooFileWatcher extends FileWatcher { public FooFileWatcher() { super(true); // true: keep reading. } public void onChange(File file) { System.out.println(file.getAbsolutePath()); } } // create new instance FooFileWatcher watcher = new FooFileWatcher(); // set inteval watcher.setDelay(10 * 1000); watcher.add(new File("/tmp/foo.txt")); watcher.start(); watcher.add(new File("/tmp/foo.txt")); wait(100*1000); watcher.exit();


Field Summary
static long DEFAULT_DELAY
          The default delay between every file modification check, set to 60 seconds.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected FileWatcher()
           
protected FileWatcher(boolean c)
           
 
Method Summary
 void add(java.io.File file)
          Add's a file to be checked...
 void exit()
          Add's a file to be checked...
protected abstract  void onChange(java.io.File file)
          Put here the stuff that has to be executed, when a file has been changed.
 void run()
          Main loop, will repeat every amount of time.
 void setDelay(long delay)
          Set the delay to observe between each check of the file changes.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DELAY

public static final long DEFAULT_DELAY
The default delay between every file modification check, set to 60 seconds.
Constructor Detail

FileWatcher

protected FileWatcher()

FileWatcher

protected FileWatcher(boolean c)
Method Detail

onChange

protected abstract void onChange(java.io.File file)
Put here the stuff that has to be executed, when a file has been changed.
Parameters:
file - The file that was changed..

setDelay

public void setDelay(long delay)
Set the delay to observe between each check of the file changes.

add

public void add(java.io.File file)
Add's a file to be checked...
Parameters:
file - The file which has to be monitored..

exit

public void exit()
Add's a file to be checked...
Parameters:
file - The file which has to be monitored..

run

public void run()
Main loop, will repeat every amount of time. It will stop, when either a file has been changed, or exit() has been called
Overrides:
run in class java.lang.Thread


MMBase 2002