Class TrcWatchdogMgr

java.lang.Object
trclib.robotcore.TrcWatchdogMgr

public class TrcWatchdogMgr extends Object
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.
  • Field Details

    • moduleName

      public static final String moduleName
    • staticTracer

      public static final TrcDbgTrace staticTracer
  • Method Details

    • getInstance

      public static TrcWatchdogMgr getInstance(double taskInterval)
      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

      public static TrcWatchdogMgr 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

      public static TrcWatchdogMgr.Watchdog registerWatchdog(String name, 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.
      paused - specifies true to create the watchdog in paused mode, false otherwise.
      Returns:
      newly created watchdog.
    • registerWatchdog

      public static TrcWatchdogMgr.Watchdog registerWatchdog(String name)
      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

      public static boolean unregisterWatchdog(TrcWatchdogMgr.Watchdog watchdog)
      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

      public static TrcWatchdogMgr.Watchdog getWatchdog()
      This method returns the watchdog associated with the current thread.
      Returns:
      watchdog associated with the current thread.