org.xins.common.io
Class HTTPFileWatcher

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.xins.common.io.FileWatcher
          extended byorg.xins.common.io.HTTPFileWatcher
All Implemented Interfaces:
Runnable

public class HTTPFileWatcher
extends FileWatcher

File watcher thread. This thread checks if a URL or a set of URLs 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).

Since:
XINS 2.1
Version:
$Revision: 1.3 $ $Date: 2007/09/18 11:21:09 $
Author:
Anthony Goubard

Nested Class Summary
 
Nested classes inherited from class org.xins.common.io.FileWatcher
FileWatcher.Listener
 
Field Summary
 
Fields inherited from class org.xins.common.io.FileWatcher
_filePaths, _lastModified
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
HTTPFileWatcher(String[] urls, int interval, FileWatcher.Listener listener)
          Creates a new HTTPFileWatcher for the specified set of URLs, with the specified interval.
HTTPFileWatcher(String url, FileWatcher.Listener listener)
          Creates a new HTTPFileWatcher for the specified URL.
HTTPFileWatcher(String url, int interval, FileWatcher.Listener listener)
          Creates a new HTTPFileWatcher for the specified URL, with the specified interval.
 
Method Summary
protected  void firstCheck()
          Performs the first check on the file to determine the date the file was last modified.
protected  long getLastModified()
          Gets the time at which the last file was modified.
protected  void storeFiles(String[] files)
          Stores the files in a class variable.
 
Methods inherited from class org.xins.common.io.FileWatcher
check, end, getInterval, run, setInterval
 
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

HTTPFileWatcher

public HTTPFileWatcher(String url,
                       FileWatcher.Listener listener)
                throws IllegalArgumentException
Creates a new HTTPFileWatcher for the specified URL.

The interval must be set before the thread can be started.

Parameters:
url - the name of the URL to watch, cannot be null.
listener - the object to notify on events, cannot be null.
Throws:
IllegalArgumentException - if url == null || listener == null

HTTPFileWatcher

public HTTPFileWatcher(String url,
                       int interval,
                       FileWatcher.Listener listener)
                throws IllegalArgumentException
Creates a new HTTPFileWatcher for the specified URL, with the specified interval.

Parameters:
url - the name of the URL to watch, cannot be null.
interval - the interval in seconds, must be greater than or equal to 0. if the interval is 0 the interval must be set before the thread can be started.
listener - the object to notify on events, cannot be null.
Throws:
IllegalArgumentException - if url == null || listener == null || interval < 0

HTTPFileWatcher

public HTTPFileWatcher(String[] urls,
                       int interval,
                       FileWatcher.Listener listener)
                throws IllegalArgumentException
Creates a new HTTPFileWatcher for the specified set of URLs, with the specified interval.

Parameters:
urls - the name of the URLs to watch, cannot be null. It should also have at least one URL and none of the URLs should be null.
interval - the interval in seconds, must be greater than or equal to 0. if the interval is 0 the interval must be set before the thread can be started.
listener - the object to notify on events, cannot be null.
Throws:
IllegalArgumentException - if urls == null || listener == null || interval < 0 || urls.length < 1 or if one of the URL is null.
Method Detail

storeFiles

protected void storeFiles(String[] files)
Description copied from class: FileWatcher
Stores the files in a class variable.

Overrides:
storeFiles in class FileWatcher
Parameters:
files - the String files to check, cannot be null.

firstCheck

protected void firstCheck()
Description copied from class: FileWatcher
Performs the first check on the file to determine the date the file was last modified. This method is called from the constructors. If the file cannot be accessed due to a SecurityException, then this exception is logged and ignored.

Overrides:
firstCheck in class FileWatcher

getLastModified

protected long getLastModified()
                        throws SecurityException
Description copied from class: FileWatcher
Gets the time at which the last file was modified. If for any reason, a file could no be read -1 is returned.

Overrides:
getLastModified in class FileWatcher
Returns:
the time of the last modified file or -1.
Throws:
SecurityException - if one of the file could not be read because of a security issue.


See http://www.xins.org/.