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
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedLinkedListBuffer(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) Creates a newLinkedListBufferinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a page of output Tuples to the buffer.intintthe maximum number of tuples we can have present in the buffer at once before it is considered full.booleanbooleanisEmpty()booleanisFull()voidSignals 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.longlongread()intsize()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
Creates a new
LinkedListBufferinstance.- Parameters:
allocator- Controls the number of Tuples per page (i.e. allocated by newPage())tupleCapacity- 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.
-
-
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:WritePageBufferAllocates a new page to write Tuples to. Note that
WritePageBuffer.add(Page page)actually adds the Tuples to the buffer.- Specified by:
newPagein interfaceWritePageBuffer
-
add
Description copied from interface:WritePageBufferAdds a page of output Tuples to the buffer.
- Specified by:
addin interfaceWritePageBuffer
-
isFull
public boolean isFull()- Specified by:
isFullin 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:
isEmptyin 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:
readin 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:WritePageBufferSignals to the downstream worker task that this process has now completed writing all its output to the buffer.
- Specified by:
markCompletein interfaceWritePageBuffer
-
isComplete
public boolean isComplete()- Specified by:
isCompletein 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:
sizein interfaceReadPageBuffer- Returns:
- the current number of unread tuples in the buffer.
-
toString
-
newReaderClone
- Specified by:
newReaderClonein 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:
numTuplesWrittenin interfaceWritePageBuffer- Returns:
- the total number of Tuples written to this buffer (for diagnostics).
-
numTuplesRead
public long numTuplesRead()- Specified by:
numTuplesReadin interfaceReadPageBuffer- Specified by:
numTuplesReadin 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:
getTupleCapacityin interfaceWritePageBuffer
-