Class TimedExpirySupport


  • public class TimedExpirySupport
    extends java.lang.Object
    Handles expiration after some interval of time has passed. Expiration time is computed as a random value between a specified minimum and a specified maximum delay interval.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimedExpirySupport()
      Constructs an instance with minimum expiry interval of 1 second and a max of 2 seconds.
      TimedExpirySupport​(long minExpiryTime, long maxExpiryTime)
      Constructs an instance with specified minimum and maximum expiry intervals.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getExpiryTime()
      Indicates the current expiration time, which is a random value between the specified minimum and maximum.
      long getMaxExpiryTime()
      Indicates this timer's maximum expiry interval.
      long getMinExpiryTime()
      Indicates this timer's minimum expiry interval.
      boolean isExpired​(long now)
      Indicates whether this timer has expired.
      boolean isExpired​(DrawContext dc)
      Indicates whether this timer has expired.
      void restart​(DrawContext dc)
      Marks this timer as not expired and restarts the timer.
      void setExpired​(boolean expired)
      Set the expiration state of this timer.
      void setExpiryTime​(long expiryTime)
      Sets the current expiration time to a specified value.
      void setExpiryTime​(long minExpiryTime, long maxExpiryTime)
      Specifies the minimum and maximum expiration intervals.
      • Methods inherited from class java.lang.Object

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

      • expired

        protected boolean expired
      • expiryTime

        protected long expiryTime
      • minExpiryTime

        protected long minExpiryTime
      • maxExpiryTime

        protected long maxExpiryTime
      • rand

        protected static java.util.Random rand
    • Constructor Detail

      • TimedExpirySupport

        public TimedExpirySupport()
        Constructs an instance with minimum expiry interval of 1 second and a max of 2 seconds.
      • TimedExpirySupport

        public TimedExpirySupport​(long minExpiryTime,
                                  long maxExpiryTime)
        Constructs an instance with specified minimum and maximum expiry intervals. An interval is set to 0 if its specified value is less than 0.
        Parameters:
        minExpiryTime - the minimum interval allowed to pass before expiration, in milliseconds.
        maxExpiryTime - the maximum interval allowed to pass before expiration, in milliseconds.
    • Method Detail

      • setExpired

        public void setExpired​(boolean expired)
        Set the expiration state of this timer.
        Parameters:
        expired - true to indicate expired, false to indicate not expired.
      • getExpiryTime

        public long getExpiryTime()
        Indicates the current expiration time, which is a random value between the specified minimum and maximum.
        Returns:
        the current expiration time, in milliseconds.
      • setExpiryTime

        public void setExpiryTime​(long expiryTime)
        Sets the current expiration time to a specified value. This method ignores the configured minimum and maximum expiry times.
        Parameters:
        expiryTime - the new expiration time, in milliseconds.
      • setExpiryTime

        public void setExpiryTime​(long minExpiryTime,
                                  long maxExpiryTime)
        Specifies the minimum and maximum expiration intervals. An interval is set to 0 if its specified value is less than 0.
        Parameters:
        minExpiryTime - the minimum interval allowed to pass before expiration, in milliseconds.
        maxExpiryTime - the maximum interval allowed to pass before expiration, in milliseconds.
      • getMinExpiryTime

        public long getMinExpiryTime()
        Indicates this timer's minimum expiry interval.
        Returns:
        this timer's minimum expiry interval, in milliseconds.
      • getMaxExpiryTime

        public long getMaxExpiryTime()
        Indicates this timer's maximum expiry interval.
        Returns:
        this timer's maximum expiry interval, in milliseconds.
      • isExpired

        public boolean isExpired​(DrawContext dc)
        Indicates whether this timer has expired.
        Parameters:
        dc - the current draw context.
        Returns:
        true if this timer has expired relative to the frame time, otherwise false.
        Throws:
        java.lang.IllegalArgumentException - if the draw context is null.
      • isExpired

        public boolean isExpired​(long now)
        Indicates whether this timer has expired.
        Parameters:
        now - the time to relate this timer's expiration time to. The timer is considered expired if this timer's expiry time is less than this value.
        Returns:
        true if this timer has expired relative to system time, otherwise false.
      • restart

        public void restart​(DrawContext dc)
        Marks this timer as not expired and restarts the timer.
        Parameters:
        dc - the current draw context.
        Throws:
        java.lang.IllegalArgumentException - if the draw context is null.