com.anthonyeden.lib.util
Class VFSFileMonitor

java.lang.Object
  extended bycom.anthonyeden.lib.util.VFSFileMonitor
All Implemented Interfaces:
java.lang.Runnable

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

Class which monitors a file in a thread separate from the main application. If the file changes then the reload() method of the given target will be executed.

Author:
Anthony Eden

Field Summary
static int DEFAULT_DELAY
          The default delay value (5 seconds) for checking for modifications.
 
Constructor Summary
VFSFileMonitor(org.apache.commons.vfs.FileObject file, long delay, Reloadable target)
          Construct a new VFSFileMonitor for the given file and target.
VFSFileMonitor(org.apache.commons.vfs.FileObject file, Reloadable target)
          Construct a new VFSFileMonitor for the given file and target.
 
Method Summary
 long getDelay()
          Get the delay between file checks.
 org.apache.commons.vfs.FileObject getFile()
          Get the file which is being monitored.
 void run()
          The thread's run method.
 void setDelay(long delay)
          Set the delay between checks.
 void startMonitor()
          Start the monitoring thread.
 void stopMonitor()
          Stop the monitoring thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELAY

public static final int DEFAULT_DELAY
The default delay value (5 seconds) for checking for modifications.

See Also:
Constant Field Values
Constructor Detail

VFSFileMonitor

public VFSFileMonitor(org.apache.commons.vfs.FileObject file,
                      Reloadable target)
               throws org.apache.commons.vfs.FileSystemException
Construct a new VFSFileMonitor for the given file and target. The default delay time will be used.

Parameters:
file - The file to monitor
target - The target
Throws:
org.apache.commons.vfs.FileSystemException

VFSFileMonitor

public VFSFileMonitor(org.apache.commons.vfs.FileObject file,
                      long delay,
                      Reloadable target)
               throws org.apache.commons.vfs.FileSystemException
Construct a new VFSFileMonitor for the given file and target. The given delay time will be used.

Parameters:
file - The file to monitor
delay - The delay time
target - The target
Throws:
org.apache.commons.vfs.FileSystemException
Method Detail

startMonitor

public void startMonitor()
Start the monitoring thread. If the thread is already running then this method will not attempt to start a new thread.


stopMonitor

public void stopMonitor()
Stop the monitoring thread. If the monitoring thread is not running then this method will do nothing.


getFile

public org.apache.commons.vfs.FileObject getFile()
Get the file which is being monitored.

Returns:
The monitored file

getDelay

public long getDelay()
Get the delay between file checks.

Returns:
The delay in milliseconds

setDelay

public void setDelay(long delay)
Set the delay between checks. If the thread is already sleeping then this delay will take effect during the next sleep.

Parameters:
delay - The delay in milliseconds

run

public void run()
The thread's run method. This method should not be executed directly nor should a thread be manually created, rather the startMonitor() and stopMonitor() methods should be used to start and stop the monitor.

Specified by:
run in interface java.lang.Runnable


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.