OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
API documentation
MessageRepository.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 #pragma once
20 
21 #include <map>
22 
23 #include <boost/function.hpp>
24 
25 #include <OnixS/HandlerCore/HandlerLogger.h>
26 #include <OnixS/HandlerCore/PacketQueue.h>
27 
31 
32 #include "NamespaceHelper.h"
33 
34 ONIXS_HANDLER_NAMESPACE_BEGIN
35 
36 class IncomingMessage;
37 
38 class ListenerHolder;
39 class OrderBookHolder;
40 class OrderBookInternal;
41 class OrderBookAllocator;
42 class OrderBookHolder;
43 class OrderBookInternal;
44 
45 class MessageRepository : public Logging::LogFacility
46 {
47 public:
49  ListenerHolder& listenerHolder,
50  const HandlerSettings& settings,
51  const Logging::LogFacility* parent,
52  HandlerCore::Common::HandlerLogger* logger,
53  OrderBookAllocator* bookAllocator);
54 
55  virtual ~MessageRepository();
56 
57  void onPacket(
58  DataSource& dataSource,
59  OnixS::HandlerCore::MarketData::FE::PacketContainer& packetContainer,
60  bool runProcessCachedMessages = true);
61 
62  void processMessage(const DataSource& dataSource, const IncomingMessage* message);
63 
64  void onGap(SequenceNumber expectedSeqNum, SequenceNumber receivedSeqNum);
65  void onInactivity();
66  void reset();
67  void resetMarketState();
68  void skipPackets(SequenceNumber seqNum1, SequenceNumber seqNum2);
69 
70  void doNotSkipGaps();
71 
72  void onSnapshotRecoveryStarted();
73  void onSnapshotRecoveryRestarted();
74 
75  /// Log helper.
76  template<typename TMsg>
77  void log (const TMsg & msg) { if(logger_) logger_->log (msg); }
78 
79  void setOrderBookIdFilter(const std::set<OrderBookId>& orderBookIdFilter);
80 
81  template <typename MessageType>
82  bool filterByInstrument(const MessageType* message, const std::set<OrderBookId>& filter);
83 
84 private:
85  template <typename MessageType>
86  const MessageType* checkDowncastMsg(const IncomingMessage* message);
87 
88  void onOrderBookUpdated(const OrderBookInternal& book);
89 
90  void checkOrderBookListener();
91  void processCachedMessages();
92 
93 private:
94  const HandlerSettings& settings_;
95  ListenerHolder& listenerHolder_;
96  const bool buildOrderBooks_;
97 
98  HandlerCore::Common::HandlerLogger* logger_;
99  SequenceNumber expectedMessageSeqNum_;
100  HandlerCore::Common::PacketQueue<DataSource> packetQueue_;
101  bool skipGaps_;
102 
103  typedef OnixS::Concurrency::RecursiveMutex Mutex;
104  typedef OnixS::Concurrency::Guard<Mutex> Guard;
105  mutable Mutex messageQueueLock_;
106 
107  boost::scoped_ptr<OrderBookHolder> orderBookHolder_;
108 
109  std::set<OrderBookId> orderBookIdFilter_;
110 
111  std::set<OrderId> marketOrderIds_;
112 };
113 
114 
115 ONIXS_HANDLER_NAMESPACE_END
UInt64 SequenceNumber
Alias for Sequence Number type.
Definition: Defines.h:37