Package wt.jmx.core
Class FileWatcher
java.lang.Object
wt.jmx.core.FileWatcher
- Direct Known Subclasses:
FileWatcher.Adapter
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
Nested ClassesModifier and TypeClassDescriptionstatic classFileWatcher subclass with no-op overrides of all abstract methods. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionintGet time interval at which file is checked for updates (in seconds); a non-positive time-interval implies no file update checking
Supported API: trueGet input stream for file
Supported API: trueprotected OutputStreamGet output stream for file
Supported API: trueGet URL, file path, or classpath-based resource reference string for file
Supported API: trueGet URL to file
Supported API: trueGet URL to file as String.Returns object used by this instance for locking purposes; default to 'this' unless FileWatcher(Object) constructor is used.booleanWhether only existing files are to be handled or whether reference may be to a file yet to be created.booleanReturns true if and only if in process of saveACopyAs().abstract voidload()Method to load from file; to be overriden by subclasses
Supported API: truevoidreload()Reload data from file
Supported API: truevoidReset this object's record of the file's last modification date.final voidsave()Save data to file
Supported API: trueabstract voidsave(OutputStream out) Method to save data to the file; to be overriden by subclasses
Supported API: truevoidsaveACopyAs(String fileRef) Save data to another file but do not change this object to reference the new file
Supported API: truevoidSave data to another file and change this object to reference the new file
Supported API: truevoidsetExistingFileOnly(boolean existingFileOnly) Set whether only existing files are to be handled or whether reference may be to a file yet to be created.voidsetFileCheckInterval(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: truevoidsetFileRef(String fileRef) Set URL, file path, or classpath-based resource reference string for file
Supported API: truevoidsetFileURL(URL fileURL) Set URL to file
Supported API: truevoidstart()Starts file update checker.voidstop()Stops file update checker.abstract voidunload()Method to unload/clear data loaded from file (as part of a reload); to be overriden by subclasses
Supported API: true
-
Constructor Details
-
FileWatcher
public FileWatcher()Constructs instance of FileWatcher which uses itself as the object to sychronize against.
Supported API: true -
FileWatcher
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 Details
-
load
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
Method to save data to the file; to be overriden by subclasses
Supported API: true- Throws:
IOExceptionURISyntaxException
-
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
Get URL to file as String.
Supported API: true -
getFileRef
Get URL, file path, or classpath-based resource reference string for file
Supported API: true -
setFileRef
Set URL, file path, or classpath-based resource reference string for file
Supported API: true- Throws:
IOException
-
getFileURL
Get URL to file
Supported API: true -
setFileURL
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
Reload data from file
Supported API: true- Throws:
IOException
-
getFileInputStream
Get input stream for file
Supported API: true- Throws:
IOException
-
getFileOutputStream
Get output stream for file
Supported API: true- Throws:
IOExceptionURISyntaxException
-
save
Save data to file
Supported API: true- Throws:
IOExceptionURISyntaxException
-
saveAs
Save data to another file and change this object to reference the new file
Supported API: true- Throws:
IOExceptionURISyntaxException
-
saveACopyAs
Save data to another file but do not change this object to reference the new file
Supported API: true- Throws:
IOExceptionURISyntaxException
-
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
-