Module stormpot

Class OrExpiration<T extends Poolable>

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

public final class OrExpiration<T extends Poolable> extends Object implements Expiration<T>
Provides a way to compose Expirations.

Given two Expirations, this class considers that a slot is expired if any of the Expiration returns true. This makes it easy to have an Expiration that expires both on time (Expiration.after(long, TimeUnit)) and some other criteria.

Since:
2.4
Author:
Guillaume Lederrey
  • Constructor Details

    • OrExpiration

      public OrExpiration(Expiration<T> firstExpiration, Expiration<T> secondExpiration)
      Create a new instance with the given two expirations.
      Parameters:
      firstExpiration - The first expiration to check.
      secondExpiration - The second expiration to check.
  • Method Details

    • hasExpired

      public boolean hasExpired(SlotInfo<? extends T> info) throws Exception
      Returns true if any of the given Expiration has 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.
      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.