public final class RecordBuffer extends RecordSource implements RecordProvider, RecordSink, DataConsumer, SubscriptionConsumer, RecordConsumer
cursors of its own --
one is used for read and is returned by cursorAt(long), current(),
and next() methods, the other is used for write and is returned
by add(com.devexperts.qd.DataRecord, int, java.lang.String) method. This class is faster replacement for deprecated
DataBuffer and SubscriptionBuffer classes.
This class is not synchronized and is not thread-safe without external synchronization.
VOIDVOIDVOIDVOIDVOID| Constructor and Description |
|---|
RecordBuffer()
Creates new
RecordBuffer with a default mode of DATA. |
RecordBuffer(RecordMode mode)
Creates new
RecordBuffer with a specified mode. |
| Modifier and Type | Method and Description |
|---|---|
RecordCursor |
add(DataRecord record,
int cipher,
String symbol)
Returns write cursor at the current limit and advances limit.
|
RecordCursor |
add(RecordCursor from)
Adds a record to this buffer from the specified
RecordCursor
and returns write cursor to the recently added record. |
void |
addAll(RecordSource source)
Deprecated.
|
void |
addAll(RecordSource source,
SubscriptionFilter filter)
Deprecated.
|
RecordCursor |
addDataAndCompactIfNeeded(RecordCursor from)
Adds record with data from the specified
RecordCursor. |
void |
append(RecordCursor from)
Adds a record to this buffer from the specified
RecordCursor. |
void |
cleanup(RecordCursor cursor)
Cleanups the data at the corresponding cursor and reduces
size() by one. |
void |
clear()
|
void |
compact()
Compacts data by copying everything between position and limit to the beginning of the buffer.
|
boolean |
compact(RecordFilter filter)
Compacts data by copying all records that are accepted by filter between position and limit to
the beginning of the buffer.
|
RecordCursor |
current()
Returns read cursor at the current position.
|
RecordCursor |
cursorAt(long position)
Returns read cursor at a specified position.
|
void |
flagFrom(long position,
int eventFlags)
|
void |
flush()
Signal that it is safe to flush
appended records to disk,
e.g. |
int |
getCipher()
Deprecated.
Use
next() and RecordCursor.getCipher() |
int |
getCipherAt(long position)
Returns cipher at the specified position.
|
long |
getEventTimeSequenceAt(long position)
Returns event time sequence at the specified position.
|
static RecordBuffer |
getInstance()
Returns instance from thread-local pool with a default mode of
RecordMode.DATA. |
static RecordBuffer |
getInstance(RecordMode mode)
Returns instance from thread-local pool with a specified mode.
|
long |
getLimit()
Returns limit of this buffer,
which is the position of the record that will be added with
add(com.devexperts.qd.DataRecord, int, java.lang.String) method. |
RecordMode |
getMode()
Returns current mode of this record buffer.
|
long |
getPosition()
Returns position of the current record.
|
DataRecord |
getRecordAt(long position)
Returns record at the specified position.
|
String |
getSymbol()
Deprecated.
Use
next() and RecordCursor.getSymbol() |
String |
getSymbolAt(long position)
Returns symbol at the specified position.
|
long |
getTime()
Deprecated.
Use
next() and RecordCursor.getTime() |
boolean |
hasCapacity()
Returns
true when this record buffer is not capacity-limited
(which is default) or, when buffer is capacity-limited, when more records can be added to it. |
boolean |
hasEstimatedCapacityForBytes(int bytes)
Returns
true if this record buffer has an estimated capacity to hold a result
of parsing a specified number of bytes in binary encoding before becoming too big to be
released into a pool. |
boolean |
hasNext()
|
boolean |
isCapacityLimited()
Returns
true when this record buffer is capacity-limited. |
boolean |
isEmpty()
Returns
true when this buffer is empty,
that is when its size is zero. |
RecordSource |
newSource()
Returns new
RecordSource that reads this record buffer from
current position to its current limit with the same
mode. |
RecordSource |
newSource(long start,
long end)
Returns new
RecordSource that reads this record buffer from
the specified start position to the specified end position. |
RecordCursor |
next()
Returns read cursor at the current position and advances position to next record.
|
int |
nextIntField()
Deprecated.
Use
next() and RecordCursor.getInt(int) |
Object |
nextObjField()
Deprecated.
Use
next() and RecordCursor.getObj(int) |
DataRecord |
nextRecord()
Deprecated.
Use
next() |
void |
process(RecordSource source)
Adds all records from the specified source to this buffer.
|
void |
process(RecordSource source,
SubscriptionFilter filter)
Adds all records that match a given filter from the specified source to this buffer.
|
void |
processData(DataIterator it)
Processes data from specified iterator and adds to this record buffer all records.
|
void |
processData(DataIterator it,
SubscriptionFilter filter)
Processes data from specified iterator and adds to this record buffer all records that are
accepted by the specified filter.
|
void |
processSubscription(SubscriptionIterator it)
Processes subscription from specified iterator and adds to this record buffer all records.
|
void |
processSubscription(SubscriptionIterator it,
SubscriptionFilter filter)
Processes subscription from specified iterator and adds to this record buffer all records that are
accepted by the specified filter.
|
void |
release()
Releases this
RecordBuffer to a thread-local pool. |
void |
removeAt(long position)
Removes record at the specified position.
|
void |
removeRange(long fromPosition,
long toPosition)
Removes records from the specified fromPosition inclusive and toPosition exclusive.
|
void |
replaceRecordAt(long position,
DataRecord newRecord)
Replaces record at the specified position.
|
void |
replaceSymbolAt(long position,
int cipher,
String symbol)
Replaces symbol at the specified position.
|
boolean |
retrieve(RecordSink sink)
Retrieves all records from
position to limit
into the given sink and advances position while the sink has capacity. |
boolean |
retrieveData(DataVisitor visitor)
Deprecated.
|
boolean |
retrieveSubscription(SubscriptionVisitor visitor)
Deprecated.
|
void |
rewind()
Sets
position of this buffer to the beginning, so that added record can be retrieved again. |
void |
setCapacityLimit(int capacityLimit)
Sets the capacity limit in the number of records for this record buffer.
|
void |
setCapacityLimited(boolean capacityLimited)
Changes capacity-limited flag of this record buffer.
|
void |
setDataListener(DataListener listener)
This method is provided for compatibility with a legacy
DataProvider interface
and throws UnsupportedOperationException. |
void |
setLimit(long limit)
Sets new buffer limit and discards everything that written after that point.
|
void |
setMode(RecordMode mode)
Changes current mode of this record buffer.
|
void |
setPosition(long position)
Changes position of the current record.
|
void |
setRecordListener(RecordListener listener)
This method throws
UnsupportedOperationException. |
void |
setSubscriptionListener(SubscriptionListener listener)
This method is provided for compatibility with a legacy
SubscriptionProvider interface
and throws UnsupportedOperationException. |
int |
size()
Returns the number of records that were added to this RecordBuffer.
|
String |
toString()
Returns string representation of this buffer for debugging purposes.
|
void |
unlinkFrom(long position)
|
void |
visitIntField(DataIntField field,
int value)
Deprecated.
Use
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer. |
void |
visitObjField(DataObjField field,
Object value)
Deprecated.
Use
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer. |
DataVisitor |
visitor()
Deprecated.
Use this implementation of
DataVisitor interface directly if absolutely needed
and reconsider this use completely, because DataVisitor is a legacy interface. |
void |
visitRecord(DataRecord record,
int cipher,
String symbol)
Deprecated.
Use
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer. |
void |
visitRecord(DataRecord record,
int cipher,
String symbol,
long time)
Deprecated.
Use
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer. |
RecordCursor |
writeCurrent()
Returns write cursor at the current position.
|
RecordCursor |
writeCursorAt(long position)
Returns write cursor at a specified position.
|
RecordCursor |
writeNext()
Returns write cursor at the current position and advances position to next record.
|
public RecordBuffer()
RecordBuffer with a default mode of DATA.
The new record buffer is not capacity-limited by default.public RecordBuffer(RecordMode mode)
RecordBuffer with a specified mode.
The new record buffer is not capacity-limited by default.public static RecordBuffer getInstance()
RecordMode.DATA.
This instance can be returned to pool with release() method.
The recommended usage pattern is:
RecordBuffer buf = RecordBuffer.getInstance();
// do some local data transfer via buf
buf.release();
This instance has the same state as returned by a default constructor.
In particular, it is not capacity-limited by default.
public static RecordBuffer getInstance(RecordMode mode)
release() method.
The recommended usage pattern is:
RecordBuffer buf = RecordBuffer.getInstance(mode);
// do some local data transfer via buf
buf.release();
This instance has the same state as returned by a
RecordBuffer(mode) constructor.
In particular, it is not capacity-limited by default.
public void release()
RecordBuffer to a thread-local pool. Many operations
on this buffer throw IllegalStateException when invoked on an object
that was released into pool (especially modifying ones). Read and write
cursors of this buffer become unusable, too.
There is a limit on how big can be instances (in terms of memory they consume) that are stored in the pool. Instances that are too big are left for GC.
IllegalStateException - if object was already released.getInstance()public boolean isEmpty()
true when this buffer is empty,
that is when its size is zero.true this buffer is empty.public int size()
public RecordMode getMode()
getMode in interface RecordProvidergetMode in class RecordSourcepublic void setMode(RecordMode mode)
empty.mode - new mode.NullPointerException - if mode is null.IllegalStateException - if attempting to change mode of non-empty buffer.public boolean isCapacityLimited()
true when this record buffer is capacity-limited.
When buffer is capacity-limited, then hasCapacity() will
return false when adding more records into this buffer
may make it ineligible to be released into pool.public void setCapacityLimited(boolean capacityLimited)
isCapacityLimited()public void setCapacityLimit(int capacityLimit)
capacityLimit - the capacity limitIllegalArgumentException - if capacityLimit < 0 (see POOLED_CAPACITY or
UNLIMITED_CAPACITY)public boolean hasCapacity()
true when this record buffer is not capacity-limited
(which is default) or, when buffer is capacity-limited, when more records can be added to it.hasCapacity in interface DataVisitorhasCapacity in interface RecordSinkhasCapacity in interface SubscriptionVisitorpublic boolean hasEstimatedCapacityForBytes(int bytes)
true if this record buffer has an estimated capacity to hold a result
of parsing a specified number of bytes in binary encoding before becoming too big to be
released into a pool.
It assumes that each int or object item takes at least one bytes.bytes - the number of bytes.true if this record buffer has an estimated capacity to hold a result
of parsing a specified number of bytes in binary encoding.public void clear()
size, position and limit to zero.
The mode and capacity-limiting
of this record buffer remains the same.IllegalStateException - if object was already released into pool.public void rewind()
position of this buffer to the beginning, so that added record can be retrieved again.IllegalStateException - if object was already released into pool.public RecordSource newSource()
RecordSource that reads this record buffer from
current position to its current limit with the same
mode.
It is equivalent to newSource(getPosition(), getLimit()).newSource in class RecordSourceIllegalStateException - if object was already released into pool.newSource(long, long)public RecordSource newSource(long start, long end)
RecordSource that reads this record buffer from
the specified start position to the specified end position.newSource in class RecordSourceIllegalStateException - if object was already released into pool.newSource()public long getLimit()
add(com.devexperts.qd.DataRecord, int, java.lang.String) method.getLimit in class RecordSourcepublic long getPosition()
getPosition in class RecordSourcepublic void setPosition(long position)
RecordSource.getPosition(), RecordSource.getLimit()
or next().getPosition()
methods are allowed here.setPosition in class RecordSourceposition - new position.public void setLimit(long limit)
Size is reduced by the number of discarded records.
This method also resets write cursor to avoid accidental corruption of data.
Only values that were previously returned by getPosition() or getLimit() methods
are allowed here.IndexOutOfBoundsException - if limit is invalid or above current limit.public DataRecord getRecordAt(long position)
getPosition() method.position - position of the record to return.IndexOutOfBoundsException - if position is invalid or above current limit.public int getCipherAt(long position)
getPosition() method.position - position of the cipher to return.IndexOutOfBoundsException - if position is invalid or above current limit.public String getSymbolAt(long position)
getPosition() method.position - position of the symbol to return.IndexOutOfBoundsException - if position is invalid or above current limit.public long getEventTimeSequenceAt(long position)
getPosition() method.
This method returns zero when getMode().hasEventTimeSequence() returns false.position - position of the event time sequence to return.IndexOutOfBoundsException - if position is invalid or above current limit.public RecordCursor cursorAt(long position)
RecordSource.getPosition() or RecordSource.getLimit() method.
Invoking this method at the current position results in the same cursor as
the call RecordSource.current() or call to RecordSource.next() without the side effect of
advancing position.
The result of this method at the current limit is null.
The mode of the resulting cursor is the same as returned by RecordSource.getMode().
cursorAt in class RecordSourcepublic RecordCursor writeCursorAt(long position)
getPosition() method.IndexOutOfBoundsException - if position is invalid or above current limit.public RecordCursor current()
cursorAt(getPosition()), but faster.
It is the same as call to RecordSource.next() without the side effect of
advancing position.
The mode of the resulting cursor is the same as returned by RecordSource.getMode().
current in class RecordSourcepublic RecordCursor writeCurrent()
writeCursorAt(getPosition()), but faster.public boolean hasNext()
true when more records can be read from this buffer,
that is when position is less than limit.true when more records can be read from this buffer.public RecordCursor next()
null when
position is equal to limit.
The mode of the resulting cursor is the same as returned by RecordSource.getMode().
next in class RecordSourcepublic RecordCursor writeNext()
null when
position is equal to limit.public RecordCursor add(DataRecord record, int cipher, String symbol)
IllegalStateException - if object was already released into pool.public RecordCursor add(RecordCursor from)
RecordCursor
and returns write cursor to the recently added record.
This method is a shortcut to
add(from.getRecord(), from.getCipher(), from.getSymbol()).
copyFrom(from)
Use faster append(RecordCursor) method if you do not need to change added data.
This method also copies all extra information (event flags,
time marks, time sequence,
and attachment) that can be
stored under this buffer's mode (note that links are not copied),
including cursor-local event flags, time mark and attachment that can be set via its owner's
Owner.setEventFlags,
Owner.setTimeMark, and
Owner.setAttachment methods.
IllegalStateException - if object was already released into pool.public void append(RecordCursor from)
RecordCursor.
The minimal subset of fields based on current mode and
cursor mode is copied.
All values are copied when both modes are DATA, only time if at least one
of them is HISTORY_SUBSCRIPTION, and nothing is copied
if at least one of them is SUBSCRIPTION (without time).
This method also copies all extra information (event flags,
time marks, time sequence,
and attachment) that can be
stored under this buffer's mode (note that links are not copied),
including cursor-local event flags, time mark and attachment that can be set via its owner's
Owner.setEventFlags,
Owner.setTimeMark, and
Owner.setAttachment methods.
append in interface RecordSinkfrom - the cursor to append from.IllegalStateException - if object was already released into pool.public RecordCursor addDataAndCompactIfNeeded(RecordCursor from)
RecordCursor.
If the specified cursor has mode that does not have full data
(RecordMode.HISTORY_SUBSCRIPTION or RecordMode.SUBSCRIPTION),
then the missing data fields are left at default values.
Buffer is compacted if it runs out of capacity.
After compaction all previously queried long positions (via getPosition() or
getLimit() methods) or read cursors become invalid.
Extra information from the cursor (like event time marks, flags, etc) is NOT added.
from - the cursor to copy data from.IllegalStateException - if object was already released into pool.RecordCursor.copyDataFrom(RecordCursor)public void replaceRecordAt(long position,
DataRecord newRecord)
position - the position.newRecord - new record.IllegalArgumentException - if replacing cannot be performed because different number of fields
needs to be stored between old and new record, which depends on mode.IndexOutOfBoundsException - if position is invalid or above current limit.public void replaceSymbolAt(long position,
int cipher,
String symbol)
position - the position.cipher - new cipher.symbol - new symbol.IndexOutOfBoundsException - if position is invalid or above current limit.public void removeAt(long position)
IndexOutOfBoundsException - if position is invalid or above current limit.public void removeRange(long fromPosition,
long toPosition)
fromPosition - start positiontoPosition - end position, exclusiveIndexOutOfBoundsException - if position is invalid or above current limit.IllegalArgumentException - if input positions and internal state of buffer are mismatched.public void process(RecordSource source)
process(source, null).process in interface RecordConsumersource - the source.IllegalStateException - when adding records to an object that was already released into pool.public void process(RecordSource source, SubscriptionFilter filter)
source - the source.filter - the filter.IllegalStateException - when adding records to an object that was already released into pool.public void addAll(RecordSource source)
process(RecordSource).source - the source.IllegalStateException - when adding records to an object that was already released into pool.public void addAll(RecordSource source, SubscriptionFilter filter)
process(RecordSource, SubscriptionFilter).source - the source.filter - the filter.IllegalStateException - when adding records to an object that was already released into pool.public void processData(DataIterator it, SubscriptionFilter filter)
RecordSource interface, this method calls
addAll((RecordSource) it, filter).
Use addAll(RecordSource) or addAll(RecordSource, SubscriptionFilter) directly when
iterator is statically known to be RecordSource in the calling code.IllegalStateException - when adding records to an object that was already released into pool.public void processSubscription(SubscriptionIterator it, SubscriptionFilter filter)
RecordSource interface, this method calls
addAll((RecordSource) it, filter).
Use addAll(RecordSource) or addAll(RecordSource, SubscriptionFilter) directly when
iterator is statically known to be RecordSource in the calling code.IllegalStateException - when adding records to an object that was already released into pool.public DataVisitor visitor()
DataVisitor interface directly if absolutely needed
and reconsider this use completely, because DataVisitor is a legacy interface.DataVisitor that adds all records to this buffer.
This implementation returns this.public void compact()
Size is set to the number of remaining records.
After compaction all previously queried long positions (via getPosition() or
getLimit() methods) or read/write cursors become invalid. This method has the same effect as
compact(null).IllegalStateException - if object was already released into pool.public boolean compact(RecordFilter filter)
Size is set to the number of remaining records.
After compaction all previously queried long positions (via getPosition() or
getLimit() methods) or read/write cursors become invalid.filter - Filter for records. Only accepted records are retained.
null filter is assumed to accept everything.IllegalStateException - if object was already released into pool.IllegalArgumentException - if filter is not null and
this buffer's mode hasLink.public void cleanup(RecordCursor cursor)
size() by one.
The cursor should have been retrieved via one of the following methods:
next,
current,
add(record,cipher,symbol),
add(cursor),
cursorAt,
writeCursorAtIndexOutOfBoundsException - if cursor's position is invalid or above current limit.IllegalStateException - if the data at the corresponding cursor was already cleared.public void unlinkFrom(long position)
links
from the given position up until (but not before) this buffer's position.
Unlinked records are marked with true result of
RecordCursor.isUnlinked() method.
If the record at the given position was not previously linked with
RecordCursor.setLinkTo method, then only one record is unlinked,
otherwise the chain of links is followed till the head of the record buffer.position - the position to start at.IllegalStateException - if the record at the specified position was already unlinked or
if this buffer's mode does not have links.public void flagFrom(long position,
int eventFlags)
links
from the given position up until (but not before) this buffer's position.
Record's event flags are OR-ed with a give eventFlags.position - the position to start at.IllegalStateException - if the record at the specified position was unlinked or
if this buffer's mode does not have links
or does not have event flags.public boolean retrieve(RecordSink sink)
position to limit
into the given sink and advances position while the sink has capacity.retrieve in interface RecordProviderretrieve in class RecordSourcesink - the sink.true if all data was retrieved,
false if sink ran out of capacity and more records remain to retrieve.public void setRecordListener(RecordListener listener)
UnsupportedOperationException.setRecordListener in interface RecordProviderlistener - the listener.public void flush()
appended records to disk,
e.g. no locks are currently held.
This implementation does nothing.
flush in interface RecordSinkpublic void processData(DataIterator it)
processData(it, null).
Use addAll(RecordSource) or addAll(RecordSource, SubscriptionFilter) when
iterator is statically known to be RecordSource in the calling code.processData in interface DataConsumerIllegalStateException - when adding records to an object that was already released into pool.public void processSubscription(SubscriptionIterator it)
processSubscription(it, null).
Use addAll(RecordSource) or addAll(RecordSource, SubscriptionFilter) when
iterator is statically known to be RecordSource in the calling code.processSubscription in interface SubscriptionConsumerIllegalStateException - when adding records to an object that was already released into pool.public DataRecord nextRecord()
next()RecordSourcenextRecord in interface DataIteratornextRecord in interface SubscriptionIteratornextRecord in class RecordSourcepublic int getCipher()
next() and RecordCursor.getCipher()RecordSourceDataIterator.nextRecord().
Returns 0 if not encoded or if no current record is being iterated.getCipher in interface DataIteratorgetCipher in interface SubscriptionIteratorgetCipher in class RecordSourcepublic String getSymbol()
next() and RecordCursor.getSymbol()RecordSourceDataIterator.nextRecord().
Returns null if encoded or if no current record is being iterated.getSymbol in interface DataIteratorgetSymbol in interface SubscriptionIteratorgetSymbol in class RecordSourcepublic long getTime()
next() and RecordCursor.getTime()RecordSourceSubscriptionIterator.nextRecord().
Returns 0 if not historical or if no current record is being iterated.getTime in interface SubscriptionIteratorgetTime in class RecordSourcepublic int nextIntField()
next() and RecordCursor.getInt(int)RecordSourcenextIntField in interface DataIteratornextIntField in class RecordSourcepublic Object nextObjField()
next() and RecordCursor.getObj(int)RecordSourcenextObjField in interface DataIteratornextObjField in class RecordSourcepublic void visitRecord(DataRecord record, int cipher, String symbol)
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer.RecordSinkvisitRecord in interface DataVisitorvisitRecord in interface RecordSinkIllegalStateException - if this cursor mode is not DATA.public void visitRecord(DataRecord record, int cipher, String symbol, long time)
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer.RecordSinkvisitRecord in interface RecordSinkvisitRecord in interface SubscriptionVisitorpublic void visitIntField(DataIntField field, int value)
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer.RecordSinkvisitIntField in interface DataVisitorvisitIntField in interface RecordSinkpublic void visitObjField(DataObjField field, Object value)
add(com.devexperts.qd.DataRecord, int, java.lang.String) to add records into this buffer.RecordSinkvisitObjField in interface DataVisitorvisitObjField in interface RecordSinkpublic boolean retrieveData(DataVisitor visitor)
retrieve(RecordSink)true if some data still remains in the provider
or false if all accumulated data were retrieved.retrieveData in interface DataProviderretrieveData in interface RecordProviderpublic void setDataListener(DataListener listener)
DataProvider interface
and throws UnsupportedOperationException.setDataListener in interface DataProvidersetDataListener in interface RecordProviderpublic boolean retrieveSubscription(SubscriptionVisitor visitor)
retrieve(RecordSink)true if some subscription still remains in the provider
or false if all accumulated subscription were retrieved.retrieveSubscription in interface RecordProviderretrieveSubscription in interface SubscriptionProviderpublic void setSubscriptionListener(SubscriptionListener listener)
SubscriptionProvider interface
and throws UnsupportedOperationException.setSubscriptionListener in interface RecordProvidersetSubscriptionListener in interface SubscriptionProviderCopyright © 2002–2025 Devexperts LLC. All rights reserved.