com.isti.util
Class FileMonPollingThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.isti.util.IstiThread
          extended by com.isti.util.IstiNotifyThread
              extended by com.isti.util.FileMonPollingThread
All Implemented Interfaces:
java.lang.Runnable

public class FileMonPollingThread
extends IstiNotifyThread

Class FileMonPollingThread defines a thread for monitoring a file via a 'FileDataMonitor' object.


Nested Class Summary
static interface FileMonPollingThread.FileDataCallBack
          Interface FileDataCallBack defines a call-back method to be invoked when new file data is available.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static byte[] ERROR_ARRAY
          Empty array used to indicate error.
protected  int fileAccessTimeOutMs
           
protected  FileMonPollingThread.FileDataCallBack fileDataCallBackObj
           
protected  FileDataMonitor fileDataMonitorObj
           
protected  boolean forceFileReadFlag
           
protected  boolean indRecoveryFlag
           
protected  long maxReadBytesLimit
           
protected  int pollingIntervalMs
           
 
Fields inherited from class com.isti.util.IstiThread
DEFAULT_TERMINATE_WAIT_TIME, terminateFlag
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FileMonPollingThread(java.lang.String fNameStr, int pollingIntervalMs, int fileAccessTimeOutMs, long maxReadBytesLimit, boolean indRecoveryFlag, FileMonPollingThread.FileDataCallBack fileDataCallBackObj)
          Creates a thread for monitoring a file via a 'FileDataMonitor' object.
FileMonPollingThread(java.lang.String fNameStr, int pollingIntervalMs, int fileAccessTimeOutMs, long maxReadBytesLimit, FileMonPollingThread.FileDataCallBack fileDataCallBackObj)
          Creates a thread for monitoring a file via a 'FileDataMonitor' object.
 
Method Summary
 byte[] checkReadFileData()
          Checks if the file has been modified and returns its contents if so.
 byte[] checkReadFileData(boolean forceFileReadFlag)
          Checks if the file has been modified and returns its contents if so.
 void fireForceFileRead()
          Fires a forced read of the file by the monitoring thread, as if the file's last-modified time had changed.
 boolean getErrorMessageFlag()
          Returns the status of the error message.
 java.lang.String getErrorMessageString()
          Returns the current error message (if any).
 FileDataMonitor getFileDataMonitorObj()
          Returns the 'FileDataMonitor' object used by this object.
 void run()
          Executing method for file-monitoring thread.
 
Methods inherited from class com.isti.util.IstiNotifyThread
sleep, terminate
 
Methods inherited from class com.isti.util.IstiThread
clearThreadWaitNotifyFlag, isTerminated, nextThreadNum, notifyThread, start, terminate, waitForNotify, waitForNotify, waitForTerminate, waitForTerminate, wasStarted
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERROR_ARRAY

public static final byte[] ERROR_ARRAY
Empty array used to indicate error.


fileDataMonitorObj

protected final FileDataMonitor fileDataMonitorObj

pollingIntervalMs

protected final int pollingIntervalMs

fileAccessTimeOutMs

protected final int fileAccessTimeOutMs

maxReadBytesLimit

protected final long maxReadBytesLimit

indRecoveryFlag

protected final boolean indRecoveryFlag

fileDataCallBackObj

protected final FileMonPollingThread.FileDataCallBack fileDataCallBackObj

forceFileReadFlag

protected boolean forceFileReadFlag
Constructor Detail

FileMonPollingThread

public FileMonPollingThread(java.lang.String fNameStr,
                            int pollingIntervalMs,
                            int fileAccessTimeOutMs,
                            long maxReadBytesLimit,
                            boolean indRecoveryFlag,
                            FileMonPollingThread.FileDataCallBack fileDataCallBackObj)
Creates a thread for monitoring a file via a 'FileDataMonitor' object. After being created, this thread should be started via its 'start()' method.

Parameters:
fNameStr - name of input file to be read and monitored.
pollingIntervalMs - number of milliseconds to wait between polls of the input file.
fileAccessTimeOutMs - timeout value for file access, or 0 for infinite.
maxReadBytesLimit - maximum number of bytes to read from file, or 0 for no limit.
indRecoveryFlag - if true then the call-back method will be invoked with (true,null) if the previous file-access attempt failed and the current attempt succeeded and no change in the file last-modified time was detected.
fileDataCallBackObj - call-back object to be invoked when changes in the file data are detected.

FileMonPollingThread

public FileMonPollingThread(java.lang.String fNameStr,
                            int pollingIntervalMs,
                            int fileAccessTimeOutMs,
                            long maxReadBytesLimit,
                            FileMonPollingThread.FileDataCallBack fileDataCallBackObj)
Creates a thread for monitoring a file via a 'FileDataMonitor' object. After being created, this thread should be started via its 'start()' method.

Parameters:
fNameStr - name of input file to be read and monitored.
pollingIntervalMs - number of milliseconds to wait between polls of the input file.
fileAccessTimeOutMs - timeout value for file access, or 0 for infinite.
maxReadBytesLimit - maximum number of bytes to read from file, or 0 for no limit.
fileDataCallBackObj - call-back object to be invoked when changes in the file data are detected.
Method Detail

run

public void run()
Executing method for file-monitoring thread.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

fireForceFileRead

public void fireForceFileRead()
Fires a forced read of the file by the monitoring thread, as if the file's last-modified time had changed.


checkReadFileData

public byte[] checkReadFileData(boolean forceFileReadFlag)
Checks if the file has been modified and returns its contents if so. The first time this method is called the file data will be returned. This method may be used to do the initial read of file data before using the monitoring thread to track future changes to the data.

Parameters:
forceFileReadFlag - true to force reading of file data; false to only read file data if file-modified time changed.
Returns:
A byte array containing the file data, 'null' if the file has not been modified, or 'ERROR_ARRAY' if an error occurred (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

checkReadFileData

public byte[] checkReadFileData()
Checks if the file has been modified and returns its contents if so. The first time this method is called the file data will be returned. This method may be used to do the initial read of file data before using the monitoring thread to track future changes to the data.

Returns:
A byte array containing the file data, 'null' if the file has not been modified, or 'ERROR_ARRAY' if an error occurred (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

getFileDataMonitorObj

public FileDataMonitor getFileDataMonitorObj()
Returns the 'FileDataMonitor' object used by this object.

Returns:
The 'FileDataMonitor' object used by this object.

getErrorMessageFlag

public boolean getErrorMessageFlag()
Returns the status of the error message.

Returns:
true if an error message is set; false if not.

getErrorMessageString

public java.lang.String getErrorMessageString()
Returns the current error message (if any).

Returns:
The current error message, or null if no errors have occurred.