org.jconfig
Class FileWatcher

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.jconfig.FileWatcher
All Implemented Interfaces:
java.lang.Runnable

public class FileWatcher
extends java.lang.Thread

A class which implements an event dispatching mechanism to all classes supporting the FileListener interface. This class will notify all FileListeners when the configuration changes. Once the FileWatcher has been shutdown, the class needs to be reinstanciated and restarted.

Author:
Andreas Mecky , Terry R. Dye

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FileWatcher(java.io.File file)
          Constructs a FileWatcher watching the specified File
FileWatcher(java.lang.String filename)
          Creates a new instance of FileWatcher by calling the FileWatcher( File ) Constructor.
 
Method Summary
 void addFileListener(FileListener fileListener)
          Adds FileListener
 FileListener[] getFileListeners()
          Retrieve an array of FileListeners.
static void main(java.lang.String[] args)
          Used to test it all
 void run()
          Start the thread to call checkFile()
 void setFile(java.io.File file)
          Sets a new File to be watched.
 void setInterval(int seconds)
          Set the timer interval.
 void start()
          Start the Thread on its journey to scan for changes to the file it is watching.
 void stopWatching()
          Tell thread to stop watching.
 
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, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileWatcher

public FileWatcher(java.lang.String filename)
Creates a new instance of FileWatcher by calling the FileWatcher( File ) Constructor.

Parameters:
filename - A String representing the path to the file to be watched.

FileWatcher

public FileWatcher(java.io.File file)
Constructs a FileWatcher watching the specified File

Parameters:
file - The File to be watched
Method Detail

addFileListener

public void addFileListener(FileListener fileListener)
Adds FileListener

Parameters:
fileListener - The FileListener

setInterval

public void setInterval(int seconds)
Set the timer interval. The default is 10 seconds

Parameters:
seconds - The number of seconds to set the interval when to check for the changes to the file.

stopWatching

public void stopWatching()
Tell thread to stop watching. Currently once a Thread is started and stopped, a new FileWatcher will be required.


start

public void start()
Start the Thread on its journey to scan for changes to the file it is watching.


run

public void run()
Start the thread to call checkFile()


getFileListeners

public FileListener[] getFileListeners()
Retrieve an array of FileListeners.

Returns:
FileListeners as array of FileListener

setFile

public void setFile(java.io.File file)
Sets a new File to be watched. This causes the FileWatcher to watch the given File and disregard the File that was used during Construction.

Parameters:
file - The File to be watched

main

public static void main(java.lang.String[] args)
Used to test it all

Parameters:
args - None required


Copyright © 2001-2005 Andreas Mecky, Terry Dye. All Rights Reserved.