Top Description Inners Fields Constructors Methods
com.github.benmanes.caffeine.cache

pack-priv final Class TimerWheel<K, V>

extends Object
implements Iterable<Node<K, V>>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Annotations
@SuppressWarnings:GuardedBy
Static Imports
com.github.benmanes.caffeine.cache.Caffeine.ceilingPowerOfTwo

A hierarchical timer wheel to add, remove, and fire expiration events in amortized O(1) time. The expiration events are deferred until the timer is advanced, which is performed as part of the cache's maintenance cycle.
Author
[email protected] (Ben Manes)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
pack-priv class
pack-priv static class
TimerWheel.Sentinel<K, V>

A sentinel for the doubly-linked list in the bucket.

pack-priv abstract class
TimerWheel.Traverser

An iterator with rough ordering that can be specialized for either direction.

Field Summary

Modifier and TypeField and Description
pack-priv static final int[]
pack-priv long
pack-priv static final long[]
pack-priv static final long[]
pack-priv final Node<K, V>[][]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
advance(BoundedLocalCache<K, V>
the instance that the entries belong to
cache
,
long
the current time, in nanoseconds
currentTimeNanos
)

Advances the timer and evicts entries that have expired.

public Iterator<Node<K, V>>
descendingIterator()

Returns an iterator roughly ordered by the expiration time from the entries least likely to expire (youngest) to the entries most likely to expire (oldest).

public void
deschedule(Node<K, V>
the entry in the cache
node
)

Removes a timer event for this entry if present.

pack-priv void
expire(BoundedLocalCache<K, V>
the instance that the entries belong to
cache
,
int
the timing wheel being operated on
index
,
long
the previous number of ticks
previousTicks
,
long
the number of additional ticks
delta
)

Expires entries or reschedules into the proper bucket if still active.

pack-priv Node<K, V>

Returns:

the sentinel at the head of the bucket
findBucket
(long
the time when the event fires
time
)

Determines the bucket that the timer event should be added to.

public long
getExpirationDelay()

Returns the duration until the next bucket expires, or Long#MAX_VALUE if none.

public Iterator<Node<K, V>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator roughly ordered by the expiration time from the entries most likely to expire (oldest) to the entries least likely to expire (youngest).
pack-priv long
peekAhead(int
the timing wheel being operated on
index
)

Returns the duration when the wheel's next bucket expires, or Long#MAX_VALUE if empty.

public void
reschedule(Node<K, V>
the entry in the cache
node
)

Reschedules an active timer event for the node.

public void
schedule(Node<K, V>
the entry in the cache
node
)

Schedules a timer event for the node.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUCKETSback to summary
pack-priv static final int[] BUCKETS
nanosback to summary
pack-priv long nanos
SHIFTback to summary
pack-priv static final long[] SHIFT
SPANSback to summary
pack-priv static final long[] SPANS
wheelback to summary
pack-priv final Node<K, V>[][] wheel

Constructor Detail

TimerWheelback to summary
pack-priv TimerWheel()
Annotations
@SuppressWarnings:rawtypes, unchecked

Method Detail

advanceback to summary
public void advance(BoundedLocalCache<K, V> cache, long currentTimeNanos)

Advances the timer and evicts entries that have expired.

Parameters
cache:BoundedLocalCache<K, V>

the instance that the entries belong to

currentTimeNanos:long

the current time, in nanoseconds

Annotations
@SuppressWarnings:PMD.UnusedAssignment
descendingIteratorback to summary
public Iterator<Node<K, V>> descendingIterator()

Returns an iterator roughly ordered by the expiration time from the entries least likely to expire (youngest) to the entries most likely to expire (oldest). The wheels are evaluated in order, but the timers that fall within the bucket's range are not sorted.

descheduleback to summary
public void deschedule(Node<K, V> node)

Removes a timer event for this entry if present.

Parameters
node:Node<K, V>

the entry in the cache

expireback to summary
pack-priv void expire(BoundedLocalCache<K, V> cache, int index, long previousTicks, long delta)

Expires entries or reschedules into the proper bucket if still active.

Parameters
cache:BoundedLocalCache<K, V>

the instance that the entries belong to

index:int

the timing wheel being operated on

previousTicks:long

the previous number of ticks

delta:long

the number of additional ticks

findBucketback to summary
pack-priv Node<K, V> findBucket(long time)

Determines the bucket that the timer event should be added to.

Parameters
time:long

the time when the event fires

Returns:Node<K, V>

the sentinel at the head of the bucket

getExpirationDelayback to summary
public long getExpirationDelay()

Returns the duration until the next bucket expires, or Long#MAX_VALUE if none.

Annotations
@SuppressWarnings:IntLongMath
iteratorback to summary
public Iterator<Node<K, V>> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator roughly ordered by the expiration time from the entries most likely to expire (oldest) to the entries least likely to expire (youngest). The wheels are evaluated in order, but the timers that fall within the bucket's range are not sorted.

Returns:Iterator<Node<K, V>>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
peekAheadback to summary
pack-priv long peekAhead(int index)

Returns the duration when the wheel's next bucket expires, or Long#MAX_VALUE if empty.

Parameters
index:int

the timing wheel being operated on

rescheduleback to summary
public void reschedule(Node<K, V> node)

Reschedules an active timer event for the node.

Parameters
node:Node<K, V>

the entry in the cache

scheduleback to summary
public void schedule(Node<K, V> node)

Schedules a timer event for the node.

Parameters
node:Node<K, V>

the entry in the cache

com.github.benmanes.caffeine.cache back to summary

pack-priv final Class TimerWheel.AscendingIterator

extends TimerWheel<K, V>.Traverser
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
Inherited from com.github.benmanes.caffeine.cache.TimerWheel.Traverser:
currentexpectedNanosnext

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv int
pack-priv @Nullable Node<K, V>
goToNextBucket()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextBucket.

Returns the sentinel for the wheel's next bucket, or null if the wheel is exhausted.
pack-priv @Nullable Node<K, V>
goToNextWheel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextWheel.

Returns the sentinel for the next wheel's bucket position, or null if no more wheels.
pack-priv boolean
isDone()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.isDone.

Returns if the iteration has completed.
pack-priv Node<K, V>
sentinel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.sentinel.

Returns the sentinel at the current wheel and bucket position.
pack-priv Node<K, V>
traverse(Node<K, V> node)

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.traverse.

Returns the node's successor, or the bucket's sentinel if at the end.
Inherited from com.github.benmanes.caffeine.cache.TimerWheel.Traverser:
computeNexthasNextnext

Field Detail

stepsback to summary
pack-priv int steps
wheelIndexback to summary
pack-priv int wheelIndex

Constructor Detail

AscendingIteratorback to summary
pack-priv AscendingIterator()

Method Detail

bucketIndexback to summary
pack-priv int bucketIndex()
goToNextBucketback to summary
pack-priv @Nullable Node<K, V> goToNextBucket()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextBucket.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextBucket.

Returns the sentinel for the wheel's next bucket, or null if the wheel is exhausted.

Annotations
@Override
goToNextWheelback to summary
pack-priv @Nullable Node<K, V> goToNextWheel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextWheel.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextWheel.

Returns the sentinel for the next wheel's bucket position, or null if no more wheels.

Annotations
@Override
isDoneback to summary
pack-priv boolean isDone()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.isDone.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.isDone.

Returns if the iteration has completed.

Annotations
@Override
sentinelback to summary
pack-priv Node<K, V> sentinel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.sentinel.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.sentinel.

Returns the sentinel at the current wheel and bucket position.

Annotations
@Override
traverseback to summary
pack-priv Node<K, V> traverse(Node<K, V> node)

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.traverse.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.traverse.

