Class CyclicTimeouts<T extends CyclicTimeouts.Expirable>
- Type Parameters:
 T- theCyclicTimeouts.Expirableentity type
- All Implemented Interfaces:
 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:
- may never expire (see 
CyclicTimeouts.Expirable.getExpireNanoTime(); the entity is ignored - may be expired; 
onExpired(Expirable)is called with that entity as parameter - may expire at a future time; the iteration records the earliest expiration time among all non-expired entities
 
When the iteration is complete, this instance is re-scheduled with the earliest expiration time calculated during the iteration.
- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn entity that may expire. - 
Constructor Summary
Constructors - 
Method Summary
 
- 
Constructor Details
- 
CyclicTimeouts
 
 - 
 - 
Method Details
- 
iterator
 - 
onExpired
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.
When
falseis returned, the implementation should adjust theCyclicTimeouts.Expirableexpiration, so that a call toCyclicTimeouts.Expirable.getExpireNanoTime()after this method has returned yields a new expiration nanoTime.- Parameters:
 expirable- the entity that is expired- Returns:
 - whether the entity should be removed from the iterator via 
Iterator.remove() 
 - 
iterate
protected void iterate() - 
schedule
Schedules a timeout for a new or modified item.
If an item returned by the
iterator()has been modified or added so that it may now be the earliest expiring item, then this method should be called to schedule the timeout. This need not be called for a recurrent timeout duringExpirable#onTimeoutExpired(), nor if the timeout of an existing item is increased. However, it is safe and inexpensive to always call this when modifying an item expiration time.- Parameters:
 expirable- the new entity to manage the timeout for
 - 
destroy
public void destroy()- Specified by:
 destroyin interfaceDestroyable
 
 -