multithreading-kata
concurrency
java8
Order events(Transaction)
Transaction Id | Order Id | Version Id | Symbol | Quantity | Operation | Buy/Sell |
---|---|---|---|---|---|---|
1 | 1 | 1 | ABC | 100 | INSERT | BUY |
2 | 2 | 2 | XYZ | 10 | UPDATE | SELL |
3 | 2 | 1 | XYZ | 10 | INSERT | SELL |
4 | 1 | 3 | ABC | 10 | CANCEL | BUY |
Process transaction(example given above) obeying following rules in a multithreaded environment
- First version of order would always be INSERT
- Last version of order would always be CANCEL
- Order versions may come in any order
- Process them in sequential order version 1,2,3....
- Final position of every symbol will be calculated by difference between BUY and SELL units, CANCEL will mark order units 0
- UPDATE operation may update the symbol, units, buy/sell
Output of the above example
Symbol | Units |
---|---|
XYZ | -10 |
ABC | 0 |