org.apache.ode.utils
Class WatchDog<T,C extends WatchDog.Observer>

java.lang.Object
  extended by org.apache.ode.utils.WatchDog<T,C>
All Implemented Interfaces:
java.lang.Runnable

public class WatchDog<T,C extends WatchDog.Observer>
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 class WatchDog.DefaultObserver<A>
          A default implementation of #ChangeHandler.
static class WatchDog.FileMutable
           
static class WatchDog.FileSetMutable
           
static interface WatchDog.Mutable<T>
          have you said that duck typing would be nice?
static interface WatchDog.Observer<A>
           
 
Field Summary
static long DEFAULT_DELAY
           
protected  WatchDog.Mutable<T> mutable
           
protected  C observer
           
 
Constructor Summary
WatchDog()
           
WatchDog(WatchDog.Mutable<T> mutable)
           
WatchDog(WatchDog.Mutable<T> mutable, C observer)
           
WatchDog(WatchDog.Mutable<T> mutable, long delay)
           
 
Method Summary
 void check()
           
 long getDelay()
           
 WatchDog.Mutable<T> getMutable()
           
 C getObserver()
           
 void run()
           
 void setDelay(long delay)
           
static
<C extends WatchDog.Observer>
WatchDog<java.lang.Long,C>
watchFile(java.io.File file, C handler)
           
static
<C extends WatchDog.Observer>
WatchDog<java.util.Map<java.io.File,java.lang.Long>,C>
watchFiles(java.util.List<java.io.File> files, C handler)
           
 
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 WatchDog.Mutable<T> mutable

observer

protected C extends WatchDog.Observer observer
Constructor Detail

WatchDog

public WatchDog()

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,
                C observer)

WatchDog

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

getMutable

public WatchDog.Mutable<T> getMutable()

getObserver

public C getObserver()

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

watchFile

public static <C extends WatchDog.Observer> WatchDog<java.lang.Long,C> watchFile(java.io.File file,
                                                                                 C handler)

watchFiles

public static <C extends WatchDog.Observer> WatchDog<java.util.Map<java.io.File,java.lang.Long>,C> watchFiles(java.util.List<java.io.File> files,
                                                                                                              C handler)