Top Description Inners Fields Constructors Methods
org.eclipse.jetty.io

public abstract Class CyclicTimeouts<T extends CyclicTimeouts.Expirable>

extends Object
implements Destroyable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.Destroyable
Type Parameters
<T>
the Expirable entity type
Imports
java.util.Iterator, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicLong, org.eclipse.jetty.util.NanoTime, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.thread.Scheduler, org.slf4j.Logger, .LoggerFactory

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
CyclicTimeout

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
CyclicTimeouts.Expirable

An entity that may expire.

private class

Field Summary

Modifier and TypeField and Description
private final CyclicTimeout
private final AtomicLong
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
protected abstract Iterator<T>

Returns:

the entities to iterate over when this instance expires
iterator
()

protected abstract boolean

Returns:

whether the entity should be removed from the iterator via Iterator#remove()
onExpired
(T
the entity that is expired
expirable
)

Invoked during the iteration when the given entity is expired.

private void
public void
schedule(T
the new entity to manage the timeout for
expirable
)

Manages the timeout of a new entity.

private void
schedule(long expiresAt)

pack-priv boolean
schedule(CyclicTimeout cyclicTimeout, long delay, TimeUnit unit)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cyclicTimeoutback to summary
private final CyclicTimeout cyclicTimeout
earliestNanoTimeback to summary
private final AtomicLong earliestNanoTime
LOGback to summary
private static final Logger LOG

Constructor Detail

CyclicTimeoutsback to summary
public CyclicTimeouts(Scheduler scheduler)

Method Detail

destroyback to summary
public void destroy()

Implements org.eclipse.jetty.util.component.Destroyable.destroy.

Annotations
@Override
iteratorback to summary
protected abstract Iterator<T> iterator()
Returns:Iterator<T>

the entities to iterate over when this instance expires

onExpiredback 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 false is returned, the implementation should adjust the Expirable expiration, so that a call to Expirable#getExpireNanoTime() after this method has returned yields a new expiration nanoTime.

Parameters
expirable:T

the entity that is expired

Returns:boolean

whether the entity should be removed from the iterator via Iterator#remove()

onTimeoutExpiredback to summary
private void onTimeoutExpired()
scheduleback to summary
public void schedule(T expirable)

Manages the timeout of a new entity.

Parameters
expirable:T

the new entity to manage the timeout for

scheduleback to summary
private void schedule(long expiresAt)
scheduleback to summary
pack-priv boolean schedule(CyclicTimeout cyclicTimeout, long delay, TimeUnit unit)
org.eclipse.jetty.io back to summary

public Interface CyclicTimeouts.Expirable


An entity that may expire.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the expiration time in nanoseconds, or Long#MAX_VALUE if this entity does not expire
getExpireNanoTime
()

Returns the expiration time in nanoseconds.

Method Detail

getExpireNanoTimeback 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 Long#MAX_VALUE indicates that this entity does not expire.

Returns:long

the expiration time in nanoseconds, or Long#MAX_VALUE if this entity does not expire

org.eclipse.jetty.io back to summary

private Class CyclicTimeouts.Timeouts

extends CyclicTimeout
Class Inheritance

Constructor Summary

AccessConstructor and Description
private
Timeouts(Scheduler scheduler)

Method Summary

Modifier and TypeMethod and Description
public void
onTimeoutExpired()

Implements abstract org.eclipse.jetty.io.CyclicTimeout.onTimeoutExpired.

Invoked when the timeout expires.

Inherited from org.eclipse.jetty.io.CyclicTimeout:
canceldestroygetSchedulerschedule

Constructor Detail

Timeoutsback to summary
private Timeouts(Scheduler scheduler)

Method Detail

onTimeoutExpiredback to summary
public void onTimeoutExpired()

Implements abstract org.eclipse.jetty.io.CyclicTimeout.onTimeoutExpired.

Doc from org.eclipse.jetty.io.CyclicTimeout.onTimeoutExpired.

Invoked when the timeout expires.

Annotations
@Override