|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread org.xins.common.io.FileWatcher
File watcher thread. This thread checks if a file changed and if it has, it notifies the listener. The check is performed every n seconds, where n can be configured.
Initially this thread will be a daemon thread. This can be changed by
calling Thread.setDaemon(boolean)
.
Nested Class Summary | |
static interface |
FileWatcher.Listener
Interface for file watcher listeners. |
Field Summary |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
FileWatcher(String file,
FileWatcher.Listener listener)
Creates a new FileWatcher for the specified file. |
|
FileWatcher(String file,
int interval,
FileWatcher.Listener listener)
Creates a new FileWatcher for the specified file, with the
specified interval. |
Method Summary | |
void |
check()
Checks if the file changed. |
void |
end()
Stops this thread. |
int |
getInterval()
Returns the current interval. |
void |
run()
Runs this thread. |
void |
setInterval(int newInterval)
Changes the file check interval. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, 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 |
Constructor Detail |
public FileWatcher(String file, int interval, FileWatcher.Listener listener) throws IllegalArgumentException
FileWatcher
for the specified file, with the
specified interval.
file
- the name of the file to watch, cannot be null
.interval
- the interval in seconds, must be greater than or equal to 1.listener
- the object to notify on events, cannot be null
.
IllegalArgumentException
- if file == null || listener == null || interval < 1
public FileWatcher(String file, FileWatcher.Listener listener) throws IllegalArgumentException
FileWatcher
for the specified file.
The interval must be set before the thread can be started.
file
- the name of the file to watch, cannot be null
.listener
- the object to notify on events, cannot be null
.
IllegalArgumentException
- if file == null || listener == null
Method Detail |
public void run() throws IllegalStateException
Thread.start()
instead. That method will call this method.
IllegalStateException
- if Thread.currentThread()
!= this
, if the thread
is already running or should stop, or if the interval was not set
yet.public int getInterval()
public void setInterval(int newInterval) throws IllegalArgumentException
newInterval
- the new interval in seconds, must be greater than or equal to 1.
IllegalArgumentException
- if interval < 1
public void end() throws IllegalStateException
IllegalStateException
- if the thread is currently not running or already stopping.public void check()
SecurityException
to be thrown, then
FileWatcher.Listener.securityException(SecurityException)
is called
and the method returns;
FileWatcher.Listener.fileNotFound()
is called and the method returns;
FileWatcher.Listener.fileFound()
is called and the method
returns;
FileWatcher.Listener.fileModified()
is called and the method returns;
FileWatcher.Listener.fileNotModified()
is called and the method
returns.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |