K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class PriorityEvictionQueue<K,V> extends Object implements EvictionQueue<K,V>
EvictionQueue
which uses a Queue
to store its
entries. The queue should support priority queue semantics and the comparator
PriorityEvictionQueue.EvictibleEntryComparator
should always be used
for comparing entries.
The interface used is Queue
and not
PriorityQueue
since the most obvious concurrent
implementation, PriorityBlockingQueue
only conforms to the former
interface. This allows passing a different queue implementation, as far as it
is concurrent (thread-safe) and has priority semantics.
Modifier and Type | Class and Description |
---|---|
static class |
PriorityEvictionQueue.EvictibleEntryComparator<K,V>
A comparator that compares
EvictibleEntry instances based on
their eviction time. |
Constructor and Description |
---|
PriorityEvictionQueue(int initialCapacity)
Creates a priority eviction queue with a
PriorityBlockingQueue with the specified
initial capacity. |
PriorityEvictionQueue(Queue<EvictibleEntry<K,V>> queue)
Creates a priority eviction queue with the specified queue.
|
Modifier and Type | Method and Description |
---|---|
boolean |
evictEntries()
Evicts all entries that have expired from their maps and removes them
from the queue.
|
long |
getNextEvictionTime()
Returns the next eviction time of all entries contained in the queue, or
0 if the queue is empty.
|
boolean |
hasEntries()
Returns true if this queue contains any entries.
|
void |
putEntry(EvictibleEntry<K,V> e)
Puts the specified evictible entry into the queue.
|
void |
removeEntry(EvictibleEntry<K,V> e)
Removes the specified evictible entry from the queue.
|
public PriorityEvictionQueue(int initialCapacity)
PriorityBlockingQueue
with the specified
initial capacity.initialCapacity
- the initial capacityIllegalArgumentException
- if initial capacity is less than 1public PriorityEvictionQueue(Queue<EvictibleEntry<K,V>> queue)
queue
- the queue to be usedNullPointerException
- if the queue is null
public boolean hasEntries()
This implementation simply returns true if the queue is non-empty and vice versa.
hasEntries
in interface EvictionQueue<K,V>
public long getNextEvictionTime()
This implementation simply returns the eviction time of the first entry in the queue if it is non-empty, or 0 otherwise.
getNextEvictionTime
in interface EvictionQueue<K,V>
public void putEntry(EvictibleEntry<K,V> e)
This implementation simply invokes the add method on the queue.
putEntry
in interface EvictionQueue<K,V>
e
- the entry to be put into the queue.public void removeEntry(EvictibleEntry<K,V> e)
This implementation simply invokes the remove method on the queue.
removeEntry
in interface EvictionQueue<K,V>
e
- the entry to be removed from the queue.public boolean evictEntries()
This implementation uses the peek and poll method on the queue repeatedly to find and remove all entries that should be evicted, evicting them via their evict method.
evictEntries
in interface EvictionQueue<K,V>
Copyright © 2012–2016. All rights reserved.