com.devexperts.qd.qtp
Class AgentAdapter

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

public class AgentAdapter
extends MessageAdapter

The AgentAdapter adapts agent side of QD to message API. The agent side of an QD is an aggregation of agents for all its data sources. Thus, the AgentAdapter can be used to represent an outside data consumer in the specific QD. if you are a QD publisher - use this Adapter


Nested Class Summary
static class AgentAdapter.Factory
          The factory for agent side of an QD.
 
Nested classes/interfaces inherited from class com.devexperts.qd.qtp.MessageAdapter
MessageAdapter.AbstractFactory, MessageAdapter.CloseListener
 
Field Summary
 
Fields inherited from class com.devexperts.qd.qtp.MessageAdapter
closeListener, 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
AgentAdapter(DataScheme scheme, QDStats stats)
          Creates new agent adapter for specified scheme and stats.
AgentAdapter(QDTicker ticker, QDStream stream, QDHistory history, SubscriptionFilter filter, QDStats stats)
          Creates new agent adapter for specified ticker, stream, history, filter and stats.
 
Method Summary
protected  void closeImpl()
           
protected  QDAgent createAgent(QDCollector collector, SubscriptionFilter filter, java.lang.String keyProperties)
          This method is used internally by agent adapter to create agent for the corresponding collector, filter, and keyProperties when the corresponding subscription arrives for a first time.
 DataScheme getScheme()
           
 java.lang.String getSymbol(char[] chars, int offset, int length)
          Returns symbol used for specified characters or null if not found.
 AgentAdapter initialize(ChannelShaper... shapers)
          Initializes the adapter with specified channel shapers.
 boolean isProtocolDescriptorCompatible(ProtocolDescriptor desc)
           
 long nextRetrieveTime(long currentTime)
           
 void prepareProtocolDescriptor(ProtocolDescriptor desc)
          Prepares outgoing protocol descriptor.
 void processDescribeProtocol(ProtocolDescriptor desc)
          Process incoming protocol descriptor.
protected  void processSubscription(SubscriptionIterator iterator, MessageType message)
           
protected  boolean retrieveDataMessages(MessageVisitor visitor)
           
 boolean retrieveMessages(MessageVisitor visitor)
          Retrieves accumulated message into specified message visitor.
 void updateChannel(ChannelShaper shaper)
           
protected  boolean visitData(MessageVisitor visitor, DataProvider provider, MessageType message)
           
 
Methods inherited from class com.devexperts.qd.qtp.MessageAdapter
addMask, clearMessageMask, close, getCommonScheme, getConnectionVariables, getMessageMask, getRemoteHostAddress, getStats, getStatus, getSubscriptionFilterFactory, handleCorruptedMessage, handleCorruptedStream, handleUnknownMessage, hasMessageMask, isAlive, isClosed, notifyListener, reportIgnoredMessage, retrieveDescribeProtocolMessage, retrieveMask, setCloseListener, setConnectionVariables, setMessageListener, start, startImpl, toString, useDescribeProtocol
 
Methods inherited from class com.devexperts.qd.qtp.MessageConsumerAdapter
processData, processHistoryAddSubscription, processHistoryData, processHistoryRemoveSubscription, processOtherMessage, processStreamAddSubscription, processStreamData, processStreamRemoveSubscription, processTickerAddSubscription, processTickerData, processTickerRemoveSubscription
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AgentAdapter

public AgentAdapter(QDTicker ticker,
                    QDStream stream,
                    QDHistory history,
                    SubscriptionFilter filter,
                    QDStats stats)
Creates new agent adapter for specified ticker, stream, history, filter and stats. Any of the collectors and/or filter may be null. The resulting adapter will be initiailized. It will use equal weight of 1 and no aggregation for all collectors.

Parameters:
ticker - ticker
stream - stream
history - history
filter - filter
stats - stats

AgentAdapter

public AgentAdapter(DataScheme scheme,
                    QDStats stats)
Creates new agent adapter for specified scheme and stats. Adapter created by this constructor must be initialized with shapers before being used.

Parameters:
scheme - data scheme
stats - stats
Method Detail

initialize

public AgentAdapter initialize(ChannelShaper... shapers)
Initializes the adapter with specified channel shapers. This method must be called exactly once before the adapter is used (unless the adapter is created with AgentAdapter(QDTicker, QDStream, QDHistory, SubscriptionFilter, QDStats) constructor in which case it ia allready initialized).

Parameters:
shapers - shaping configuration for adapter channels
Returns:
this agent adapter (in order to allow chained notation)

createAgent

protected QDAgent createAgent(QDCollector collector,
                              SubscriptionFilter filter,
                              java.lang.String keyProperties)
This method is used internally by agent adapter to create agent for the corresponding collector, filter, and keyProperties when the corresponding subscription arrives for a first time. This method is called while holding this adapter's lock. This implementation returns collector.createAgent(filter, keyProperties). This method may be overriden to create agent with other filter, otherwise customize the agent that is being created, or to keep track of created agents.

Parameters:
collector - collector to create agent for
filter - subscription filter for the agent
keyProperties - key properties for stats
Returns:
newly created agent

getScheme

public DataScheme getScheme()
Specified by:
getScheme in class MessageAdapter

getSymbol

public java.lang.String getSymbol(char[] chars,
                                  int offset,
                                  int length)
Description copied from class: MessageConsumerAdapter
Returns symbol used for specified characters or null if not found.

Overrides:
getSymbol in class MessageConsumerAdapter

updateChannel

public void updateChannel(ChannelShaper shaper)

processSubscription

protected void processSubscription(SubscriptionIterator iterator,
                                   MessageType message)
Overrides:
processSubscription in class MessageConsumerAdapter

closeImpl

protected void closeImpl()
Overrides:
closeImpl in class MessageAdapter

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
Overrides:
retrieveMessages in class MessageAdapter

prepareProtocolDescriptor

public void prepareProtocolDescriptor(ProtocolDescriptor desc)
Description copied from class: MessageAdapter
Prepares outgoing protocol descriptor. Implementers should call super.prepareProtocolDescriptor(desc).

Overrides:
prepareProtocolDescriptor in class MessageAdapter
Parameters:
desc - outgoing protocol descriptor

processDescribeProtocol

public void processDescribeProtocol(ProtocolDescriptor desc)
Description copied from class: MessageAdapter
Process incoming protocol descriptor. Implementers should call super.processDescribeProtocol(desc).

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

isProtocolDescriptorCompatible

public boolean isProtocolDescriptorCompatible(ProtocolDescriptor desc)
Overrides:
isProtocolDescriptorCompatible in class MessageAdapter

retrieveDataMessages

protected boolean retrieveDataMessages(MessageVisitor visitor)

nextRetrieveTime

public long nextRetrieveTime(long currentTime)
Overrides:
nextRetrieveTime in class MessageAdapter

visitData

protected boolean visitData(MessageVisitor visitor,
                            DataProvider provider,
                            MessageType message)