Class CycleResultsRLEBufferTarget
- java.lang.Object
-
- io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget
-
- All Implemented Interfaces:
CanFilterResultValue,Output,java.lang.AutoCloseable
public class CycleResultsRLEBufferTarget extends java.lang.Object implements Output, CanFilterResultValue
Implements a convenient target buffer for Marker data that can be used to create nio ByteBuffers easily. This is not thread-safe. It is not meant to be used by concurrent callers. It is recommended to use theAutoCloseablemethod to ensure that partial runs are flushed automatically. Access the buffer for read via either thetoByteBuffer()or thetoSegmentsReadable()methods will automaticallyflush()and invalidate the writable buffer, so further writes will be deemed invalid and will cause an exception to be thrown.
-
-
Field Summary
Fields Modifier and Type Field Description static intBYTES
-
Constructor Summary
Constructors Constructor Description CycleResultsRLEBufferTarget(int elementCount)Create a target RLE buffer for the specified getCount in memory, rounded to the nearest record getCount.CycleResultsRLEBufferTarget(java.nio.ByteBuffer buf)Create a buffer with the provided ByteBuffer.
-
Method Summary
Modifier and Type Method Description voidclose()intgetRawBufferCapacity()intgetRecordCapacity()booleanonCycleResult(long cycle, int result)Record new cycle result data in the buffer, and optionally flush any completed RLE segments to the internal ByteBuffer.booleanonCycleResult(CycleResult cycleResult)voidsetFilter(java.util.function.Predicate<ResultReadable> filter)java.nio.ByteBuffertoByteBuffer()CycleResultsRLEBufferReadabletoSegmentsReadable()Convert the contents of this RLE buffer to a readable and invalide it for writing.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.engineblock.activityapi.output.Output
onCycleResultSegment
-
-
-
-
Field Detail
-
BYTES
public static final int BYTES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CycleResultsRLEBufferTarget
public CycleResultsRLEBufferTarget(java.nio.ByteBuffer buf)
Create a buffer with the provided ByteBuffer.- Parameters:
buf- the source data
-
CycleResultsRLEBufferTarget
public CycleResultsRLEBufferTarget(int elementCount)
Create a target RLE buffer for the specified getCount in memory, rounded to the nearest record getCount.- Parameters:
elementCount- The number of elements to buffer.
-
-
Method Detail
-
toSegmentsReadable
public CycleResultsRLEBufferReadable toSegmentsReadable()
Convert the contents of this RLE buffer to a readable and invalide it for writing.- Returns:
- a CycleResultRLEBuffer
-
toByteBuffer
public java.nio.ByteBuffer toByteBuffer()
-
onCycleResult
public boolean onCycleResult(long cycle, int result)Record new cycle result data in the buffer, and optionally flush any completed RLE segments to the internal ByteBuffer.- Specified by:
onCycleResultin interfaceOutput- Parameters:
cycle- The cycle number being marked.result- the result ordinal- Returns:
- false if there was no more room in the buffer for another tuple, true otherwise.
- Throws:
java.lang.RuntimeException- if the buffer has been converted to a readable form
-
getRawBufferCapacity
public int getRawBufferCapacity()
-
getRecordCapacity
public int getRecordCapacity()
-
close
public void close()
-
onCycleResult
public boolean onCycleResult(CycleResult cycleResult)
- Specified by:
onCycleResultin interfaceOutput
-
setFilter
public void setFilter(java.util.function.Predicate<ResultReadable> filter)
- Specified by:
setFilterin interfaceCanFilterResultValue
-
-