com.anthonyeden.lib.util
Class FileMonitor

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

public class FileMonitor
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
FileMonitor(java.io.File file, long delay, Reloadable target)
          Construct a new FileMonitor for the given file and target.
FileMonitor(java.io.File file, Reloadable target)
          Construct a new FileMonitor for the given file and target.
 
Method Summary
 long getDelay()
          Get the delay between file checks.
 java.io.File 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

FileMonitor

public FileMonitor(java.io.File file,
                   Reloadable target)
Construct a new FileMonitor for the given file and target. The default delay time will be used.

Parameters:
file - The file to monitor
target - The target

FileMonitor

public FileMonitor(java.io.File file,
                   long delay,
                   Reloadable target)
Construct a new FileMonitor 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
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 java.io.File 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.