Returns the node's successor, or the bucket's sentinel if at the end.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv final Class TimerWheel.DescendingIterator

extends TimerWheel<K, V>.Traverser
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
Inherited from com.github.benmanes.caffeine.cache.TimerWheel.Traverser:
currentexpectedNanosnext

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv int
pack-priv @Nullable Node<K, V>
goToNextBucket()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextBucket.

Returns the sentinel for the wheel's next bucket, or null if the wheel is exhausted.
pack-priv @Nullable Node<K, V>
goToNextWheel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextWheel.

Returns the sentinel for the next wheel's bucket position, or null if no more wheels.
pack-priv boolean
isDone()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.isDone.

Returns if the iteration has completed.
pack-priv Node<K, V>
sentinel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.sentinel.

Returns the sentinel at the current wheel and bucket position.
pack-priv Node<K, V>
traverse(Node<K, V> node)

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.traverse.

Returns the node's successor, or the bucket's sentinel if at the end.
Inherited from com.github.benmanes.caffeine.cache.TimerWheel.Traverser:
computeNexthasNextnext

Field Detail

stepsback to summary
pack-priv int steps
wheelIndexback to summary
pack-priv int wheelIndex

Constructor Detail

DescendingIteratorback to summary
pack-priv DescendingIterator()

Method Detail

bucketIndexback to summary
pack-priv int bucketIndex()
goToNextBucketback to summary
pack-priv @Nullable Node<K, V> goToNextBucket()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextBucket.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextBucket.

Returns the sentinel for the wheel's next bucket, or null if the wheel is exhausted.

Annotations
@Override
goToNextWheelback to summary
pack-priv @Nullable Node<K, V> goToNextWheel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextWheel.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.goToNextWheel.

Returns the sentinel for the next wheel's bucket position, or null if no more wheels.

Annotations
@Override
isDoneback to summary
pack-priv boolean isDone()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.isDone.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.isDone.

Returns if the iteration has completed.

Annotations
@Override
sentinelback to summary
pack-priv Node<K, V> sentinel()

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.sentinel.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.sentinel.

Returns the sentinel at the current wheel and bucket position.

Annotations
@Override
traverseback to summary
pack-priv Node<K, V> traverse(Node<K, V> node)

Implements abstract com.github.benmanes.caffeine.cache.TimerWheel.Traverser.traverse.

Doc from com.github.benmanes.caffeine.cache.TimerWheel.Traverser.traverse.

Returns the node's successor, or the bucket's sentinel if at the end.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv final Class TimerWheel.Sentinel<K, V>

extends Node<K, V>
Class Inheritance

A sentinel for the doubly-linked list in the bucket.

Field Summary

Modifier and TypeField and Description
pack-priv Node<K, V>
pack-priv Node<K, V>
Inherited from com.github.benmanes.caffeine.cache.Node:
PROBATIONPROTECTEDWINDOW

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
containsValue(Object value)

Implements abstract com.github.benmanes.caffeine.cache.Node.containsValue.

Returns true if the given objects are considered equivalent.
public void
die()

Implements abstract com.github.benmanes.caffeine.cache.Node.die.

Sets the node to the dead state.
public @Nullable K
getKey()

Implements abstract com.github.benmanes.caffeine.cache.Node.getKey.

Return the key or null if it has been reclaimed by the garbage collector.
public Object
getKeyReference()

Implements abstract com.github.benmanes.caffeine.cache.Node.getKeyReference.

Returns the reference that the cache is holding the entry by.
public Node<K, V>
public Node<K, V>
public @Nullable V
getValue()

Implements abstract com.github.benmanes.caffeine.cache.Node.getValue.

Return the value or null if it has been reclaimed by the garbage collector.
public Object
getValueReference()

Implements abstract com.github.benmanes.caffeine.cache.Node.getValueReference.

Returns the reference to the value.
public boolean
isAlive()

