Package trclib.robotcore
Class TrcWatchdogMgr
java.lang.Object
trclib.robotcore.TrcWatchdogMgr
This class is a singleton. It manages a list of watchdogs. Watchdogs are typically used for detecting thread
deadlocks. A thread can register a watchdog with the Watchdog manager and periodically sends a heartbeat to it.
If a heart beat is not sent within the heart beat threshold time, a stack trace for the thread will be dump to the
trace log. This allows us to catch thread deadlocks quite easily. Since watchdog is designed per thread, only one
watchdog needs to be registered for each thread.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class encapsulates the state of the watchdog. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TrcWatchdogMgr
This method should only be called once.static TrcWatchdogMgr
getInstance
(double taskInterval) This method should only be called once.static TrcWatchdogMgr.Watchdog
This method returns the watchdog associated with the current thread.static TrcWatchdogMgr.Watchdog
registerWatchdog
(String name) This method registers a new watchdog for the current thread if one is not already registered.static TrcWatchdogMgr.Watchdog
registerWatchdog
(String name, boolean paused) This method registers a new watchdog for the current thread if one is not already registered.static TrcWatchdogMgr.Watchdog
registerWatchdog
(String name, double heartBeatThreshold, boolean paused) This method registers a new watchdog for the current thread if one is not already registered.static boolean
unregisterWatchdog
(TrcWatchdogMgr.Watchdog watchdog) This method removes the watchdog from the watchdog list and map.
-
Field Details
-
moduleName
-
staticTracer
-
-
Method Details
-
getInstance
This method should only be called once. It creates a singleton of the Watchdog Manager. If it is called again, it will just return the Watchdog Manager instance created previously.- Parameters:
taskInterval
- specifies the watchdog task interval.- Returns:
- Watchdog Manager instance.
-
getInstance
This method should only be called once. It creates a singleton of the Watchdog Manager. If it is called again, it will just return the Watchdog Manager instance created previously.- Returns:
- Watchdog Manager instance.
-
registerWatchdog
public static TrcWatchdogMgr.Watchdog registerWatchdog(String name, double heartBeatThreshold, boolean paused) This method registers a new watchdog for the current thread if one is not already registered. Important: this method must be called in the thread the watchdog is monitoring.- Parameters:
name
- specifies the name of the watchdog.heartBeatThreshold
- specifies the maximum heart beat interval in seconds.paused
- specifies true to create the watchdog in paused mode, false otherwise.- Returns:
- newly created watchdog.
-
registerWatchdog
This method registers a new watchdog for the current thread if one is not already registered. Important: this method must be called in the thread the watchdog is monitoring.- Parameters:
name
- specifies the name of the watchdog.paused
- specifies true to create the watchdog in paused mode, false otherwise.- Returns:
- newly created watchdog.
-
registerWatchdog
This method registers a new watchdog for the current thread if one is not already registered. Important: this method must be called in the thread the watchdog is monitoring.- Parameters:
name
- specifies the name of the watchdog.- Returns:
- newly created watchdog.
-
unregisterWatchdog
This method removes the watchdog from the watchdog list and map. It can be called from any thread as long as it provides the watchdog to be unregistered.- Parameters:
watchdog
- specifies the watchdog to be removed.- Returns:
- true if watchdog is removed successfully, false if watchdog does not exist.
-
getWatchdog
This method returns the watchdog associated with the current thread.- Returns:
- watchdog associated with the current thread.
-