OnixS C++ CME Market Data Handler  5.4.0
API documentation
SocketFeedEngine.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <OnixS/CME/MDH/Watch.h>
26 
28 
29 /// Represents a collection of settings affecting
30 /// the behavior of the multi-threaded feed engine
31 /// while working with network-related services.
34 {
35  PacketSize packetMaxSize_;
36  WatchService* watch_;
37 
38  UInt32 socketBufferSize_;
39  UInt32 dataWaitTime_;
40 
41 public:
42  /// Initializes the given instance of the
43  /// network settings with the default values.
45  : packetMaxSize_(1420)
46  , watch_(&UtcWatch::service())
47  , socketBufferSize_(8 * 1024 * 1024)
48  , dataWaitTime_(10)
49  {
50  }
51 
52  /// Cleans everything up.
54  {
55  }
56 
57  /// Max size for network packet transmitted by MDP.
58  ///
59  /// @note Default value is '1420'.
61  {
62  return packetMaxSize_;
63  }
64 
65  /// Max size for network packet transmitted by MDP.
66  void
69  {
70  packetMaxSize_ = value;
71  }
72 
73  /// Watch service to be used by Feed Engine.
74  ///
75  /// Watch is used by Feed Engine to assign time
76  /// points to packets received from the feeds.
77  ///
78  /// @note By default, UTC watch service is used.
80  {
81  return *watch_;
82  }
83 
84  /// Watch service to be used by Feed Engine.
85  ///
86  /// If no instance associated, UTC watch is used.
87  void
89  WatchService& watch)
90  {
91  watch_ = &watch;
92  }
93 
94  /// Defines size of receiving buffer in bytes for sockets.
95  ///
96  /// @note Default value is 8 MiB.
97  UInt32
99  {
100  return socketBufferSize_;
101  }
102 
103  /// Sets socketBufferSize. @see socketBufferSize.
104  void
106  UInt32 value)
107  {
108  socketBufferSize_ = value;
109  }
110 
111  /// Defines amount of time Feed Engine spends on socket
112  /// waiting for I/O while running master processing loop.
113  ///
114  /// Time is measured in milliseconds.
115  ///
116  /// @note Default value is '10'.
117  ///
118  /// @warning The given parameter significantly affects
119  /// responsiveness of the Handler and load onto CPU.
120  UInt32
121  dataWaitTime() const
122  {
123  return dataWaitTime_;
124  }
125 
126  /// Sets dataWaitTime. @see dataWaitTime.
127  void
129  UInt32 value)
130  {
131  dataWaitTime_ = value;
132  }
133 };
134 
135 /// Serializes feed engine settings into a string.
136 ONIXS_CMEMDH_EXPORTED
137 void
138 toStr(
139  std::string&,
140  const
142 
143 /// Serializes feed engine settings into a string.
144 inline
145 std::string
147  const
148  SocketFeedEngineSettings& settings)
149 {
150  std::string str;
151 
152  toStr(str, settings);
153 
154  return str;
155 }
156 
157 /// The given class implements feed engine concept
158 /// using pool of working threads and standard socket
159 /// API.
162 {
163  // The workhorse for the multi-threaded
164  // feed engine based on the standard socket
165  // API and a pool of threads.
166  class Workhorse;
167 
168  Workhorse* workhorse_;
169 
170 public:
171  /// Initializes the engine according to the given configuration.
173  const SocketFeedEngineSettings&);
174 
175  /// Destructs the given instance.
176  ~SocketFeedEngine();
177 
178  /// Appends information on the given
179  /// implementation to the given string.
180  void
181  info(
182  std::string&);
183 
184  /// Allocates a link for the given feed.
185  NetFeedLink&
186  allocate(
187  const NetFeed&);
188 
189  /// Exposes a watch service used
190  /// while manipulating the feed links.
191  WatchService&
192  watch();
193 
194  /// Carries out pending actions like
195  /// data retrival and event dispatching.
196  ///
197  /// The returned value indicates whether any
198  /// events have been handled by the engine.
199  virtual
201  process();
202 };
203 
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
std::string toStr(const SocketFeedEngineSettings &settings)
Serializes feed engine settings into a string.
void dataWaitTime(UInt32 value)
Sets dataWaitTime.
UInt32 UInt32
uInt32.
Definition: Fields.h:247
void socketBufferSize(UInt32 value)
Sets socketBufferSize.
Abstract watch service.
Definition: Watch.h:29
void packetMaxSize(PacketSize value)
Max size for network packet transmitted by MDP.
bool process(NetFeedEngine &engine)
Definition: FeedEngine.h:183
bool value(Number &number, const MultiContainer &container, Tag tag)
Base attributes of market data feed.
Definition: Feed.h:60
#define ONIXS_CMEMDH_EXPORTED_CLASS
Definition: Bootstrap.h:54
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
~SocketFeedEngineSettings()
Cleans everything up.
UInt16 PacketSize
Integral type for measuring packets.
Definition: PacketTraits.h:36
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156