Class Timeout

java.lang.Object
noaa.coastwatch.net.Timeout

public class Timeout extends Object

A timeout allows the user to perform a certain task after some amount of time has passed. A timeout may be used for example to take action if a network stall occurs.

When a timeout object is created, it is given a task to run and a length of time after which to run the task. However, the timeout is created in an inactive state. To start the timeout countdown, the start() method must be called. Once the timeout is started, the timeout may be cancelled using the cancel() method, or reset via reset(). The reset() method effectively resets the timeout as if cancel() and then start() had been called, but does so in a way that does not create any new objects or start any new threads, and is thus safe to call frequently if needed, rather than calling cancel() followed by start().

Since:
3.1.5
Author:
Peter Hollemans
  • Constructor Summary

    Constructors
    Constructor
    Description
    Timeout(int length, Runnable task)
    Creates a new timeout.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancels the timeout.
    void
    Resets the elapsed time back to zero and continues the timeout.
    void
    Resets the elapsed time and starts the timeout countdown.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Timeout

      public Timeout(int length, Runnable task)
      Creates a new timeout.
      Parameters:
      length - the timeout length in milliseconds.
      task - the runnable task to perform when the timeout occurs.
  • Method Details

    • reset

      public void reset()
      Resets the elapsed time back to zero and continues the timeout.
    • start

      public void start()
      Resets the elapsed time and starts the timeout countdown. If the countdown has already started and the cancel method has not been called, this method has no effect.
    • cancel

      public void cancel()
      Cancels the timeout. The timeout is stopped and the start method must be called again.