com.isti.util
Class FileMonPollingThread

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.isti.util.IstiThread
          extended bycom.isti.util.IstiNotifyThread
              extended bycom.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.
 
Field Summary
static byte[] ERROR_ARRAY
          Empty array used to indicate error.
protected  int fileAccessTimeOutMs
           
protected  FileMonPollingThread.FileDataCallBack fileDataCallBackObj
           
protected  FileDataMonitor fileDataMonitorObj
           
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, 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.
 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, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, 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

fileDataCallBackObj

protected final FileMonPollingThread.FileDataCallBack fileDataCallBackObj
Constructor Detail

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.


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.