Class Watchdog

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Watchdog
    extends java.lang.Object
    implements java.io.Closeable
    A reusable watchdog that will execute a callback if the watchdog is not disarmed before it expires.
    • Constructor Summary

      Constructors 
      Constructor Description
      Watchdog​(long defaultTimeoutMS, java.lang.Runnable timeoutMethod)
      Creates a watchdog (initially disarmed) that will poll for expiration every defaultTimeoutMS milliseconds, calling timeoutMethod when triggered.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void arm()
      Enables this watchdog so that at defaultWatchdogTimeoutMS milliseconds in the future the timeoutMethod will be called.
      void close()
      Releases the background timer that this watchdog uses.
      void disarm()
      Disables this watchdog.
      void finalize()  
      boolean isEnabled()
      Returns the status of the watchdog.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Watchdog

        public Watchdog​(long defaultTimeoutMS,
                        java.lang.Runnable timeoutMethod)
        Creates a watchdog (initially disarmed) that will poll for expiration every defaultTimeoutMS milliseconds, calling timeoutMethod when triggered.

        Parameters:
        defaultTimeoutMS - number of milliseconds that the watchdog will wait after being armed before calling the timeout method.
        timeoutMethod - Runnable functional callback.
    • Method Detail

      • finalize

        public void finalize()
        Overrides:
        finalize in class java.lang.Object
      • close

        public void close()
        Releases the background timer that this watchdog uses.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • isEnabled

        public boolean isEnabled()
        Returns the status of the watchdog.
        Returns:
        true if the watchdog is armed, false if the watchdog is disarmed
      • disarm

        public void disarm()
        Disables this watchdog.