Implements abstract com.github.benmanes.caffeine.cache.Node.isAlive.

If the entry is available in the hash-table and page replacement policy.
public boolean
isDead()

Implements abstract com.github.benmanes.caffeine.cache.Node.isDead.

If the entry was removed from the hash-table and the page replacement policy.
public boolean
isRetired()

Implements abstract com.github.benmanes.caffeine.cache.Node.isRetired.

If the entry was removed from the hash-table and is awaiting removal from the page replacement policy.
public void
retire()

Implements abstract com.github.benmanes.caffeine.cache.Node.retire.

Sets the node to the retired state.
public void
public void
public void
setValue(V value, @Nullable ReferenceQueue<V> referenceQueue)

Inherited from com.github.benmanes.caffeine.cache.Node:
casVariableTimecasWriteTimegetAccessTimegetNextInAccessOrdergetNextInWriteOrdergetPolicyWeightgetPreviousInAccessOrdergetPreviousInWriteOrdergetQueueTypegetVariableTimegetWeightgetWriteTimeinMainProbationinMainProtectedinWindowmakeMainProbationmakeMainProtectedmakeWindowsetAccessTimesetNextInAccessOrdersetNextInVariableOrdersetNextInWriteOrdersetPolicyWeightsetPreviousInAccessOrdersetPreviousInVariableOrdersetPreviousInWriteOrdersetQueueTypesetValuesetVariableTimesetWeightsetWriteTimetoString

Field Detail

nextback to summary
pack-priv Node<K, V> next
prevback to summary
pack-priv Node<K, V> prev

Constructor Detail

Sentinelback to summary
pack-priv Sentinel()

Method Detail

containsValueback to summary
public boolean containsValue(Object value)

Implements abstract com.github.benmanes.caffeine.cache.Node.containsValue.

Doc from com.github.benmanes.caffeine.cache.Node.containsValue.

Returns true if the given objects are considered equivalent. A strongly held value is compared by equality and a weakly or softly held value is compared by identity.

Annotations
@Override
dieback to summary
public void die()

Implements abstract com.github.benmanes.caffeine.cache.Node.die.

Doc from com.github.benmanes.caffeine.cache.Node.die.

Sets the node to the dead state.

Annotations
@Override
getKeyback to summary
public @Nullable K getKey()

Implements abstract com.github.benmanes.caffeine.cache.Node.getKey.

Doc from com.github.benmanes.caffeine.cache.Node.getKey.

Return the key or null if it has been reclaimed by the garbage collector.

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements abstract com.github.benmanes.caffeine.cache.Node.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.Node.getKeyReference.

Returns the reference that the cache is holding the entry by. This is either the key if strongly held or a java.lang.ref.WeakReference to that key.

Annotations
@Override
getNextInVariableOrderback to summary
public Node<K, V> getNextInVariableOrder()

Overrides com.github.benmanes.caffeine.cache.Node.getNextInVariableOrder.

Annotations
@Override
getPreviousInVariableOrderback to summary
public Node<K, V> getPreviousInVariableOrder()

Overrides com.github.benmanes.caffeine.cache.Node.getPreviousInVariableOrder.

Annotations
@Override
getValueback to summary
public @Nullable V getValue()

Implements abstract com.github.benmanes.caffeine.cache.Node.getValue.

Doc from com.github.benmanes.caffeine.cache.Node.getValue.

Return the value or null if it has been reclaimed by the garbage collector.

Annotations
@Override
getValueReferenceback to summary
public Object getValueReference()

Implements abstract com.github.benmanes.caffeine.cache.Node.getValueReference.

Doc from com.github.benmanes.caffeine.cache.Node.getValueReference.

Returns the reference to the value. This is either the value if strongly held or a java.lang.ref.Reference to that value.

Annotations
@Override
isAliveback to summary
public boolean isAlive()

Implements abstract com.github.benmanes.caffeine.cache.Node.isAlive.

