|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.mmbase.util.FileWatcher
This will run as a thread after 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 that
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();
Thanks to contributions by Mathias Bogaert.
Licence was changed from apache 1.1 to Mozilla.
| Field Summary | |
static long |
DEFAULT_DELAY
The default delay between every file modification check, set to 60 seconds. |
static long |
THREAD_DELAY
The one thread doing al the work also needs a delay. |
| Constructor Summary | |
protected |
FileWatcher()
|
protected |
FileWatcher(boolean c)
|
| Method Summary | |
void |
add(java.io.File file)
Add's a file to be checked... |
boolean |
contains(java.io.File file)
Wether the file is being watched or not. |
boolean |
equals(java.lang.Object o)
|
void |
exit()
|
static void |
main(java.lang.String[] args)
|
protected abstract void |
onChange(java.io.File file)
Put here the stuff that has to be executed, when a file has been changed. |
void |
remove(java.io.File file)
Remove file from the watch-list |
void |
setDelay(long delay)
Set the delay to observe between each check of the file changes. |
void |
start()
|
java.lang.String |
toString()
Shows the 'contents' of the filewatcher. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final long DEFAULT_DELAY
public static final long THREAD_DELAY
| Constructor Detail |
protected FileWatcher()
protected FileWatcher(boolean c)
| Method Detail |
public void start()
protected abstract void onChange(java.io.File file)
file - The file that was changed..public void setDelay(long delay)
public void add(java.io.File file)
file - The file which has to be monitored..
java.lang.RuntimeException - If file is null or does not exist.public boolean contains(java.io.File file)
public void remove(java.io.File file)
public void exit()
public java.lang.String toString()
public boolean equals(java.lang.Object o)
public static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||