@InterfaceAudience.Private public class LruCachedBlockQueue extends Object implements HeapSize
Use this when you want to find the largest elements (according to their ordering, not their heap size) that consume as close to the specified maxSize as possible. Default behavior is to grow just above rather than just below specified max.
Object used in this queue must implement HeapSize
as well as
Comparable
.
Modifier and Type | Field and Description |
---|---|
private long |
heapSize |
private long |
maxSize |
private com.google.common.collect.MinMaxPriorityQueue<LruCachedBlock> |
queue |
Constructor and Description |
---|
LruCachedBlockQueue(long maxSize,
long blockSize) |
Modifier and Type | Method and Description |
---|---|
void |
add(LruCachedBlock cb)
Attempt to add the specified cached block to this queue.
|
long |
heapSize()
Total size of all elements in this queue.
|
LruCachedBlock |
poll() |
LruCachedBlock |
pollLast() |
private com.google.common.collect.MinMaxPriorityQueue<LruCachedBlock> queue
private long heapSize
private long maxSize
public LruCachedBlockQueue(long maxSize, long blockSize)
maxSize
- the target size of elements in the queueblockSize
- expected average size of blockspublic void add(LruCachedBlock cb)
If the queue is smaller than the max size, or if the specified element is ordered before the smallest element in the queue, the element will be added to the queue. Otherwise, there is no side effect of this call.
cb
- block to try to add to the queuepublic LruCachedBlock poll()
null
if the queue is
empty.public LruCachedBlock pollLast()
null
if the queue is
empty.Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.