Module aeonics.core

Class Timeout.Tracker<T>

  • Type Parameters:
    T - the type of target element
    Enclosing class:
    Timeout

    public abstract static class Timeout.Tracker<T>
    extends java.lang.Object
    This class englobes a target object to track and defines a delay(). The target object is kept as a weak reference. Once the delay is reached then the onExpire callback will be triggered with the target. If the target is not valid anymore, then the callback is never called and this tracker instance is subject to removal from the timeout watch list. If the delay is < 0 then this tracker is considered cancelled and is subject to removal from the timeout watch list.
    See Also:
    delay()
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Tracker​(T target)
      Creates a target instance with the specified element.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract long delay()
      Returns the delay in milliseconds after which this element expires.
      Callback<T,​Timeout.Tracker<T>> onExpire()
      Gets the callback object that will be called when the element has expired.
      T target()
      Returns the target element or null if it was garbage collected meanwhile
      • Methods inherited from class java.lang.Object

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

      • Tracker

        protected Tracker​(T target)
        Creates a target instance with the specified element. The target element may be null in which case it is the responsibility of the caller to perform the specified logic upon onExpire().
        Parameters:
        target - the target element
    • Method Detail

      • target

        public T target()
        Returns the target element or null if it was garbage collected meanwhile
        Returns:
        the target element
      • delay

        public abstract long delay()
        Returns the delay in milliseconds after which this element expires. This method may be called multiple times, pushing back the timeout value by the specified amount every time.

        If the element has expired, this method must return 0. The onExpire() handler will be called, then this tracker instance is subject to removal from the timeout watch list.

        If the returned delay is negative, it is considered cancelled and not expired, this tracker instance is then subject to removal from the timeout watch list without ever triggering the onExpire() handler.

        If the value is positive, then it is not yet expired and will be checked again later.

        Returns:
        the delay in milliseconds
      • onExpire

        public Callback<T,​Timeout.Tracker<T>> onExpire()
        Gets the callback object that will be called when the element has expired.
        Returns:
        the onExpire callback
        See Also:
        delay()