DataServer of AIOTrade
程皓轩
2023-12-01
1. How to compare two DataServers?
If the Dataservers' displayNames are same and they have the same hashCode, then they are equal.
2. What the contract for this Dataserver?
3. What is the DataServer's core data structure?
There are three main data Map and a helper Map, the details are:
a) contractToStorage: Map[C, ArrayList[V]], DataContract -> Storage
b) subscribedContractToSer: Map[C, T], DataContract -> Tser
c) serToChainSers: Map[Tser, List[Tser]], Tser -> ChainSers
The helper Map is:
a) subscribedSymbolToContract: Map[String, DataContract]
It is used to quick search the contract, then to get the Storage or the Tser
All the method and logic are used to support these four Map.
4. What the event will the DataServer publish?
Totally two kinds of event,
the first one is HeartBeat(heartBeatInterval), it is published by a timer in the DataServer every `heartBeatInteval`. The default action when the DataServer received the HeartBeat is to loadFromSource(loadedTime) and postRefresh
loadFromSource will be overrided by the subclass.
The second kind of event is LoadHistory(afterTime). The default action when DataServer received the LoadHistory(afterTime) is also to loadFromSource(loadedTime) and postLoadHistory.
5. What does the postRefresh and postLoadHistory do?
Currently in the TickerServer, the postRefresh will firstly composeSer, then publish TSerEvent.Updated to the Tser. Tser also is a kind of publisher, TODO here.
6. What does the composeSer do?
composeSer will [b]compose[/b] the ticker(new ticker copied from the tickerSnapshot) in the subscribedContracts's storage [b]to Tser, that is to say the 1m quoteSer[/b]
7. What event will the TickerServer observer?
TickerServer extends DataServer, that is to say Ticker is a Publisher which will publish the HeartBeat(heartBeatInterval) and LoadHistory(afterTime) event to [b]itself[/b].
TickerServer is a publisher and is also a Reactor, so it will listen to the Exchange.
Exchange will publish Opened(exchange: Exchange) and Closed(exchange: Exchange). [b]TickerServer has not define the action when it received the Opened and Closed event.[/b]
TickerServer also implements the traits ChangeObserver, so it will observe the tickerSnapshot. [b]When the tickerSnapshot notifies, the default action is TickerServer will create a new Ticker, copy the tickerSnapshot content to the new ticker, then save this new ticker into the storage(actually a ArrayList) of the DataServer.[/b] The tickerSnapshot is the latest tickerSnapshot, which means that it is always changing.
[I]Question: how to track the new tickerSnapshot, observe it and unobserve it?[/I]
Ticker will subscribe a tickerContract, then it observe the tickerSnapshot <- Sec.lastData <- contract.symbol <- contract.
And unsubscribe is vice verse. contract -> contract.symbol -> Sec -> sec.lastData.tickerSnapShot.