org.apache.ode.utils
Class WatchDog<T>
java.lang.Object
org.apache.ode.utils.WatchDog<T>
- All Implemented Interfaces:
- java.lang.Runnable
- Direct Known Subclasses:
- FileWatchDog
public class WatchDog<T>
- extends java.lang.Object
- implements java.lang.Runnable
This class is based on org.apache.log4j.helpers.FileWatchdog.
Modifications have been made to support additional abstract ressource and more events (creation, deletion and updates), and to allow "manual"
invocations of check() (i.e wihtout having to use a thread) while preserving time checking.
Now two use cases coexist:
- Pass an instance of
WatchDog to a new thread (WatchDog is a Runnable).
So that check () will be called automatically every delay milliseconds.
- Invoke
check () only when you feel like it. If the expiration date previously set is lower than NOW then event
callback methods will be invoked accordingly.
|
Nested Class Summary |
static interface |
WatchDog.Mutable<T>
have you said that duck typing would be nice? |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_DELAY
public static final long DEFAULT_DELAY
- See Also:
- Constant Field Values
mutable
protected final WatchDog.Mutable<T> mutable
WatchDog
public WatchDog(WatchDog.Mutable<T> mutable,
long delay)
- Parameters:
mutable - the object to watch closelydelay - between two checks
WatchDog
public WatchDog(WatchDog.Mutable<T> mutable)
- See Also:
WatchDog(org.apache.ode.utils.WatchDog.Mutable, long)
isInitialized
protected boolean isInitialized()
init
protected void init()
- Called by
check() if the object is not initialized and the WatchDog.Mutable.exists() resource does not exist}.
This method might called to reset the object.
- Throws:
java.lang.Exception
doOnDelete
protected void doOnDelete()
- Called only if the resource previously existed and now does not exist.
The default implementation invokes init() .
- Throws:
java.lang.Exception
doOnUpdate
protected void doOnUpdate()
- Called only if the resource previously existed but the
WatchDog.Mutable.lastModified() timestamp has changed (greater than the previous value).
The default implementation invokes init() .
- Throws:
java.lang.Exception
getDelay
public long getDelay()
setDelay
public void setDelay(long delay)
run
public void run()
- Specified by:
run in interface java.lang.Runnable
check
public final void check()