org.cip4.jdflib.util.hotfolder
Class HotFolder

java.lang.Object
  extended by org.cip4.jdflib.util.hotfolder.HotFolder
All Implemented Interfaces:
java.lang.Runnable

public class HotFolder
extends java.lang.Object
implements java.lang.Runnable

a very simple hotfolder watcher subdirectories are ignored

Author:
prosirai

Nested Class Summary
protected  class HotFolder.ExtensionListener
          simple container class that retains the last known mod date of a file
protected  class HotFolder.FileTime
          simple container class that retains the last known mod date of a file
 
Field Summary
private  java.lang.String allExtensions
           
static int defaultStabilizeTime
          the default time time in milliseconds to wait for stabilization
private  java.io.File dir
           
protected  java.util.Vector<HotFolder.ExtensionListener> hfl
           
private  boolean interrupt
           
private  java.util.Vector<HotFolder.FileTime> lastFileTime
           
private  long lastModified
           
private  org.apache.commons.logging.Log log
           
private static int nThread
           
private  java.lang.Thread runThread
           
 int stabilizeTime
          the time in milliseconds to wait for stabilization
 
Constructor Summary
HotFolder(java.io.File _dir)
          Deprecated. - use the 3 parameter version
HotFolder(java.io.File _dir, java.lang.String ext, HotFolderListener _hfl)
          constructor for a simple hotfolder watcher that is automagically started in its own thread
 
Method Summary
 void addListener(HotFolderListener _hfl, java.lang.String ext)
           
private  java.lang.String getAllExtensions()
          cache the extension list, null if any wildcard is accepted
static int getDefaultStabilizeTime()
           
 java.io.File getDir()
           
private  java.io.File[] getHotFiles()
           
 int getStabilizeTime()
           
private  void hotFiles(java.io.File fileJ)
           
private  boolean processSingleFile(java.io.File[] files, HotFolder.FileTime lftAt, int j, java.io.File fileJ)
           
 void restart()
          restart the thread
 void run()
          run the listener thread...
static void setDefaultStabilizeTime(int defaultStabilizeTime)
           
 void setStabilizeTime(int stabilizeTime)
           
 void stop()
          stop this thread;
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultStabilizeTime

public static int defaultStabilizeTime
the default time time in milliseconds to wait for stabilization


stabilizeTime

public int stabilizeTime
the time in milliseconds to wait for stabilization


interrupt

private boolean interrupt

nThread

private static int nThread

dir

private final java.io.File dir

allExtensions

private java.lang.String allExtensions

lastModified

private long lastModified

lastFileTime

private final java.util.Vector<HotFolder.FileTime> lastFileTime

hfl

protected final java.util.Vector<HotFolder.ExtensionListener> hfl

runThread

private java.lang.Thread runThread

log

private final org.apache.commons.logging.Log log
Constructor Detail

HotFolder

@Deprecated
public HotFolder(java.io.File _dir)
Deprecated. - use the 3 parameter version

constructor for a simple hotfolder watcher that is automagically started in its own thread

Parameters:
_dir - the Directory to watch

HotFolder

public HotFolder(java.io.File _dir,
                 java.lang.String ext,
                 HotFolderListener _hfl)
constructor for a simple hotfolder watcher that is automagically started in its own thread

Parameters:
_dir - the Directory to watch
ext - the extension filter - case is ignored and lists of extensions may be specified as a comma separated list e.g. ".txt,.xml"
_hfl - the listener callback
Method Detail

getDir

public java.io.File getDir()
Returns:
the hot folder directory

getAllExtensions

private java.lang.String getAllExtensions()
cache the extension list, null if any wildcard is accepted

Returns:
the comma separated list of extensions

addListener

public void addListener(HotFolderListener _hfl,
                        java.lang.String ext)
Parameters:
_hfl -
ext -

restart

public void restart()
restart the thread


stop

public void stop()
stop this thread;


run

public void run()
run the listener thread...

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

getHotFiles

private java.io.File[] getHotFiles()

processSingleFile

private boolean processSingleFile(java.io.File[] files,
                                  HotFolder.FileTime lftAt,
                                  int j,
                                  java.io.File fileJ)

hotFiles

private void hotFiles(java.io.File fileJ)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getDefaultStabilizeTime

public static int getDefaultStabilizeTime()
Returns:
the defaultStabilizeTime

setDefaultStabilizeTime

public static void setDefaultStabilizeTime(int defaultStabilizeTime)
Parameters:
defaultStabilizeTime - the defaultStabilizeTime to set

getStabilizeTime

public int getStabilizeTime()
Returns:
the stabilizeTime

setStabilizeTime

public void setStabilizeTime(int stabilizeTime)
Parameters:
stabilizeTime - the stabilizeTime to set