Doc from com.github.benmanes.caffeine.cache.Node.isAlive.

If the entry is available in the hash-table and page replacement policy.

Annotations
@Override
isDeadback to summary
public boolean isDead()

Implements abstract com.github.benmanes.caffeine.cache.Node.isDead.

Doc from com.github.benmanes.caffeine.cache.Node.isDead.

If the entry was removed from the hash-table and the page replacement policy.

Annotations
@Override
isRetiredback to summary
public boolean isRetired()

Implements abstract com.github.benmanes.caffeine.cache.Node.isRetired.

Doc from com.github.benmanes.caffeine.cache.Node.isRetired.

If the entry was removed from the hash-table and is awaiting removal from the page replacement policy.

Annotations
@Override
retireback to summary
public void retire()

Implements abstract com.github.benmanes.caffeine.cache.Node.retire.

Doc from com.github.benmanes.caffeine.cache.Node.retire.

Sets the node to the retired state.

Annotations
@Override
setNextInVariableOrderback to summary
public void setNextInVariableOrder(@Nullable Node<K, V> next)
Annotations
@SuppressWarnings:NullAway
@Override
setPreviousInVariableOrderback to summary
public void setPreviousInVariableOrder(@Nullable Node<K, V> prev)
Annotations
@SuppressWarnings:NullAway
@Override
setValueback to summary
public void setValue(V value, @Nullable ReferenceQueue<V> referenceQueue)
Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv abstract Class TimerWheel.Traverser

extends Object
implements Iterator<Node<K, V>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Known Direct Subclasses
com.github.benmanes.caffeine.cache.TimerWheel.AscendingIterator, com.github.benmanes.caffeine.cache.TimerWheel.DescendingIterator

An iterator with rough ordering that can be specialized for either direction.

Field Summary

Modifier and TypeField and Description
pack-priv @Nullable Node<K, V>
pack-priv final long
pack-priv @Nullable Node<K, V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv @Nullable Node<K, V>
pack-priv abstract @Nullable Node<K, V>
goToNextBucket()

Returns the sentinel for the wheel's next bucket, or null if the wheel is exhausted.

pack-priv abstract @Nullable Node<K, V>
goToNextWheel()

Returns the sentinel for the next wheel's bucket position, or null if no more wheels.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
pack-priv abstract boolean
isDone()

Returns if the iteration has completed.

public Node<K, V>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
pack-priv abstract Node<K, V>
sentinel()

Returns the sentinel at the current wheel and bucket position.

pack-priv abstract Node<K, V>
traverse(Node<K, V> node)

Returns the node's successor, or the bucket's sentinel if at the end.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
pack-priv @Nullable Node<K, V> current
expectedNanosback to summary
pack-priv final long expectedNanos
nextback to summary
pack-priv @Nullable Node<K, V> next

Constructor Detail

Traverserback to summary
pack-priv Traverser()

Method Detail

computeNextback to summary
pack-priv @Nullable Node<K, V> computeNext()
goToNextBucketback to summary
pack-priv abstract @Nullable Node<K, V> goToNextBucket()

Returns the sentinel for the wheel's next bucket, or null if the wheel is exhausted.

goToNextWheelback to summary
pack-priv abstract @Nullable Node<K, V> goToNextWheel()

Returns the sentinel for the next wheel's bucket position, or null if no more wheels.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
isDoneback to summary
pack-priv abstract boolean isDone()

Returns if the iteration has completed.

nextback to summary
public Node<K, V> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Node<K, V>

the next element in the iteration

Annotations
@Override
@SuppressWarnings:NullAway
sentinelback to summary
pack-priv abstract Node<K, V> sentinel()

Returns the sentinel at the current wheel and bucket position.

traverseback to summary
pack-priv abstract Node<K, V> traverse(Node<K, V> node)

Returns the node's successor, or the bucket's sentinel if at the end.