|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.devexperts.qd.ng.RecordSource
com.devexperts.qd.ng.RecordBuffer
public final class RecordBuffer
Buffers int and obj values of data records. This class has two 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 DataBuffer
.
This class is not synchronized and is not thread-safe without external synchronization.
Constructor Summary | |
---|---|
RecordBuffer()
Creates new RecordBuffer . |
Method Summary | |
---|---|
RecordCursor |
add(DataRecord record,
int cipher,
java.lang.String symbol)
Returns write cursor at the current limit and advances limit. |
RecordCursor |
add(RecordCursor from)
Adds a record from the specified RecordCursor . |
void |
addAll(RecordSource source)
|
void |
addAll(RecordSource source,
SubscriptionFilter filter)
|
void |
append(RecordCursor cursor)
Adds a record from the specified RecordCursor . |
boolean |
appendAndCompactIfNeeded(RecordCursor cursor)
Adds a record from the specified RecordCursor performing compact()
if needed to avoid growing the size of internal arrays. |
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()
Returs read cursor at the current position. |
RecordCursor |
cursorAt(long position)
Returns read cursor at a specified position. |
boolean |
examineData(DataVisitor visitor)
|
int |
getCipher()
Deprecated. Use next() and RecordCursor.getCipher() |
static RecordBuffer |
getInstance()
Returns instance from thread-local pool. |
long |
getLimit()
Retruns 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. |
long |
getPosition()
Retruns position of the current record. |
java.lang.String |
getSymbol()
Deprecated. Use next() and RecordCursor.getSymbol() |
long |
getTime()
Deprecated. Use next() and RecordCursor.getTime() |
boolean |
hasCapacity()
Returns whether visitor has capacity to efficiently visit next record. |
boolean |
hasNext()
|
boolean |
isEmpty()
|
RecordSource |
newSource()
Returns new RecordSource that reads this record buffer from
current position to its current limit . |
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) |
java.lang.Object |
nextObjField()
Deprecated. Use next() and RecordCursor.getObj(int) |
DataRecord |
nextRecord()
Deprecated. Use next() |
void |
processData(DataIterator it)
This implementation calls processData(it, null) . |
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 |
release()
Releases this RecordBuffer to a thread-local pool. |
void |
removeAt(long position)
Removes record at the specified position. |
void |
replaceRecordAt(long position,
DataRecord newRecord)
|
void |
replaceSymbolAt(long position,
int cipher,
java.lang.String symbol)
|
boolean |
retrieveData(DataVisitor visitor)
Retrieves accumulated data into specified data visitor. |
boolean |
retrieveData(RecordSink sink)
|
int |
retrieveDataAndCount(RecordFilter filter,
DataVisitor visitor,
boolean cleanup)
Retrieves data starting from this buffer's position into the specified visitor
and counts the number of retrieved records. |
int |
retrieveDataAndCount(RecordFilter filter,
RecordSink sink,
boolean cleanup)
Retrieves data starting from this buffer's position into the specified sink
and counts the number of retrieved records. |
void |
rewind()
|
void |
setDataListener(DataListener listener)
This method throws UnsupportedOperationException . |
void |
setLimit(long limit)
Sets new buffer limit and discards everything that written after that point. |
void |
setPosition(long position)
|
int |
size()
Returns the number of records that can be retrieved from this RecordBuffer. |
void |
visitIntField(DataIntField field,
int value)
Deprecated. Use add(com.devexperts.qd.DataRecord, int, java.lang.String) or get visitor via visitor() . |
void |
visitObjField(DataObjField field,
java.lang.Object value)
Deprecated. Use add(com.devexperts.qd.DataRecord, int, java.lang.String) or get visitor via visitor() . |
DataVisitor |
visitor()
Returns DataVisitor that adds all records to this buffer. |
DataVisitor |
visitor(int max,
RecordFilter filter)
Returns DataVisitor that adds at most max records that
match the specified filter to this buffer. |
void |
visitRecord(DataRecord record,
int cipher,
java.lang.String symbol)
Deprecated. Use add(com.devexperts.qd.DataRecord, int, java.lang.String) or get visitor via visitor() . |
void |
visitRecord(DataRecord record,
int cipher,
java.lang.String symbol,
long time)
Deprecated. Use add(com.devexperts.qd.DataRecord, int, java.lang.String) . |
RecordCursor |
writeCurrent()
Returs 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RecordBuffer()
RecordBuffer
.
Method Detail |
---|
public static RecordBuffer getInstance()
release()
method.
The recommended usage pattern is:
RecordBuffer buf = RecordBuffer.getInstance();
// do some local data transfer via buf
buf.release();
public void release()
RecordBuffer
to a thread-local pool.
getInstance()
public boolean isEmpty()
public int size()
public void clear()
public void rewind()
public RecordSource newSource()
RecordSource
that reads this record buffer from
current position
to its current limit
.
It is equivalent to newSource(getPosition(), getLimit())
.
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()
public long getLimit()
add(com.devexperts.qd.DataRecord, int, java.lang.String)
method.
public long getPosition()
next()
and current()
methods.
getPosition
in class RecordSource
public void setPosition(long position)
public void setLimit(long limit)
public RecordCursor cursorAt(long position)
getPosition()
method.
cursorAt
in class RecordSource
public RecordCursor writeCursorAt(long position)
getPosition()
method.
public RecordCursor current()
cursorAt(getPosition())
, but faster.
public RecordCursor writeCurrent()
writeCursorAt(getPosition())
, but faster.
public boolean hasNext()
public RecordCursor next()
next
in class RecordSource
public RecordCursor writeNext()
public RecordCursor add(DataRecord record, int cipher, java.lang.String symbol)
public RecordCursor add(RecordCursor from)
RecordCursor
. 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 appended data.
public void append(RecordCursor cursor)
RecordCursor
.
append
in interface RecordSink
public boolean appendAndCompactIfNeeded(RecordCursor cursor)
RecordCursor
performing compact()
if needed to avoid growing the size of internal arrays.
compacted
.public void replaceRecordAt(long position, DataRecord newRecord)
public void replaceSymbolAt(long position, int cipher, java.lang.String symbol)
public void removeAt(long position)
public boolean examineData(DataVisitor visitor)
public void addAll(RecordSource source)
public void addAll(RecordSource source, SubscriptionFilter filter)
public void processData(DataIterator it, SubscriptionFilter filter)
RecordSource
interface, this method calls
addAll((RecordSource)it, filter)
.
public DataVisitor visitor()
DataVisitor
that adds all records to this buffer.
public DataVisitor visitor(int max, RecordFilter filter)
DataVisitor
that adds at most max
records that
match the specified filter
to this buffer.
public void compact()
getPosition()
or
getLimit()
methods) become invalid. This method has the same effect as
compact(null)
.
public boolean compact(RecordFilter filter)
getPosition()
or
getLimit()
methods) become invalid.
filter
- Filter for records. Only accepted records are retained.
null filter is assumed to accept everything.
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
,
writeCursorAt
public int retrieveDataAndCount(RecordFilter filter, DataVisitor visitor, boolean cleanup)
position
into the specified visitor
and counts the number of retrieved records.
The retrieved data is optionally cleaned up from the buffer.
filter
- The filter to apply to all records before retrieiving. null means retrieve all.visitor
- The visitor to retrieve data to (will only receive records accepted by filter).cleanup
- when true, retrieved data is cleaned up from the buffer.
When data is cleaned up, you cannot rewind()
to retrieve it again;
size
is also reduced during cleanup.
public int retrieveDataAndCount(RecordFilter filter, RecordSink sink, boolean cleanup)
position
into the specified sink
and counts the number of retrieved records.
The retrieved data is optionally cleaned up from the buffer.
filter
- The filter to apply to all records before retrieiving. null means retrieve all.sink
- The sink to retrieve data to (will only receive records accepted by filter).cleanup
- when true, retrieved data is cleaned up from the buffer.
When data is cleaned up, you cannot rewind()
to retrieve it again;
size
is also reduced during cleanup.
public void processData(DataIterator it)
processData(it, null)
.
processData
in interface DataConsumer
public DataRecord nextRecord()
next()
DataIterator
nextRecord
in interface DataIterator
nextRecord
in interface SubscriptionIterator
public int getCipher()
next()
and RecordCursor.getCipher()
DataIterator
DataIterator.nextRecord()
.
Returns 0 if not encoded or if no current record is being iterated.
getCipher
in interface DataIterator
getCipher
in interface SubscriptionIterator
public java.lang.String getSymbol()
next()
and RecordCursor.getSymbol()
DataIterator
DataIterator.nextRecord()
.
Returns null if encoded or if no current record is being iterated.
getSymbol
in interface DataIterator
getSymbol
in interface SubscriptionIterator
public long getTime()
next()
and RecordCursor.getTime()
SubscriptionIterator
SubscriptionIterator.nextRecord()
.
Returns 0 if not historical or if no current record is being iterated.
getTime
in interface SubscriptionIterator
public int nextIntField()
next()
and RecordCursor.getInt(int)
DataIterator
nextIntField
in interface DataIterator
public java.lang.Object nextObjField()
next()
and RecordCursor.getObj(int)
DataIterator
nextObjField
in interface DataIterator
public boolean hasCapacity()
DataVisitor
NOTE: data visitor must process all data that is passed to it via visitXXX calls no matter whether it has capacity to do it efficiently.
hasCapacity
in interface DataVisitor
hasCapacity
in interface RecordSink
hasCapacity
in interface SubscriptionVisitor
public void visitRecord(DataRecord record, int cipher, java.lang.String symbol)
add(com.devexperts.qd.DataRecord, int, java.lang.String)
or get visitor via visitor()
.
DataVisitor
visitRecord
in interface DataVisitor
public void visitRecord(DataRecord record, int cipher, java.lang.String symbol, long time)
add(com.devexperts.qd.DataRecord, int, java.lang.String)
.
SubscriptionVisitor
visitRecord
in interface SubscriptionVisitor
public void visitIntField(DataIntField field, int value)
add(com.devexperts.qd.DataRecord, int, java.lang.String)
or get visitor via visitor()
.
DataVisitor
visitIntField
in interface DataVisitor
public void visitObjField(DataObjField field, java.lang.Object value)
add(com.devexperts.qd.DataRecord, int, java.lang.String)
or get visitor via visitor()
.
DataVisitor
visitObjField
in interface DataVisitor
public boolean retrieveData(DataVisitor visitor)
DataProvider
true
if some data still remains in the provider
or false
if all accumulated data were retrieved.
retrieveData
in interface DataProvider
public boolean retrieveData(RecordSink sink)
public void setDataListener(DataListener listener)
UnsupportedOperationException
.
setDataListener
in interface DataProvider
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |