com.devexperts.qd.qtp
Class MessageAdapter

java.lang.Object
  extended by com.devexperts.qd.qtp.MessageConsumerAdapter
      extended by com.devexperts.qd.qtp.MessageAdapter
All Implemented Interfaces:
MessageAdapterMBean, MessageConstants, MessageConsumer, MessageProvider
Direct Known Subclasses:
AgentAdapter, DistributorAdapter

public abstract class MessageAdapter
extends MessageConsumerAdapter
implements MessageProvider, MessageAdapterMBean

The MessageAdapter is a basic adapter of some entity to message API. It implements both MessageConsumer and MessageProvider interfaces with default behavior and is recommended for extension by specific adapters (instead of pure implementations of corresponding interfaces). Certain QTP connectors works only with MessageAdapter as a single representative of some entity.


Nested Class Summary
static class MessageAdapter.AbstractFactory
          An abstract message adapter factory.
static interface MessageAdapter.CloseListener
          The CloseListener is used to notify QTP connector that this message adapter was closed by some reason.
static interface MessageAdapter.Factory
          The Factory performs creation of actual message agents on demand from QTP connector.
 
Field Summary
protected  MessageAdapter.CloseListener closeListener
           
protected  MessageListener messageListener
           
 
Fields inherited from interface com.devexperts.qd.qtp.MessageConstants
MESSAGE_DESCRIBE_PROTOCOL, MESSAGE_DESCRIBE_RECORDS, MESSAGE_DESCRIBE_RESERVED, MESSAGE_HEARTBEAT, MESSAGE_HISTORY_ADD_SUBSCRIPTION, MESSAGE_HISTORY_DATA, MESSAGE_HISTORY_REMOVE_SUBSCRIPTION, MESSAGE_PART, MESSAGE_RAW_DATA, MESSAGE_RMI_CANCEL, MESSAGE_RMI_DESCRIBE_OPERATION, MESSAGE_RMI_DESCRIBE_SUBJECT, MESSAGE_RMI_ERROR, MESSAGE_RMI_REQUEST, MESSAGE_RMI_RESULT, MESSAGE_STREAM_ADD_SUBSCRIPTION, MESSAGE_STREAM_DATA, MESSAGE_STREAM_REMOVE_SUBSCRIPTION, MESSAGE_TEXT_FORMAT_COMMENT, MESSAGE_TEXT_FORMAT_SPECIAL, MESSAGE_TICKER_ADD_SUBSCRIPTION, MESSAGE_TICKER_DATA, MESSAGE_TICKER_REMOVE_SUBSCRIPTION
 
Constructor Summary
protected MessageAdapter(QDStats stats)
           
 
Method Summary
protected  boolean addMask(long mask)
          Adds bytes from argument mask to internal mask and notifies listeners if internal mask changed.
protected static long clearMessageMask(long mask, MessageType message)
           
 void close()
          Closes this adapter.
protected  void closeImpl()
           
static DataScheme getCommonScheme(QDCollector c1, QDCollector c2, QDCollector c3)
          Returns common data scheme or throws IllegalArgumentException.
 com.devexperts.util.TypedMap getConnectionVariables()
          Returns per-connection variables for this message adapter.
protected static long getMessageMask(MessageType message)
           
protected  java.lang.String getRemoteHostAddress()
           
abstract  DataScheme getScheme()
           
 QDStats getStats()
           
 java.lang.String getStatus()
           
static SubscriptionFilterFactory getSubscriptionFilterFactory(DataScheme scheme)
           
 void handleCorruptedMessage(int messageType)
           
 void handleCorruptedStream()
           
 void handleUnknownMessage(int messageType)
           
protected static boolean hasMessageMask(long mask, MessageType message)
           
 boolean isAlive()
          Returns true when this message adapter is alive (was started and was not closed yet).
 boolean isClosed()
           
 boolean isProtocolDescriptorCompatible(ProtocolDescriptor desc)
           
 long nextRetrieveTime(long currentTime)
           
protected  void notifyListener()
           
 void prepareProtocolDescriptor(ProtocolDescriptor desc)
          Prepares outgoing protocol descriptor.
 void processDescribeProtocol(ProtocolDescriptor desc)
          Process incoming protocol descriptor.
protected  void reportIgnoredMessage(MessageType message)
           
protected  long retrieveDescribeProtocolMessage(MessageVisitor visitor, long mask)
           
protected  long retrieveMask()
           
 boolean retrieveMessages(MessageVisitor visitor)
          Retrieves accumulated message into specified message visitor.
 void setCloseListener(MessageAdapter.CloseListener listener)
           
 void setConnectionVariables(com.devexperts.util.TypedMap connectionVariables)
          Sets per-connection variables for this message adapter.
 void setMessageListener(MessageListener listener)
          Note: this method SHOULD be called before calling .start() - it does not give immediate notification regarding the pending messages
 void start()
          Starts this adapter.
protected  void startImpl()
           
 java.lang.String toString()
          Returns description of this MessageAdapter for management and logging purposes.
 void useDescribeProtocol()
          Invocation of this method causes this MessageAdapter to send DESCRIBE_PROTOCOL message if it is capable of doing so.
 
Methods inherited from class com.devexperts.qd.qtp.MessageConsumerAdapter
getSymbol, processData, processHistoryAddSubscription, processHistoryData, processHistoryRemoveSubscription, processOtherMessage, processStreamAddSubscription, processStreamData, processStreamRemoveSubscription, processSubscription, processTickerAddSubscription, processTickerData, processTickerRemoveSubscription
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

closeListener

protected volatile MessageAdapter.CloseListener closeListener

messageListener

protected volatile MessageListener messageListener
Constructor Detail

MessageAdapter

protected MessageAdapter(QDStats stats)
Method Detail

getCommonScheme

public static DataScheme getCommonScheme(QDCollector c1,
                                         QDCollector c2,
                                         QDCollector c3)
Returns common data scheme or throws IllegalArgumentException. Accepts null parameters.

Parameters:
c1 - QDCollector
c2 - QDCollector
c3 - QDCollector
Returns:
common data scheme.
Throws:
java.lang.IllegalArgumentException - if collectors have different schemes or all are null.

getSubscriptionFilterFactory

public static SubscriptionFilterFactory getSubscriptionFilterFactory(DataScheme scheme)

toString

public java.lang.String toString()
Returns description of this MessageAdapter for management and logging purposes.

Overrides:
toString in class java.lang.Object

getScheme

public abstract DataScheme getScheme()

notifyListener

protected void notifyListener()

setCloseListener

public void setCloseListener(MessageAdapter.CloseListener listener)

nextRetrieveTime

public long nextRetrieveTime(long currentTime)

getConnectionVariables

public com.devexperts.util.TypedMap getConnectionVariables()
Returns per-connection variables for this message adapter.


setConnectionVariables

public void setConnectionVariables(com.devexperts.util.TypedMap connectionVariables)
Sets per-connection variables for this message adapter. This method may be invoked only once during a life-time of MessageAdapter.


getRemoteHostAddress

protected java.lang.String getRemoteHostAddress()

useDescribeProtocol

public void useDescribeProtocol()
Invocation of this method causes this MessageAdapter to send DESCRIBE_PROTOCOL message if it is capable of doing so. It should be invoked once before calling start(). The code that calls this method shall also consult nextRetrieveTime(long).


retrieveDescribeProtocolMessage

protected long retrieveDescribeProtocolMessage(MessageVisitor visitor,
                                               long mask)

prepareProtocolDescriptor

public void prepareProtocolDescriptor(ProtocolDescriptor desc)
Prepares outgoing protocol descriptor. Implementers should call super.prepareProtocolDescriptor(desc).

Parameters:
desc - outgoing protocol descriptor

processDescribeProtocol

public void processDescribeProtocol(ProtocolDescriptor desc)
Process incoming protocol descriptor. Implementers should call super.processDescribeProtocol(desc).

Specified by:
processDescribeProtocol in interface MessageConsumer
Overrides:
processDescribeProtocol in class MessageConsumerAdapter
Parameters:
desc - incoming protocol descriptor

isProtocolDescriptorCompatible

public boolean isProtocolDescriptorCompatible(ProtocolDescriptor desc)

getStats

public QDStats getStats()

handleCorruptedStream

public void handleCorruptedStream()
Specified by:
handleCorruptedStream in interface MessageConsumer
Overrides:
handleCorruptedStream in class MessageConsumerAdapter

handleCorruptedMessage

public void handleCorruptedMessage(int messageType)
Specified by:
handleCorruptedMessage in interface MessageConsumer
Overrides:
handleCorruptedMessage in class MessageConsumerAdapter

handleUnknownMessage

public void handleUnknownMessage(int messageType)
Specified by:
handleUnknownMessage in interface MessageConsumer
Overrides:
handleUnknownMessage in class MessageConsumerAdapter

retrieveMessages

public boolean retrieveMessages(MessageVisitor visitor)
Description copied from interface: MessageProvider
Retrieves accumulated message into specified message visitor. Returns true if some messages still remains in the provider or false if all accumulated messages were retrieved.

Specified by:
retrieveMessages in interface MessageProvider

setMessageListener

public void setMessageListener(MessageListener listener)
Note: this method SHOULD be called before calling .start() - it does not give immediate notification regarding the pending messages

Specified by:
setMessageListener in interface MessageProvider

isAlive

public final boolean isAlive()
Returns true when this message adapter is alive (was started and was not closed yet).

Specified by:
isAlive in interface MessageAdapterMBean

isClosed

public final boolean isClosed()

getStatus

public final java.lang.String getStatus()

start

public final void start()
Starts this adapter. Each adapter can be started only once. Closed adapter can not be started again.


close

public final void close()
Closes this adapter. Once closed, adapter can not be started again and is useless.

Specified by:
close in interface MessageAdapterMBean

startImpl

protected void startImpl()

closeImpl

protected void closeImpl()

reportIgnoredMessage

protected void reportIgnoredMessage(MessageType message)

retrieveMask

protected final long retrieveMask()

addMask

protected final boolean addMask(long mask)
Adds bytes from argument mask to internal mask and notifies listeners if internal mask changed.

Parameters:
mask - changed bytes mask.
Returns:
true, if internal mask changed and adapter is alive.

getMessageMask

protected static long getMessageMask(MessageType message)

hasMessageMask

protected static boolean hasMessageMask(long mask,
                                        MessageType message)

clearMessageMask

protected static long clearMessageMask(long mask,
                                       MessageType message)