Expirable entity type
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:
Expirable#getExpireNanoTime(); the entity is ignoredonExpired(Expirable) is called with that entity as parameterWhen the iteration is complete, this instance is re-scheduled with the earliest expiration time calculated during the iteration.
CyclicTimeout
| Modifier and Type | Class and Description |
|---|---|
| public static interface | CyclicTimeouts.Expirable
An entity that may expire. |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final CyclicTimeout | |
| private final AtomicLong | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| protected abstract Iterator | |
| protected abstract boolean | Returns: whether the entity should be removed from the iterator viaIterator#remove()the entity that is expired expirable)Invoked during the iteration when the given entity is expired. |
| private void | |
| public void | |
| private void | |
| pack-priv boolean |
| cyclicTimeout | back to summary |
|---|---|
| private final CyclicTimeout cyclicTimeout | |
| earliestNanoTime | back to summary |
|---|---|
| private final AtomicLong earliestNanoTime | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| CyclicTimeouts | back to summary |
|---|---|
| public CyclicTimeouts(Scheduler scheduler) | |
| destroy | back to summary |
|---|---|
| public void destroy() Implements org.
| |
| iterator | back to summary |
|---|---|
protected abstract Iterator
| |
| onExpired | back to summary |
|---|---|
| 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. When
| |
| onTimeoutExpired | back to summary |
|---|---|
| private void onTimeoutExpired() | |
| schedule | back to summary |
|---|---|
| public void schedule(T expirable) Manages the timeout of a new entity.
| |
| schedule | back to summary |
|---|---|
| private void schedule(long expiresAt) | |
| schedule | back to summary |
|---|---|
| pack-priv boolean schedule(CyclicTimeout cyclicTimeout, long delay, TimeUnit unit) | |
An entity that may expire.
| Modifier and Type | Method and Description |
|---|---|
| public long | Returns: the expiration time in nanoseconds, orLong#MAX_VALUE if this entity does not expireReturns the expiration time in nanoseconds. |
| getExpireNanoTime | back to summary |
|---|---|
| public long getExpireNanoTime() Returns the expiration time in nanoseconds. The value to return must be calculated taking into account the current nanoTime, for example: expireNanoTime = NanoTime.now() + timeoutNanos
Returning
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | onTimeoutExpired()
Implements abstract org. Invoked when the timeout expires. |
| Timeouts | back to summary |
|---|---|
| private Timeouts(Scheduler scheduler) | |
| onTimeoutExpired | back to summary |
|---|---|
| public void onTimeoutExpired() Implements abstract org. Doc from org. Invoked when the timeout expires.
| |