uk.ac.vamsas.client.simpleclient
Class FileWatcher

java.lang.Object
  extended byuk.ac.vamsas.client.simpleclient.FileWatcher

public class FileWatcher
extends java.lang.Object

Watches a particular file for its creation, deletion, or modification. The watcher is thread safe and different instances watching the state of a particular file carry their own state record for the file.


Constructor Summary
FileWatcher(java.io.File subject)
          Make a watcher for a particular file.
 
Method Summary
 boolean diffState(long[] a, long[] b)
          safely compare an externally recorded state with the current state for significant modifications.
 Lock getChangedState()
          passes lock back to caller if hasChanged returned true.
 long[] getCurrentState()
          safely? getting current state of the watched file
 java.io.File getSubject()
           
 boolean hasChanged()
          Test for change in file state.
 void setState()
          updates internal record of file state when caller has intentionally modified subject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileWatcher

public FileWatcher(java.io.File subject)
Make a watcher for a particular file. If the file doesn't exist, the watcher will watch for its creation (and indicate a change of state) For locked files, the removal of a lock constitutes a change of state if the file was modified.

Parameters:
subject -
Method Detail

setState

public void setState()
updates internal record of file state when caller has intentionally modified subject. (ignores locked-state of subject)


hasChanged

public boolean hasChanged()
Test for change in file state. Only indicates a change after any lock on a file has been released.

Returns:
true if file has been modified.

getChangedState

public Lock getChangedState()
passes lock back to caller if hasChanged returned true.

Returns:

getCurrentState

public long[] getCurrentState()
safely? getting current state of the watched file

Returns:

diffState

public boolean diffState(long[] a,
                         long[] b)
safely compare an externally recorded state with the current state for significant modifications.

Parameters:
a -
b -
Returns:

getSubject

public java.io.File getSubject()
Returns:
the subject