Module stormpot

Class TimeSpreadExpiration<T extends Poolable>

java.lang.Object
stormpot.internal.TimeSpreadExpiration<T>
Type Parameters:
T - The concrete poolable type.
All Implemented Interfaces:
Expiration<T>

public final class TimeSpreadExpiration<T extends Poolable> extends Object implements Expiration<T>
This is the standard time based Expiration. It will invalidate objects based on about how long ago they were allocated.
Since:
2.2
Author:
Chris Vest
  • Constructor Summary

    Constructors
    Constructor
    Description
    TimeSpreadExpiration(long lowerBound, long upperBound, TimeUnit unit)
    Construct a new Expiration that will invalidate objects that are older than the given lower bound, before they get older than the upper bound, in the given time unit.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    hasExpired(SlotInfo<? extends T> info)
    Returns true, with uniformly increasing probability, if the Poolable represented by the given SlotInfo is older than the lower bound, eventually returning true with 100% certainty when the age of the Poolable is equal to or greater than the upper bound.
    Produces a String representation of this TimeSpreadExpiration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface stormpot.Expiration

    every, every, or
  • Constructor Details

    • TimeSpreadExpiration

      public TimeSpreadExpiration(long lowerBound, long upperBound, TimeUnit unit)
      Construct a new Expiration that will invalidate objects that are older than the given lower bound, before they get older than the upper bound, in the given time unit.

      If the lowerBound is less than 1, the upperBound is less than the lowerBound, or the unit is null, then an IllegalArgumentException will be thrown.

      Parameters:
      lowerBound - Poolables younger than this, in the given unit, are not considered expired. This value must be at least 1.
      upperBound - Poolables older than this, in the given unit, are always considered expired. This value must be greater than the lowerBound.
      unit - The TimeUnit of the bounds values. Never null.
  • Method Details

    • hasExpired

      public boolean hasExpired(SlotInfo<? extends T> info)
      Returns true, with uniformly increasing probability, if the Poolable represented by the given SlotInfo is older than the lower bound, eventually returning true with 100% certainty when the age of the Poolable is equal to or greater than the upper bound.

      The uniformity of the random expiration holds regardless of how often a Poolable is checked. That is to say, checking a Poolable more times within an interval of time, does _not_ increase its chances of being declared expired.

      Specified by:
      hasExpired in interface Expiration<T extends Poolable>
      Parameters:
      info - An informative representative of the slot being tested. Never null.
      Returns:
      true if the Slot and Poolable in question should be deallocated, false if it is valid and eligible for claiming.
    • toString

      public String toString()
      Produces a String representation of this TimeSpreadExpiration.
      Overrides:
      toString in class Object