Class TrcWatchdogMgr.Watchdog

java.lang.Object
trclib.robotcore.TrcWatchdogMgr.Watchdog
Enclosing class:
TrcWatchdogMgr

public static class TrcWatchdogMgr.Watchdog extends Object
This class encapsulates the state of the watchdog. A watchdog has an identifiable name, an associated thread, a maximum time interval between which the heart beat must be received and the next heart beat expiraton time.
  • Field Details

    • name

      private final String name
    • heartBeatThreshold

      private final double heartBeatThreshold
    • thread

      private final Thread thread
    • heartBeatExpiredTime

      private volatile double heartBeatExpiredTime
    • expired

      private volatile boolean expired
    • paused

      private volatile boolean paused
  • Constructor Details

    • Watchdog

      private Watchdog(String name, Thread thread, double heartBeatThreshold, boolean paused)
      Constructor: Creates an instance of the object.
      Parameters:
      name - specifies the name of the watchdog.
      thread - specifies the thread the watchdog is monitoring.
      heartBeatThreshold - specifies the maximum heart beat interval in seconds.
      paused - specifies true to create the watchdog in paused mode, false otherwise.
  • Method Details

    • pauseWatch

      public void pauseWatch()
      This method is called to pause watchdog monitoring. It is useful for a thread to call this before going into sleep or a wait knowing it won't be able to send periodic heartbeat to prevent a watchdog timeout.
    • resumeWatch

      public void resumeWatch()
      This method is called to resume watchdog monitoring. It is useful for a thread to call this right after waking up from a sleep or a wait so watchdog monitoring will be resumed.
    • sendHeartBeat

      public void sendHeartBeat()
      This method is called by the thread that registered the watchdog to send a heart beat. This will update the next heart beat expiration time.
    • checkForExpiration

      private boolean checkForExpiration()
      This method checks if the watchdog has expired.
      Returns:
      true if no heartbeat has been received for the specified threshold period, false otherwise.
    • unregister

      public boolean unregister()
      This method unregisters this watchdog from Watchdog Manager. Important: this method must be called in the thread the watchdog is monitoring. In other words, the caller's thread must be the owner of the watchdog.
      Returns:
      true if watchdog is unregistered successfully, false if watchdog does not exist.
    • toString

      public String toString()
      This method returns the string containing the info of the watchdog.
      Overrides:
      toString in class Object
      Returns:
      string form of the watchdog info.
    • getHeartBeatThreshold

      public double getHeartBeatThreshold()
      This method returns the heart beat threshold time for the watchdog.
      Returns:
      watchdog heart beat threshold time in seconds.