|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.devexperts.qd.SubscriptionBuffer
public class SubscriptionBuffer
The SubscriptionBuffer
class is an universal buffer for subscription,
able to receive and retrieve subscription via all appropriate interfaces and via
random access. It uses cyclic buffers for efficient subscription storage.
NOTE: the SubscriptionBuffer
is not thread-safe;
it is designed to be used in a single-thread mode.
Field Summary | |
---|---|
static SubscriptionBuffer |
VOID
The instance of SubscriptionBuffer that is always empty. |
Constructor Summary | |
---|---|
SubscriptionBuffer()
|
Method Summary | |
---|---|
void |
clear()
Clears this subscription buffer. |
protected static void |
copy(java.lang.Object src,
java.lang.Object dst,
int head,
int tail,
int length)
Copies cyclic array buffer from source to destination. |
protected void |
ensureCapacity(DataRecord record)
Ensures that this buffer has capacity to visit and store specified record. |
void |
examineRecord(int index,
SubscriptionVisitor visitor)
Examines record by its index within this buffer via specivied visitor. |
boolean |
examineSubscription(SubscriptionVisitor visitor)
Examines accumulated subscription via specified subscription visitor. |
SubscriptionIterator |
examiningIterator()
Returns subscription iterator that examines this subscription buffer. |
int |
getCipher()
Returns cipher for the current record returned by last call to SubscriptionIterator.nextRecord() . |
int |
getCipher(int index)
Returns cipher of the record by its index within this buffer. |
DataRecord |
getRecord(int index)
Returns record by its index within this buffer. |
java.lang.String |
getSymbol()
Returns symbol for the current record returned by last call to SubscriptionIterator.nextRecord() . |
java.lang.String |
getSymbol(int index)
Returns symbol of the record by its index within this buffer. |
long |
getTime()
Returns time for the current record returned by last call to SubscriptionIterator.nextRecord() . |
long |
getTime(int index)
Returns time of the record by its index within this buffer. |
boolean |
hasCapacity()
Returns whether visitor has capacity to efficiently visit next record. |
boolean |
isEmpty()
Returns true if this subscription buffer has no records. |
DataRecord |
nextRecord()
Returns next record. |
protected void |
notifyListener()
Notifies subscription listener used in SubscriptionProvider part
of this subscription buffer. |
static boolean |
process(SubscriptionIterator iterator,
SubscriptionVisitor visitor)
Processes subscription from specified iterator via specified visitor. |
void |
processSubscription(SubscriptionIterator iterator)
Processes subscription from specified subscription iterator. |
boolean |
retrieveSubscription(SubscriptionVisitor visitor)
Retrieves accumulated subscription into specified subscription visitor. |
void |
setSubscriptionListener(SubscriptionListener listener)
Sets new subscription listener to receive notifications about subscription. |
int |
size()
Returns number of records in this subscription buffer. |
void |
visitRecord(DataRecord record,
int cipher,
java.lang.String symbol)
Visits next record using time = 0 . |
void |
visitRecord(DataRecord record,
int cipher,
java.lang.String symbol,
long time)
Visits next record. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final SubscriptionBuffer VOID
Constructor Detail |
---|
public SubscriptionBuffer()
Method Detail |
---|
public static boolean process(SubscriptionIterator iterator, SubscriptionVisitor visitor)
true
if some subscription may still remain in
the iterator or false
if all subscription were processed.
public int size()
public boolean isEmpty()
true
if this subscription buffer has no records.
public void clear()
public int getCipher(int index)
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public java.lang.String getSymbol(int index)
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public long getTime(int index)
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public DataRecord getRecord(int index)
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public void examineRecord(int index, SubscriptionVisitor visitor)
NOTE: unlike bulk transfer methods, this method does not check
SubscriptionVisitor.hasCapacity()
method of specified visitor.
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public boolean examineSubscription(SubscriptionVisitor visitor)
true
if not all accumulated subscription were examined
or false
if all accumulated subscription were examined.
public SubscriptionIterator examiningIterator()
NOTE: returned iterator possesses no special protection against concurrent modifications of this buffer and it will fail in unexpected way in such event; it should be used up before any such modifications.
public void processSubscription(SubscriptionIterator iterator)
SubscriptionConsumer
processSubscription
in interface SubscriptionConsumer
public boolean retrieveSubscription(SubscriptionVisitor visitor)
SubscriptionProvider
true
if some subscription still remains in the provider
or false
if all accumulated subscription were retrieved.
retrieveSubscription
in interface SubscriptionProvider
public void setSubscriptionListener(SubscriptionListener listener)
SubscriptionProvider
null
to set empty subscription listener (no notifications).
NOTE: if there is accumulated subscription available, then specified listener will be notified by this method.
setSubscriptionListener
in interface SubscriptionProvider
public int getCipher()
SubscriptionIterator
SubscriptionIterator.nextRecord()
.
Returns 0 if not encoded or if no current record is being iterated.
getCipher
in interface SubscriptionIterator
public java.lang.String getSymbol()
SubscriptionIterator
SubscriptionIterator.nextRecord()
.
Returns null if encoded or if no current record is being iterated.
getSymbol
in interface SubscriptionIterator
public long getTime()
SubscriptionIterator
SubscriptionIterator.nextRecord()
.
Returns 0 if not historical or if no current record is being iterated.
getTime
in interface SubscriptionIterator
public DataRecord nextRecord()
SubscriptionIterator
nextRecord
in interface SubscriptionIterator
public boolean hasCapacity()
SubscriptionVisitor
NOTE: subscription visitor must process all subscription that is passed to it via visitXXX calls no matter whether it has capacity to do it efficiently.
hasCapacity
in interface SubscriptionVisitor
public void visitRecord(DataRecord record, int cipher, java.lang.String symbol, long time)
SubscriptionVisitor
visitRecord
in interface SubscriptionVisitor
public void visitRecord(DataRecord record, int cipher, java.lang.String symbol)
time = 0
.
protected void notifyListener()
SubscriptionProvider
part
of this subscription buffer. Does not check actual subscription availability.
protected void ensureCapacity(DataRecord record)
protected static void copy(java.lang.Object src, java.lang.Object dst, int head, int tail, int length)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |