org.apache.ode.utils
Class WatchDog<T>

java.lang.Object
  extended by 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:

  1. Pass an instance of WatchDog to a new thread (WatchDog is a Runnable). So that check () will be called automatically every delay milliseconds.
  2. 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?
 
Field Summary
static long DEFAULT_DELAY
           
protected  WatchDog.Mutable<T> mutable
           
 
Constructor Summary
WatchDog(WatchDog.Mutable<T> mutable)
           
WatchDog(WatchDog.Mutable<T> mutable, long delay)
           
 
Method Summary
 void check()
           
protected  void doOnDelete()
          Called only if the resource previously existed and now does not exist.
protected  void doOnUpdate()
          Called only if the resource previously existed but the WatchDog.Mutable.lastModified() timestamp has changed (greater than the previous value).
 long getDelay()
           
protected  void init()
          Called by check() if the object is not initialized and the WatchDog.Mutable.exists() resource does not exist}.
protected  boolean isInitialized()
           
 void run()
           
 void setDelay(long delay)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELAY

public static final long DEFAULT_DELAY
See Also:
Constant Field Values

mutable

protected final WatchDog.Mutable<T> mutable
Constructor Detail

WatchDog

public WatchDog(WatchDog.Mutable<T> mutable,
                long delay)
Parameters:
mutable - the object to watch closely
delay - between two checks

WatchDog

public WatchDog(WatchDog.Mutable<T> mutable)
See Also:
WatchDog(org.apache.ode.utils.WatchDog.Mutable, long)
Method Detail

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()