|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.io.ExpandingBuffer<T>
public abstract class ExpandingBuffer<T>
Abstraction of ExpandingByteBuffer and ExpandingCharBuffer to manage
indices and bookeeping for these buffers from a single control point. In general, this
class represents an expandable and thread safe buffer of elements of some type. T is the
type of a sequence of these elements of fixed length BUFFER_SIZE. Subclasses are responsible
for managing reading and writing, but need not interact directly with the expanding queue
of Ts, nor with the indices used to manage this queue. Instead, the methods in
this class provide the necessary tools. Synchronization should occur on the ExpandingBuffer
object to prevent conflicts between threads before invoking any of this class's helper methods.
| Field Summary | |
|---|---|
protected static int |
BUFFER_SIZE
|
| Constructor Summary | |
|---|---|
ExpandingBuffer()
|
|
| Method Summary | |
|---|---|
protected int |
allocate()
Allocate space in the buffer if none is available. |
protected abstract T |
allocateBuffer(int size)
Create a fixed-size sub-buffer |
protected boolean |
deallocate()
Deallocate the first buffer if it is no longer needed. |
protected int |
elementsInFirstBuffer()
Determine the number of buffered elements located in _buffers.getFirst() |
protected T |
firstBuffer()
Access the first buffer (assuming it exists) |
protected int |
firstIndex()
Calculate the first valid index in firstBuffer() (assuming it exists) |
boolean |
isEmpty()
|
protected T |
lastBuffer()
Access the last buffer (assuming it exists) |
protected int |
lastIndex()
Calculate the index after the last valid element in lastBuffer() (assuming it exists) |
protected void |
recordRead(long read)
Adjust the indices after reading the given number of elements. |
protected void |
recordWrite(long written)
Adjust the indices after writing the given number of elements. |
long |
size()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int BUFFER_SIZE
| Constructor Detail |
|---|
public ExpandingBuffer()
| Method Detail |
|---|
protected abstract T allocateBuffer(int size)
public long size()
public boolean isEmpty()
protected int allocate()
_buffers is nonempty). Should be called before
a write is attempted.
> 0)protected int elementsInFirstBuffer()
_buffers.getFirst()
protected boolean deallocate()
protected T firstBuffer()
protected int firstIndex()
firstBuffer() (assuming it exists)
protected T lastBuffer()
protected int lastIndex()
lastBuffer() (assuming it exists)
protected void recordWrite(long written)
protected void recordRead(long read)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||