Class Watchdog

  • All Implemented Interfaces:
    java.lang.Runnable

    public class Watchdog
    extends java.lang.Object
    implements java.lang.Runnable
    Generalization of ExecuteWatchdog.
    See Also:
    ExecuteWatchdog
    • Field Detail

      • observers

        private final java.util.List<TimeoutObserver> observers
        Observers.
      • timeout

        private final java.time.Duration timeout
        Timeout duration.
      • stopped

        private boolean stopped
        Whether this is stopped.
      • threadFactory

        private final java.util.concurrent.ThreadFactory threadFactory
        The thread factory.
    • Constructor Detail

      • Watchdog

        private Watchdog​(Watchdog.Builder builder)
        Constructs a new instance.
        Parameters:
        threadFactory - the thread factory.
        timeout - the timeout duration.
      • Watchdog

        @Deprecated
        public Watchdog​(long timeoutMillis)
        Deprecated.
        Constructs a new instance.
        Parameters:
        timeoutMillis - the timeout duration.
    • Method Detail

      • builder

        public static Watchdog.Builder builder()
        Creates a new builder.
        Returns:
        a new builder.
        Since:
        1.4.0
      • addTimeoutObserver

        public void addTimeoutObserver​(TimeoutObserver to)
        Adds a TimeoutObserver.
        Parameters:
        to - a TimeoutObserver to add.
      • fireTimeoutOccured

        protected final void fireTimeoutOccured()
        Fires a timeout occurred event for each observer.
      • getThreadFactory

        java.util.concurrent.ThreadFactory getThreadFactory()
        Gets the thread factory.
        Returns:
        the thread factory.
      • getTimeout

        public java.time.Duration getTimeout()
        Gets the timeout.
        Returns:
        the timeout.
        Since:
        1.6.0
      • removeTimeoutObserver

        public void removeTimeoutObserver​(TimeoutObserver to)
        Removes a TimeoutObserver.
        Parameters:
        to - a TimeoutObserver to remove.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • start

        public void start()
        Starts a new thread.
      • stop

        public void stop()
        Requests a thread stop.