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
FieldsModifier and TypeFieldDescriptionprivate static final double
private static final double
private static TrcWatchdogMgr
static final String
static final TrcDbgTrace
private static final ArrayList<TrcWatchdogMgr.Watchdog>
private static final HashMap<Thread,
TrcWatchdogMgr.Watchdog> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
TrcWatchdogMgr
(double taskInterval) Constructor: Creates an instance of the object. -
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.private void
watchdogTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method runs periodically to check for watchdog timeouts.
-
Field Details
-
moduleName
-
staticTracer
-
DEF_TASK_INTERVAL
private static final double DEF_TASK_INTERVAL- See Also:
-
DEF_HEARTBEAT_THRESHOLD
private static final double DEF_HEARTBEAT_THRESHOLD- See Also:
-
instance
-
watchdogList
-
watchdogMap
-
-
Constructor Details
-
TrcWatchdogMgr
private TrcWatchdogMgr(double taskInterval) Constructor: Creates an instance of the object.- Parameters:
taskInterval
- specifies the watchdog task interval.
-
-
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.
-
watchdogTask
private void watchdogTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method runs periodically to check for watchdog timeouts.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the current robot run mode.slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-