public class SimpleAsyncProcessor extends Module implements DataEmitter, DataReceiver, DynamicMBean
For each data flow this module is participating in, the module adds every received data item into a queue. Hence the emitter module from which this module is receiving data is not blocked when delivering data. The module creates a separate thread for the data flow that removes the data items from this queue and delivers it to the next receiver module in the data flow.
Do note that the if the module that is receiving data emitted by this module is not able to keep up with the module that is emittin data into this module, the data items will keep on accumulating in the queue. If this condition continues on for a while, this may lead to JVM running out of memory. When using this module, be sure to size the heap of the process to ensure that the process does not run out of memory, when there's a disparity in the data emit rate and data receive rate of the modules before and after this module in the data flow.
The module exposes an DynamicMBean interface to monitor the current
queue sizes for every flow. The MBean offers list of attributes,
one per data flow, that it is participating in.
Each attribute has name of the form "Flowdata_flow_id"
where data_flow_id is the flowID of the data flow that the attribute
represents. The value of the attribute is the current size of the queue
for that data flow. The attribute value can be monitored to observe if
the module receiving data from this module is able to keep up with the
module emitting data into this module in the data flow represented by the
attribute.
Note that when the data flow is canceled, the module does not wait for the all the data in the queue to be delivered, it interrupts the delivery thread right away and allows the flow to be canceled.
Note that this module is not designed such that the same instance can be used more than once in a single data flow. If you need to use this module more than once in the same data flow make sure that you use different instances of this module in the flow such that the same instance doesn't appear more than once in the same data flow.
This module is meant to be used as an intermediate module between two modules in a data flow. Although this module can be used as the first or the last module in a data flow, the features provided by this module offer little merit in such a scenario.
Usage:
The following strategy agent command demonstrates how this module can be inserted between two modules to decouple the data flow between them.
# Start the bogus feed module startModule;metc:mdata:bogus:single # Create data flow createDataFlow;metc:mdata:bogus;single:symbols=AAPL:content=latest_tick,top_of_book^metc:async:simple:myinstanceThe command above will create a data flow where the market data events from the bogus feed are fed into the simple async module. The async module adds all the received market data events to the queue and has a separate thread that removes them from the queue and delivers them to the sink module. Since the market data events are always added to the queue, market data delivery is very fast and the market data delivery thread is not blocked while the sink module processes the event (for example, logs it).
Module Features
| Capabilities | Data Emitter, Data Reciever |
|---|---|
| DataFlow Request Parameters | None. |
| Stops data flows | No. |
| Start Operation | Initializes the thread pool for emitting data. |
| Stop Operation | Shuts down the thread pool. |
| Management Interface | dynamic: see above |
| Factory | SimpleAsyncProcessorFactory |
| Modifier | Constructor and Description |
|---|---|
protected |
SimpleAsyncProcessor(ModuleURN inURN)
Creates an instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(DataFlowID inFlowID,
RequestID inRequestID) |
Object |
getAttribute(String attribute) |
AttributeList |
getAttributes(String[] attributes) |
MBeanInfo |
getMBeanInfo() |
Object |
invoke(String actionName,
Object[] params,
String[] signature) |
protected void |
preStart() |
protected void |
preStop() |
void |
receiveData(DataFlowID inFlowID,
Object inData) |
void |
requestData(DataRequest inRequest,
DataEmitterSupport inSupport) |
void |
setAttribute(Attribute attribute) |
AttributeList |
setAttributes(AttributeList attributes) |
getCreated, getLastStartFailure, getLastStopFailure, getStarted, getState, getStopped, getURN, isAutoCreated, isAutoStartprotected SimpleAsyncProcessor(ModuleURN inURN)
inURN - the module's instance URN.public void requestData(DataRequest inRequest, DataEmitterSupport inSupport) throws IllegalRequestParameterValue
requestData in interface DataEmitterIllegalRequestParameterValuepublic void cancel(DataFlowID inFlowID, RequestID inRequestID)
cancel in interface DataEmitterpublic void receiveData(DataFlowID inFlowID, Object inData)
receiveData in interface DataReceiverpublic Object getAttribute(String attribute) throws AttributeNotFoundException
getAttribute in interface DynamicMBeanAttributeNotFoundExceptionpublic void setAttribute(Attribute attribute) throws AttributeNotFoundException
setAttribute in interface DynamicMBeanAttributeNotFoundExceptionpublic AttributeList getAttributes(String[] attributes)
getAttributes in interface DynamicMBeanpublic AttributeList setAttributes(AttributeList attributes)
setAttributes in interface DynamicMBeanpublic Object invoke(String actionName, Object[] params, String[] signature) throws ReflectionException
invoke in interface DynamicMBeanReflectionExceptionpublic MBeanInfo getMBeanInfo()
getMBeanInfo in interface DynamicMBeanCopyright © 2017. All Rights Reserved.