|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.lang.Thread
|
+--org.mmbase.util.FileWatcher
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 |
public static final long DEFAULT_DELAY
| Constructor Detail |
protected FileWatcher()
protected FileWatcher(boolean c)
| Method Detail |
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..public void exit()
file - The file which has to be monitored..public void run()
run in class java.lang.Thread
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||