public final class WatchDog extends java.lang.Object
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 and Description |
|---|
WatchDog(Engine engine,
java.lang.Thread thread)
Creates a new WatchDog for a Thread.
|
WatchDog(Engine engine,
Watchable watch)
Creates a new WatchDog for a Watchable.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disable()
Is used to disable a WatchDog.
|
void |
enable()
Can be used to enable the WatchDog.
|
void |
enterState(java.lang.String state)
Enters a watched state with no expectation of the expected completion time.
|
void |
enterState(java.lang.String state,
int expectedCompletionTime)
Enters a watched state which has an expected completion time.
|
void |
exitState()
Exits a state entered with enterState().
|
void |
exitState(java.lang.String state)
Exits a particular state entered with enterState().
|
static WatchDog |
getCurrentWatchDog(Engine 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.
|
java.lang.String |
toString()
Strictly for debugging/informative purposes.
|
public WatchDog(Engine engine, Watchable watch)
engine - The Engine.watch - A Watchable object.public static WatchDog getCurrentWatchDog(Engine engine)
engine - The Engine to which the Watchdog should be bonded to.public void enable()
public void disable()
public void enterState(java.lang.String state)
state - A free-form string description of your state.public void enterState(java.lang.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(java.lang.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 java.lang.String toString()
toString in class java.lang.ObjectCopyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.