|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wiki.WatchDog
public final class WatchDog
WatchDog is a general system watchdog. You can attach any Watchable or a Thread object to it, and it will notify you if a timeout has been exceeded.
The notification of the timeouts is done from a separate WatchDog thread, of which there is one per watched thread. This Thread is named 'WatchDog for XXX', where XXX is your Thread name.
The suggested method of obtaining a WatchDog is via the static factory method, since it will return you the correct watchdog for the current thread. However, we do not prevent you from creating your own watchdogs either.
If you create a WatchDog for a Thread, the WatchDog will figure out when the Thread is dead, and will stop itself accordingly. However, this object is not automatically released, so you might want to check it out after a while.
Constructor Summary | |
---|---|
WatchDog(WikiEngine engine,
Thread thread)
Creates a new WatchDog for a Thread. |
|
WatchDog(WikiEngine engine,
Watchable watch)
Creates a new WatchDog for a Watchable. |
Method Summary | |
---|---|
void |
disable()
Is used to disable a WatchDog. |
void |
enable()
Can be used to enable the WatchDog. |
void |
enterState(String state)
Enters a watched state with no expectation of the expected completion time. |
void |
enterState(String state,
int expectedCompletionTime)
Enters a watched state which has an expected completion time. |
void |
exitState()
Exits a state entered with enterState(). |
void |
exitState(String state)
Exits a particular state entered with enterState(). |
static WatchDog |
getCurrentWatchDog(WikiEngine engine)
Returns the current watchdog for the current thread. |
boolean |
isStateStackNotEmpty()
helper to see if the associated stateStack is not empty. |
boolean |
isWatchableAlive()
helper to see if the associated watchable is alive. |
String |
toString()
Strictly for debugging/informative purposes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public WatchDog(WikiEngine engine, Watchable watch)
engine
- The WikiEngine.watch
- A Watchable object.public WatchDog(WikiEngine engine, Thread thread)
engine
- The WikiEnginethread
- A Thread for watching.Method Detail |
---|
public static WatchDog getCurrentWatchDog(WikiEngine engine)
engine
- The WikiEngine to which the Watchdog should
be bonded to.
public void enable()
public void disable()
public void enterState(String state)
state
- A free-form string description of your state.public void enterState(String state, int expectedCompletionTime)
WatchDog w = m_engine.getCurrentWatchDog();
w.enterState("Processing Foobar", 60);
foobar();
w.exitState();
If the call to foobar() takes more than 60 seconds, you will receive an ERROR in the log stream.
state
- A free-form string description of the stateexpectedCompletionTime
- The timeout in seconds.public void exitState()
public void exitState(String state)
state
- The state you wish to exit.public boolean isStateStackNotEmpty()
true
if not empty, false
otherwise.public boolean isWatchableAlive()
true
if it's alive, false
otherwise.public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |