Package trclib.robotcore
Class TrcWatchdogMgr.Watchdog
java.lang.Object
trclib.robotcore.TrcWatchdogMgr.Watchdog
- Enclosing class:
- TrcWatchdogMgr
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
This method checks if the watchdog has expired.double
This method returns the heart beat threshold time for the watchdog.void
This method is called to pause watchdog monitoring.void
This method is called to resume watchdog monitoring.void
This method is called by the thread that registered the watchdog to send a heart beat.toString()
This method returns the string containing the info of the watchdog.boolean
This method unregisters this watchdog from Watchdog Manager.
-
Field Details
-
name
-
heartBeatThreshold
private final double heartBeatThreshold -
thread
-
heartBeatExpiredTime
private volatile double heartBeatExpiredTime -
expired
private volatile boolean expired -
paused
private volatile boolean paused
-
-
Constructor Details
-
Watchdog
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
This method returns the string containing the info of the watchdog. -
getHeartBeatThreshold
public double getHeartBeatThreshold()This method returns the heart beat threshold time for the watchdog.- Returns:
- watchdog heart beat threshold time in seconds.
-