Module stormpot

Class EveryExpiration<T extends Poolable>

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

public final class EveryExpiration<T extends Poolable> extends Object implements Expiration<T>
The implementation of the Expiration.every(long, TimeUnit) and Expiration.every(long, long, TimeUnit) expiration combinators.
  • Constructor Details

    • EveryExpiration

      public EveryExpiration(Expiration<T> innerExpiration, long fromTime, long toTime, TimeUnit unit)
      Create an instance of the combinator with the given configuration.
      Parameters:
      innerExpiration - The inner expiration to wrap.
      fromTime - The lower expiration time bound.
      toTime - The upper expiration time bound.
      unit - The time unit of the bounds.
  • Method Details

    • hasExpired

      public boolean hasExpired(SlotInfo<? extends T> info) throws Exception
      Description copied from interface: Expiration
      Test whether the Slot and Poolable object, represented by the given SlotInfo object, is still valid, or if the pool should deallocate it and allocate a replacement.

      If the method throws an exception, then that is taken to mean that the slot is invalid. The exception will bubble out of the claim method, but the mechanism is implementation specific. For this reason, it is generally advised that Expirations do not throw exceptions.

      Note that this method can be called as often as several times per claim. The performance of this method therefor has a big influence on the perceived performance of the pool.

      If this implementation ends up being expensive, then the every-combinator can be used to construct a new expiration object that only performs the expensive check every so often.

      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.
      Throws:
      Exception - If checking the validity of the Slot or Poolable somehow went wrong. In this case, the Poolable will be assumed to be expired.