wt.jmx.core
Class FileWatcher

java.lang.Object
  extended by wt.jmx.core.FileWatcher
Direct Known Subclasses:
FileWatcher.Adapter

public abstract class FileWatcher
extends Object

Provides ability to watch and load a file upon changes via a fairly general URL abstraction.

Note this class is not itself properly configured for direct persistence via Encoder; rather it is suggested that controlling properties of interest be exposed in an aggregating MBean.

Supported API: true

Extendable: true


Nested Class Summary
static class FileWatcher.Adapter
          FileWatcher subclass with no-op overrides of all abstract methods.
 
Constructor Summary
FileWatcher()
          Constructs instance of FileWatcher which uses itself as the object to sychronize against.
FileWatcher(Object lockObject)
          Constructs instance of FileWatcher which uses the specified object as the object to sychronize against.
 
Method Summary
 int getFileCheckInterval()
          Get time interval at which file is checked for updates (in seconds); a non-positive time-interval implies no file update checking

Supported API: true
 BufferedInputStream getFileInputStream()
          Get input stream for file

Supported API: true
protected  OutputStream getFileOutputStream()
          Get output stream for file

Supported API: true
 String getFileRef()
          Get URL, file path, or classpath-based resource reference string for file

Supported API: true
 URL getFileURL()
          Get URL to file

Supported API: true
 String getFileURLString()
          Get URL to file as String.
 Object getLockObject()
          Returns object used by this instance for locking purposes; default to 'this' unless FileWatcher(Object) constructor is used.
 boolean isExistingFileOnly()
          Whether only existing files are to be handled or whether reference may be to a file yet to be created.
 boolean isSavingCopy()
          Returns true if and only if in process of saveACopyAs().
abstract  void load()
          Method to load from file; to be overriden by subclasses

Supported API: true
 void reload()
          Reload data from file

Supported API: true
 void resetFileLastModified()
          Reset this object's record of the file's last modification date.
 void save()
          Save data to file

Supported API: true
abstract  void save(OutputStream out)
          Method to save data to the file; to be overriden by subclasses

Supported API: true
 void saveACopyAs(String fileRef)
          Save data to another file but do not change this object to reference the new file

Supported API: true
 void saveAs(String fileRef)
          Save data to another file and change this object to reference the new file

Supported API: true
 void setExistingFileOnly(boolean existingFileOnly)
          Set whether only existing files are to be handled or whether reference may be to a file yet to be created.
 void setFileCheckInterval(int fileCheckIntervalInSeconds)
          Set time interval at which file is checked for updates (in seconds); a non-positive time-interval implies no file update checking

Supported API: true
 void setFileRef(String fileRef)
          Set URL, file path, or classpath-based resource reference string for file

Supported API: true
 void setFileURL(URL fileURL)
          Set URL to file

Supported API: true
 void start()
          Starts file update checker.
 void stop()
          Stops file update checker.
abstract  void unload()
          Method to unload/clear data loaded from file (as part of a reload); to be overriden by subclasses

Supported API: true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileWatcher

public FileWatcher()
Constructs instance of FileWatcher which uses itself as the object to sychronize against.

Supported API: true


FileWatcher

public FileWatcher(Object lockObject)
Constructs instance of FileWatcher which uses the specified object as the object to sychronize against.

Supported API: true

Parameters:
lockObject - Object to synchronize against, if null, 'this' is used instead; see getLockObject()
Method Detail

load

public abstract void load()
                   throws IOException
Method to load from file; to be overriden by subclasses

Supported API: true

Throws:
IOException

unload

public abstract void unload()
Method to unload/clear data loaded from file (as part of a reload); to be overriden by subclasses

Supported API: true


save

public abstract void save(OutputStream out)
                   throws IOException,
                          URISyntaxException
Method to save data to the file; to be overriden by subclasses

Supported API: true

Throws:
IOException
URISyntaxException

getLockObject

public Object getLockObject()
Returns object used by this instance for locking purposes; default to 'this' unless FileWatcher(Object) constructor is used.

Supported API: true


resetFileLastModified

public void resetFileLastModified()
Reset this object's record of the file's last modification date. This is set to the actual last modification date milliseconds if this can be obtained or '0' when it cannot be.

Supported API: true


isExistingFileOnly

public boolean isExistingFileOnly()
Whether only existing files are to be handled or whether reference may be to a file yet to be created.

Supported API: true


setExistingFileOnly

public void setExistingFileOnly(boolean existingFileOnly)
Set whether only existing files are to be handled or whether reference may be to a file yet to be created.

Supported API: true


getFileURLString

public String getFileURLString()
Get URL to file as String.

Supported API: true


getFileRef

public String getFileRef()
Get URL, file path, or classpath-based resource reference string for file

Supported API: true


setFileRef

public void setFileRef(String fileRef)
                throws IOException
Set URL, file path, or classpath-based resource reference string for file

Supported API: true

Throws:
IOException

getFileURL

public URL getFileURL()
Get URL to file

Supported API: true


setFileURL

public void setFileURL(URL fileURL)
                throws IOException
Set URL to file

Supported API: true

Throws:
IOException

getFileCheckInterval

public int getFileCheckInterval()
Get time interval at which file is checked for updates (in seconds); a non-positive time-interval implies no file update checking

Supported API: true


setFileCheckInterval

public void setFileCheckInterval(int fileCheckIntervalInSeconds)
Set time interval at which file is checked for updates (in seconds); a non-positive time-interval implies no file update checking

Supported API: true


reload

public void reload()
            throws IOException
Reload data from file

Supported API: true

Throws:
IOException

getFileInputStream

public BufferedInputStream getFileInputStream()
                                       throws IOException
Get input stream for file

Supported API: true

Throws:
IOException

getFileOutputStream

protected OutputStream getFileOutputStream()
                                    throws IOException,
                                           URISyntaxException
Get output stream for file

Supported API: true

Throws:
IOException
URISyntaxException

save

public final void save()
                throws IOException,
                       URISyntaxException
Save data to file

Supported API: true

Throws:
IOException
URISyntaxException

saveAs

public void saveAs(String fileRef)
            throws IOException,
                   URISyntaxException
Save data to another file and change this object to reference the new file

Supported API: true

Throws:
IOException
URISyntaxException

saveACopyAs

public void saveACopyAs(String fileRef)
                 throws IOException,
                        URISyntaxException
Save data to another file but do not change this object to reference the new file

Supported API: true

Throws:
IOException
URISyntaxException

isSavingCopy

public boolean isSavingCopy()
Returns true if and only if in process of saveACopyAs().

Supported API: true


start

public void start()
Starts file update checker. When used within a SelfAwareMBean, this should generally be called from within the MBean's start() method.

Supported API: true


stop

public void stop()
Stops file update checker. When used within a SelfAwareMBean, this should generally be called from within the MBean's stop() method.

Supported API: true