|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.devexperts.qd.qtp.AbstractMessageVisitor
com.devexperts.qd.qtp.AbstractByteArrayComposer
public abstract class AbstractByteArrayComposer
Base class for classes that compose QTP messages data into byte array.
It consolidates common logic for text
and binary
byte array composers.
Most of it's logic was simply extracted from ByteArrayComposer.
Classes that are interested in extra-high performance can use ByteArrayComposer directly, and classes that are interested in opportunity to compose data both in text and binary formats can use this class.
NOTE: All protected methods declared to throw IOException actually never do this, because underlying ByteArrayDataOutput never do this. They are declared to throw IOException only in order not to process it in every subclass but to process it here. The only reason why IOException can be thrown is that there are errors in internal logic of a class. That's why AssertionError is always thrown in this case.
ByteArrayComposer
,
TextByteArrayComposer
,
AbstractByteArrayParser
Nested Class Summary | |
---|---|
protected static class |
AbstractByteArrayComposer.RecordState
|
Field Summary | |
---|---|
protected static int |
DEFAULT_THERESHOLD
|
protected boolean |
historyAddSubscription
|
protected static int |
MIN_BUFFER_SIZE
|
protected com.devexperts.io.ByteArrayOutput |
out
|
protected byte[] |
pooledBuffer
|
protected int |
processed
|
protected AbstractByteArrayComposer.RecordState[] |
recordState
|
protected DataScheme |
scheme
|
protected int |
threshold
|
Constructor Summary | |
---|---|
AbstractByteArrayComposer(DataScheme scheme)
Constructs composer with a specified scheme in a stateless mode (describe messages are not being composed). |
|
AbstractByteArrayComposer(DataScheme scheme,
boolean composeDescribeRecords)
Constructs composer with a specified scheme and a describe records mode. |
Method Summary | |
---|---|
protected void |
beginMessage(int messageTypeId)
Invoked every time before processing a message. |
protected abstract void |
composeHistorySubscriptionTime(DataRecord record,
long time)
|
protected abstract void |
composeIntField(DataIntField field,
int value)
|
protected abstract void |
composeMessageHeader(int messageTypeId)
Composes header of a message of specific type. |
protected abstract void |
composeObjField(DataObjField field,
java.lang.Object value)
|
protected abstract void |
composeOtherMessageBody(byte[] messageBytes,
int offset,
int length)
|
protected abstract void |
composeRecord(DataRecord record,
int cipher,
java.lang.String symbol)
|
protected void |
endMessage()
Invoked every time after processing all message data. |
protected abstract void |
finishComposingMessage(int messageStart)
Performs actions necessary to finish composing a message (for example, inserts message size, inserts records descriptions if necessary). |
byte[] |
getBuffer()
Returns byte array buffer where data is stored. |
int |
getProcessed()
Returns number of processed bytes ready to be sent over and removed. |
int |
getThreshold()
Returns current threshold. |
boolean |
hasCapacity()
Returns whether visitor has capacity to efficiently visit next record. |
protected void |
moveDataForward(int oldPos,
int newPos,
int length)
Accurately moves block of data of length length in
out buffer form position oldPos
into position newPos . |
void |
removeBytes(int n)
Removes specified number of bytes from the start of the buffer. |
void |
resetSession()
Resets session state for composer with describe records mode. |
void |
setThreshold(int threshold)
Sets new threshold. |
boolean |
visitData(DataProvider provider,
MessageType type)
This method consumes available data for data message from the given data provider. |
void |
visitIntField(DataIntField field,
int value)
Visits next Int-field within current record. |
void |
visitObjField(DataObjField field,
java.lang.Object value)
Visits next Obj-field within current record. |
boolean |
visitOtherMessage(int messageType,
byte[] messageBytes,
int offset,
int length)
This implementation simply skips all unknown messages. |
void |
visitRecord(DataRecord record,
int cipher,
java.lang.String symbol)
Visits next record. |
void |
visitRecord(DataRecord record,
int cipher,
java.lang.String symbol,
long time)
Visits next record. |
boolean |
visitSubscription(SubscriptionProvider provider,
MessageType type)
This method consumes available subscription for subscription message from the given subscription provider. |
Methods inherited from class com.devexperts.qd.qtp.AbstractMessageVisitor |
---|
visitDescribeProtocol, visitHistoryAddSubscription, visitHistoryData, visitHistoryRemoveSubscription, visitStreamAddSubscription, visitStreamData, visitStreamRemoveSubscription, visitTickerAddSubscription, visitTickerData, visitTickerRemoveSubscription |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int threshold
protected static final int DEFAULT_THERESHOLD
protected byte[] pooledBuffer
protected static final int MIN_BUFFER_SIZE
protected boolean historyAddSubscription
protected final DataScheme scheme
protected final AbstractByteArrayComposer.RecordState[] recordState
protected final com.devexperts.io.ByteArrayOutput out
protected int processed
Constructor Detail |
---|
public AbstractByteArrayComposer(DataScheme scheme)
AbstractByteArrayComposer(scheme, false)
.
scheme
- Data scheme to use.public AbstractByteArrayComposer(DataScheme scheme, boolean composeDescribeRecords)
scheme
- The data scheme.composeDescribeRecords
- If true
, then describe messages are composed right before
records are used for the first time and this instance keeps its state and shall not be
reused for different communication sessions.Method Detail |
---|
public void removeBytes(int n)
n
- Number of bytes to remove.
java.lang.IllegalArgumentException
- if specified number is negative
or is larger than the number of processed bytes.public int getThreshold()
public void setThreshold(int threshold)
Note that it is not guaranteed that accumulated data will never exceed threshold. The threshold is merely a hint and it is observed only by some methods.
threshold
- New thereshold.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 SubscriptionVisitor
public void resetSession()
java.lang.UnsupportedOperationException
- when composer was constructed witout describe records mode.AbstractByteArrayComposer(DataScheme, boolean)
public int getProcessed()
public byte[] getBuffer()
Note: the array instance used for buffering may change if new messages are added or previous ones are removed.
public void visitRecord(DataRecord record, int cipher, java.lang.String symbol)
DataVisitor
visitRecord
in interface DataVisitor
protected abstract void composeRecord(DataRecord record, int cipher, java.lang.String symbol) throws java.io.IOException
java.io.IOException
public void visitRecord(DataRecord record, int cipher, java.lang.String symbol, long time)
SubscriptionVisitor
visitRecord
in interface SubscriptionVisitor
protected abstract void composeHistorySubscriptionTime(DataRecord record, long time) throws java.io.IOException
java.io.IOException
public void visitIntField(DataIntField field, int value)
DataVisitor
visitIntField
in interface DataVisitor
protected abstract void composeIntField(DataIntField field, int value) throws java.io.IOException
java.io.IOException
public void visitObjField(DataObjField field, java.lang.Object value)
DataVisitor
visitObjField
in interface DataVisitor
protected abstract void composeObjField(DataObjField field, java.lang.Object value) throws java.io.IOException
java.io.IOException
public boolean visitData(DataProvider provider, MessageType type)
AbstractMessageVisitor
visitData
in interface MessageVisitor
visitData
in class AbstractMessageVisitor
false
if it had retrieved all available data and no data left,
true
if more data remains to be consumedpublic boolean visitSubscription(SubscriptionProvider provider, MessageType type)
AbstractMessageVisitor
visitSubscription
in interface MessageVisitor
visitSubscription
in class AbstractMessageVisitor
false
if it had retrieved all available subscription and nothing left,
true
if more subscription remains to be consumedpublic boolean visitOtherMessage(int messageType, byte[] messageBytes, int offset, int length)
AbstractMessageVisitor
visitOtherMessage
in interface MessageVisitor
visitOtherMessage
in class AbstractMessageVisitor
messageType
- integer number representing a type of the message.messageBytes
- array containing message data.offset
- position of the first byte of message data in messageBytes
array.length
- number of bytes starting from offset in
messageBytes
related to this message.
- Returns:
- true if the whole message was not processed because the visitor is full
and false if the message was successfully processed.
protected abstract void composeOtherMessageBody(byte[] messageBytes, int offset, int length) throws java.io.IOException
java.io.IOException
protected void beginMessage(int messageTypeId)
messageTypeId
- id of message type (see MessageConstants
).protected abstract void composeMessageHeader(int messageTypeId) throws java.io.IOException
messageTypeId
- id of message type (see MessageConstants
).
java.io.IOException
- never. If it has been thrown then it means an internal error.protected void endMessage()
protected abstract void finishComposingMessage(int messageStart) throws java.io.IOException
ByteArrayComposer
.
messageStart
- position in buffer where message begins. The end of a message
is at current buffer position (out.getPosition()
).
java.io.IOException
- never.protected void moveDataForward(int oldPos, int newPos, int length)
length
in
out
buffer form position oldPos
into position newPos
.
oldPos
- position to move from.newPos
- position to move into.length
- length of data block.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |