|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opennms.netmgt.dao.support.FileReloadContainer<T>
T - the class of the inner object that is stored in this containerpublic class FileReloadContainer<T>
Provides a container for returning an object and reloading the object if an underlying file has changed. Ideally suited for automatically reloading configuration files that might be edited outside of the application.
There are two constructors:
FileReloadContainer(T, Resource, FileReloadCallback<T>)
is used for objects having an underlying resource and are reloadableFileReloadContainer(T) is used
for objects that either do not have an underlying file or are otherwise
not reloadable
If the first constructor is used, the Resource will be stored for later
reloading. If Resource.getFile() does not
throw an exception, the returned File object will be stored and
File.lastModified() will be called every time
the getObject() method is called to see if the file
has changed. If the file has changed, the last modified time is updated
and the reload callback, FileReloadCallback.reload, is called. If it returns a non-null object,
the new object is stored and it gets returned to the caller. If a null
object is returned, the stored object isn't modified and the old object
is returned to the caller.
If an unchecked exception is thrown by the reload callback, it will be
caught, logged, and a DataAccessResourceFailureException with
a cause of the unchecked exception. This will propogate up to the
caller of the getObject method. If you do not want unchecked exceptions
on reloads to propogate up to the caller of getObject, they need to be
caught within the reload method. Returning a null in the case of errors
is a good alternative in this case.
| Constructor Summary | |
|---|---|
FileReloadContainer(T object)
Creates a new container with an object which has no underlying file. |
|
FileReloadContainer(T object,
org.springframework.core.io.Resource resource,
FileReloadCallback<T> callback)
Creates a new container with an object and a file underlying that object. |
|
| Method Summary | |
|---|---|
java.io.File |
getFile()
Get the file underlying the object in this container, if any. |
T |
getObject()
Get the object in this container. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileReloadContainer(T object,
org.springframework.core.io.Resource resource,
FileReloadCallback<T> callback)
reload
on the callback will be called when the file is modified.
object - object to be stored in this containerfile - file underlying the objectcallback - reload
will be called when the underlying file object is modified
java.lang.IllegalArgumentException - if object, file, or callback are nullpublic FileReloadContainer(T object)
object - object to be stored in this container
java.lang.IllegalArgumentException - if object is null| Method Detail |
|---|
public T getObject()
throws org.springframework.dao.DataAccessResourceFailureException
org.springframework.dao.DataAccessResourceFailureException - if an unchecked exception
is received while trying to reload the object from the underlying filepublic java.io.File getFile()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||