net.larsan.urd.util.fileset
Class WatchedFileSet

java.lang.Object
  |
  +--net.larsan.urd.util.fileset.FileSet
        |
        +--net.larsan.urd.util.fileset.RegexpFileSet
              |
              +--net.larsan.urd.util.fileset.WatchedFileSet
All Implemented Interfaces:
ResourceLocator, WatchableFileSet
Direct Known Subclasses:
ClassFileSet

public class WatchedFileSet
extends RegexpFileSet
implements WatchableFileSet

This file set is a RegexpFileSet that implements the WatchableFileSet interface. this class uses a java.util.Timer to regulary scan the set for changes, this timer can be provided by the controlling class in order to minimize the use of thread when having multiple file sets.

In order to control the timer threads this class should be started and stopped.

This files set recurses through subfolders by default and is synchronized.

This class does not support signed resources.

Version:
Alpha-0.1 / 2002-10-06 21:37
Author:
Lars J. Nilsson

Field Summary
 
Fields inherited from class net.larsan.urd.util.fileset.RegexpFileSet
resources
 
Fields inherited from class net.larsan.urd.util.fileset.FileSet
root
 
Constructor Summary
WatchedFileSet(java.io.File root)
          Contruct the file without a regular expression or without an external timer.
WatchedFileSet(java.io.File root, java.lang.String regexp)
          Contruct the file set using a regular expression but without an external timer.
WatchedFileSet(java.io.File root, java.lang.String regexp, java.util.Timer timer)
          Contruct the file set using a regular expression and an external timer.
 
Method Summary
 void addFileSetListener(FileSetListener listener)
          Register file set listener.
 void removeFileSetListener(FileSetListener listener)
          De-register file set listener
 void start(long interval)
          Start watching this file set.
 void stop()
          Stop watcing this file set.
 
Methods inherited from class net.larsan.urd.util.fileset.RegexpFileSet
getCertificates, getResource, getResourcePaths, scan
 
Methods inherited from class net.larsan.urd.util.fileset.FileSet
getErrorHandler, isRecursive, matches, resolvePath, setErrorHandler, setIsRecursive, setRegexpPattern
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WatchedFileSet

public WatchedFileSet(java.io.File root,
                      java.lang.String regexp,
                      java.util.Timer timer)
               throws java.io.IOException,
                      java.util.regex.PatternSyntaxException
Contruct the file set using a regular expression and an external timer. An IOException will be thrown if the root folder does not exists (or is a file) and a PatternSyntaxException if the regular expression is invalid.

Parameters:
root - File set root folder, must exist
timer - Timer to use for re-scans
Throws:
java.io.IOException - If the file set root does not exist, or is a file
java.util.regex.PatternSyntaxException - If the regular expression is not valid

WatchedFileSet

public WatchedFileSet(java.io.File root,
                      java.lang.String regexp)
               throws java.io.IOException,
                      java.util.regex.PatternSyntaxException
Contruct the file set using a regular expression but without an external timer. An IOException will be thrown if the root folder does not exists (or is a file) and a PatternSyntaxException if the regular expression is invalid.

Parameters:
root - File set root folder, must exist
Throws:
java.io.IOException - If the file set root does not exist, or is a file
java.util.regex.PatternSyntaxException - If the regular expression is not valid

WatchedFileSet

public WatchedFileSet(java.io.File root)
               throws java.io.IOException
Contruct the file without a regular expression or without an external timer. An IOException will be thrown if the root folder does not exists (or is a file).

Parameters:
root - File set root folder, must exist
Throws:
java.io.IOException - If the file set root does not exist, or is a file
Method Detail

start

public void start(long interval)
Start watching this file set. The watch interval will be determined by the parameter which must be a long which is bigger than 0 for the watch to start.

Parameters:
interval - Interval in milliseconds between file set checks, must be bigger than 0

stop

public void stop()
Stop watcing this file set.


addFileSetListener

public void addFileSetListener(FileSetListener listener)
Register file set listener.

Specified by:
addFileSetListener in interface WatchableFileSet
Parameters:
listener - File set listener to add

removeFileSetListener

public void removeFileSetListener(FileSetListener listener)
De-register file set listener

Specified by:
removeFileSetListener in interface WatchableFileSet
Parameters:
listener - File set listener to remove