Package nz.org.riskscape.engine.sched
Class LinkedListBuffer
java.lang.Object
nz.org.riskscape.engine.sched.LinkedListBuffer
- All Implemented Interfaces:
PageBuffer
,ReadPageBuffer
,WritePageBuffer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
LinkedListBuffer
(int pageSize, int pageCapacity) Create a buffer with a fixed page-size and a maximum number of pages it can hold at any one time.LinkedListBuffer
(PageAllocator allocator, int tupleCapacity) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a page of output Tuples to the buffer.int
int
the maximum number of tuples we can have present in the buffer at once before it is considered full.boolean
boolean
isEmpty()
boolean
isFull()
void
Signals to the downstream worker task that this process has now completed writing all its output to the buffer.newPage()
Allocates a new page to write Tuples to.long
long
read()
int
size()
toString()
withMaxPageSize
(int pageSize)
-
Field Details
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZE- See Also:
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITY- See Also:
-
-
Constructor Details
-
LinkedListBuffer
protected LinkedListBuffer() -
LinkedListBuffer
protected LinkedListBuffer(int pageSize, int pageCapacity) Create a buffer with a fixed page-size and a maximum number of pages it can hold at any one time. This is mostly used for testing.
-
LinkedListBuffer
-
-
Method Details
-
withMaxPageSize
- Returns:
- a new buffer with all the same settings, except for a new maximum page size.
-
getMaxPageSize
public int getMaxPageSize()- Returns:
- the max number of tuples that could potentially fill in one page
-
newPage
Description copied from interface:WritePageBuffer
Allocates a new page to write Tuples to. Note that
WritePageBuffer.add(Page page)
actually adds the Tuples to the buffer.- Specified by:
newPage
in interfaceWritePageBuffer
-
add
Description copied from interface:WritePageBuffer
Adds a page of output Tuples to the buffer.
- Specified by:
add
in interfaceWritePageBuffer
-
isFull
public boolean isFull()- Specified by:
isFull
in interfaceWritePageBuffer
- Returns:
- true if the WritePageBuffer has reached capacity. If so, the downstream
worker task needs to read pages from the buffer before more can be written.
Note that due to supporting multi-threaded writers, this is a polite back-off
that the writing worker task should honour, rather than a hard limit, i.e.
WritePageBuffer.newPage()
andWritePageBuffer.add(Page page)
will not strictly enforce the capacity limit.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceReadPageBuffer
- Returns:
- true if there are no more pages in the buffer to read (because we're waiting for the upstream worker task to write more).
-
read
- Specified by:
read
in interfaceReadPageBuffer
- Returns:
- a page of Tuples to read, or null if there's no Tuples to read
-
markComplete
public void markComplete()Description copied from interface:WritePageBuffer
Signals to the downstream worker task that this process has now completed writing all its output to the buffer.
- Specified by:
markComplete
in interfaceWritePageBuffer
-
isComplete
public boolean isComplete()- Specified by:
isComplete
in interfaceReadPageBuffer
- Returns:
- true if there are no more pages in the buffer to read (because the upstream worker task has finished writing all its output).
-
size
public int size()- Specified by:
size
in interfaceReadPageBuffer
- Returns:
- the current number of unread tuples in the buffer.
-
toString
-
newReaderClone
- Specified by:
newReaderClone
in interfacePageBuffer
- Returns:
- a clone of the ReadPageBuffer. This allows multiple different threads to read from the same input buffer without interfering with each other. Both the cloned and the original ReadPageBuffer will get all the same input Tuples/pages, without actually duplicating the underlying input memory-wise.
-
numTuplesWritten
public long numTuplesWritten()- Specified by:
numTuplesWritten
in interfaceWritePageBuffer
- Returns:
- the total number of Tuples written to this buffer (for diagnostics).
-
numTuplesRead
public long numTuplesRead()- Specified by:
numTuplesRead
in interfaceReadPageBuffer
- Specified by:
numTuplesRead
in interfaceWritePageBuffer
- Returns:
- the total number of Tuples read from the buffer (for diagnostics).
-
getTupleCapacity
public int getTupleCapacity()the maximum number of tuples we can have present in the buffer at once before it is considered full. Note that this capacity can be overshot slightly, as pages can be different sizes.
- Specified by:
getTupleCapacity
in interfaceWritePageBuffer
-