`
guibin
  • 浏览: 366223 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

AioTrade Investigation (Section A: DataServer)

阅读更多
AioTrade Investigation (Section A: DataServer)
guibin.beijing@gmail.com
AioTrade source code: https://github.com/dcaoyuan/aiotrade

Note: The DataServer we are talking about is just org.aiotrade.lib.math.timeseries.DataServer, and the source code can be found at https://github.com/dcaoyuan/aiotrade/tree/master/libs/lib.math/src/main/scala/org/aiotrade/lib/math/timeseries/datasource/DataServer.scala

DataServer's responsibility is to load the quote data from some data source, and do the processing logic via processData. The old version DataServer could save the data in its storage quotes, but now it doesn't.

This DataServer also records the contract who subscribe this DataServer, and records the symbol to contract mapping. One DataServer could act as the data source for several uniSymbols. According to the design, each security could have its own data server, different security could have different data server.

1. object DataServer
This object DataServer just publish the heart beat to drive the workflow in class DataServer. The heart beat is implemented by the simple timer.

2. Workflow of class DataServer
e: event; a: action.
e: HeartBeat(interval) -> e: AskLoadData(loadedTime, subscribedContracts) -> a: requestData(afterTime, contracts) -> e: DataLoaded(values: Array[V], contract) -> a: processData(values, contract.asInstanceOf[C]) -> e: DataProcessed

3. Explanation for the workflow
The object DataServer fires the heart beat periodically, class DataServer should listen to this object DataServer. When receives the heart beat, class DataServer will judge whether it should react to this. If it is refreshable and is not loading data at that moment, it will react to publish the AskLoadData event to drive the requestData action.
In the requestData action, class DataServer should request the data from the itself's data source, such as database, dbf, yahoo's web service etc.
When finishes requesting data, it should publish the event DataLoaded to drive the processData. The logic in the processData can be merging the tickers into time serieses.
After processing data, class DataServer will publish the event DataProcessed to notify its finishing processing data.

4. Other functions in class DataServer
Class DataServer has a method named protected def publishData(msg: Any), by default, it will publish msg to local reactor. If necessary, we can override this function to publish the msg to remote reactor via AMQP etc.
The methods startRefresh and stopRefresh can be use to enable or disable the heart beat to let the workflow work or not.

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics