Module stormpot

Class TimeExpiration<T extends Poolable>

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

public final class TimeExpiration<T extends Poolable> extends Object implements Expiration<T>
This is a time based Expiration. It will invalidate objects based on how long ago they were allocated.
Author:
Chris Vest
  • Constructor Details

    • TimeExpiration

      public TimeExpiration(long maxPermittedAge, TimeUnit unit)
      Construct a new Expiration that will invalidate objects that are older than the provided span of time in the given unit.

      If the maxPermittedAge is less than one, or the unit is null, then an IllegalArgumentException will be thrown.

      Parameters:
      maxPermittedAge - Poolables older than this, in the given unit, will be considered expired. This value must be at least 1.
      unit - The TimeUnit of the maximum permitted age. Never null.
  • Method Details

    • hasExpired

      public boolean hasExpired(SlotInfo<? extends T> info)
      Returns true if the Poolable represented by the given SlotInfo is older than the maximum age permitted by this TimeExpiration.
      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()
      Overrides:
      toString in class Object