org.zkoss.io
Class FileWatchdog

java.lang.Object
  extended by java.lang.Thread
      extended by org.zkoss.io.FileWatchdog
All Implemented Interfaces:
java.lang.Runnable

public class FileWatchdog
extends java.lang.Thread

File modification monitor thread. It monitors a gving file in a lowest priority thread. Then, if it detects any modification, invokes a giving interface. Note: Callback.onModified is at least called once.

Caller has to implement the FileWatchdog.Callback interface. Then,
new FileWatchdog(filename, 30000, callback).start();

This class is extended from Thread, so you could manipulate it as a normal thread, such as interrupt, suspend, and change priority.

The watchdog executes at the lowest priority, so it won't affect much of the system performance.

Author:
tomyeh

Nested Class Summary
static interface FileWatchdog.Callback
          The interface to implement when using a FileWatchdog.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FileWatchdog(java.io.File file, long delay, FileWatchdog.Callback callback)
          Constructor.
FileWatchdog(java.lang.String filename, long delay, FileWatchdog.Callback callback)
          Constructor.
 
Method Summary
 void cease()
          Stops the thread.
 void run()
           
 void start()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileWatchdog

public FileWatchdog(java.io.File file,
                    long delay,
                    FileWatchdog.Callback callback)
Constructor.

Parameters:
file - the file
delay - the delay in milliseconds to wait between each check
callback - the callback

FileWatchdog

public FileWatchdog(java.lang.String filename,
                    long delay,
                    FileWatchdog.Callback callback)
Constructor.

Parameters:
filename - the filename
delay - the delay in milliseconds to wait between each check
callback - the callback
Method Detail

start

public void start()
Overrides:
start in class java.lang.Thread

cease

public void cease()
Stops the thread.


run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo