Class CyclicTimeouts<T extends CyclicTimeouts.Expirable>

java.lang.Object
org.eclipse.jetty.io.CyclicTimeouts<T>
Type Parameters:
T - the CyclicTimeouts.Expirable entity type
All Implemented Interfaces:
Destroyable
Direct Known Subclasses:
HttpConnection.RequestTimeouts, HttpDestination.RequestTimeouts

public abstract class CyclicTimeouts<T extends CyclicTimeouts.Expirable> extends Object implements Destroyable

An implementation of a timeout that manages many expirable entities whose timeouts are mostly cancelled or re-scheduled.

A typical scenario is for a parent entity to manage the timeouts of many children entities.

When a new entity is created, call schedule(Expirable) with the new entity so that this instance can be aware and manage the timeout of the new entity.

Eventually, this instance wakes up and iterates over the entities provided by iterator(). During the iteration, each entity:

When the iteration is complete, this instance is re-scheduled with the earliest expiration time calculated during the iteration.

See Also:
  • Field Details

    • LOG

      private static final Logger LOG
    • earliestTimeout

      private final AtomicLong earliestTimeout
    • cyclicTimeout

      private final CyclicTimeout cyclicTimeout
  • Constructor Details

    • CyclicTimeouts

      public CyclicTimeouts(Scheduler scheduler)
  • Method Details

    • iterator

      protected abstract Iterator<T> iterator()
      Returns:
      the entities to iterate over when this instance expires
    • onExpired

      protected abstract boolean onExpired(T expirable)

      Invoked during the iteration when the given entity is expired.

      This method may be invoked multiple times, and even concurrently, for the same expirable entity and therefore the expiration of the entity, if any, should be an idempotent action.

      Parameters:
      expirable - the entity that is expired
      Returns:
      whether the entity should be removed from the iterator via Iterator.remove()
    • onTimeoutExpired

      private void onTimeoutExpired()
    • schedule

      public void schedule(T expirable)

      Manages the timeout of a new entity.

      Parameters:
      expirable - the new entity to manage the timeout for
    • schedule

      private void schedule(long expiresAt)
    • destroy

      public void destroy()
      Specified by:
      destroy in interface Destroyable
    • schedule

      boolean schedule(CyclicTimeout cyclicTimeout, long delay, TimeUnit unit)