OnixS C++ B3 Binary UMDF Market Data Handler 1.10.0
Users' manual and API documentation
Loading...
Searching...
No Matches
FeedEngine.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
20#pragma once
21
27
28#include <string>
29#include <vector>
30#include <cassert>
31
32namespace OnixS
33{
34 namespace B3
35 {
36 namespace MarketData
37 {
38 namespace UMDF
39 {
40 namespace System
41 {
43 class ONIXS_B3_UMDF_MD_API ThisThread
44 {
45 public:
47 static void affinity(const System::ThreadAffinity&);
49
50#if defined (_WIN32)
51 typedef unsigned int ThreadId;
52#else
53 typedef pthread_t ThreadId;
54#endif
55
57 };
58 }
59
62 {
63 public:
65 typedef UInt32 Flags;
66
68 explicit NetFeedEngineProcessResult(UInt32 flags) noexcept
69 {
70 value_.raw_ = flags;
71 }
72
74 bool eventsDispatched() const noexcept
75 {
76 return 0 != value_.bits_.eventsDispatched_;
77 }
78
80 void eventsDispatched(bool state) noexcept
81 {
82 value_.bits_.eventsDispatched_ = state ? 1 : 0;
83 }
84
86 bool ioWaited() const noexcept
87 {
88 return 0 != value_.bits_.ioWaited_;
89 }
90
92 void ioWaited(bool state) noexcept
93 {
94 value_.bits_.ioWaited_ = state ? 1 : 0;
95 }
96
98 Flags reserved() const noexcept
99 {
100 return value_.bits_.reserved_;
101 }
102
104 void reserved(Flags flags) noexcept
105 {
106 value_.bits_.reserved_ = flags;
107 }
108
109 private:
110 struct Bitset
111 {
112 Flags eventsDispatched_ : 1;
113 Flags ioWaited_ : 1;
114 Flags reserved_ : 30;
115 };
116
117 union Value
118 {
119 Bitset bits_;
120 Flags raw_;
121 };
122
123 Value value_;
124 };
125
127 class ONIXS_B3_UMDF_MD_API FeedEngine
128 {
129 public:
131 std::string info();
132
134 virtual ~FeedEngine();
135
136 protected:
137 explicit FeedEngine(void* impl);
138
139 protected:
140 FeedEngine(const FeedEngine&) =delete;
142
143 void* const impl_;
144 friend struct FeHelper;
145 };
146
148 class ONIXS_B3_UMDF_MD_API SocketFeedEngine : public FeedEngine
149 {
150 public:
164 const LoggerSettings& loggerSettings, UInt32 dataWaitTime = 10,
165 UInt32 socketBufferSize = 8 * 1024 * 1024, WatchService& watch = UtcWatch::service());
166
168 explicit SocketFeedEngine(UInt32 dataWaitTime = 10, UInt32 socketBufferSize = 8 * 1024 * 1024,
170
174
177 };
178
181 class ONIXS_B3_UMDF_MD_API SingleThreadedSocketFeedEngine : public FeedEngine
182 {
183 public:
188 const LoggerSettings& loggerSettings,
189 UInt32 socketBufferSize = 8 * 1024 * 1024);
190
193 explicit SingleThreadedSocketFeedEngine(UInt32 socketBufferSize = 8 * 1024 * 1024);
194
199 {
200 assert(threadId_ == System::ThisThread::threadId() && "External thread is detected.");
201 return processImpl();
202 }
203
206
207 private:
208 NetFeedEngineProcessResult processImpl();
210 };
211
215 {
216 public:
221 const LoggerSettings& loggerSettings,
222 UInt32 socketBufferSize = 8 * 1024 * 1024);
223
226 explicit SingleThreadedHardwareTimestampSocketFeedEngine(UInt32 socketBufferSize = 8 * 1024 * 1024);
227
232 {
233 assert(threadId_ == System::ThisThread::threadId() && "External thread is detected.");
234 return processImpl();
235 }
236
239
240 private:
241 NetFeedEngineProcessResult processImpl();
243 };
244
247 class ONIXS_B3_UMDF_MD_API EfViFeedEngine : public FeedEngine
248 {
249 public:
263 EfViFeedEngine(const LoggerSettings& loggerSettings,
264 UInt32 receiveRingSize = 4095, WatchService& watch = NicWatch::service());
265
267 explicit EfViFeedEngine(UInt32 receiveRingSize = 4095, WatchService& watch = NicWatch::service());
268
272
274 ~EfViFeedEngine() override;
275 };
276
283 class ONIXS_B3_UMDF_MD_API SingleThreadedEfViFeedEngine : public FeedEngine
284 {
285 public:
294 SingleThreadedEfViFeedEngine(const LoggerSettings& loggerSettings, const std::string& ifName, UInt16 memregSize = 512, UInt32 receiveRingSize = 1024);
295
303 explicit SingleThreadedEfViFeedEngine(const std::string& ifName, UInt16 memregSize = 512, UInt32 receiveRingSize = 1024);
304
310 {
311 assert(threadId_ == System::ThisThread::threadId() && "External thread is detected.");
312 return processImpl();
313 }
314
317
318 private:
319 NetFeedEngineProcessResult processImpl();
321 };
322
325 template <typename EngineT>
326 typename std::enable_if<std::is_base_of<FeedEngine, EngineT>::value, bool>::type
327 process(EngineT& engine)
328 {
329 return engine.process().eventsDispatched();
330 }
331
332 template <typename EngineT, typename... T>
333 bool process(EngineT& engine, T &&... args)
334 {
335 return process(engine) + process(args...);
336 }
337
340 {
352 };
353
356 {
358 : threadAffinity_()
359 , spinBeforeIdleTime_(1)
360 , threadCount_(1)
361 {
362 }
363
372 {
373 return threadAffinity_;
374 }
375
384 {
385 return threadAffinity_;
386 }
387
392 {
393 return threadCount_;
394 }
395
397 void threadCount(UInt32 value)
398 {
399 threadCount_ = value;
400 }
401
411 {
412 return spinBeforeIdleTime_;
413 }
414
417 {
418 spinBeforeIdleTime_ = value;
419 }
420
421 private:
422 System::ThreadAffinity threadAffinity_;
423 UInt32 spinBeforeIdleTime_;
424 UInt32 threadCount_;
425 };
426
427 class ONIXS_B3_UMDF_MD_API FeedEngineThreadPool;
428
459
461 class ONIXS_B3_UMDF_MD_API FeedEngineThreadPool
462 {
463 public:
466
468 const FeedEngineThreadPoolSettings&, const std::vector<FeedEngine*>&, FeedEngineThreadPoolListener* = nullptr);
469
471
473
474 private:
477
478 const FeedEngineThreadPoolSettings settings_;
479 class FeedEngineThreadPoolImpl;
480 FeedEngineThreadPoolImpl* const impl_;
481 };
482 }
483 }
484 }
485}
EfViFeedEngine(const LoggerSettings &loggerSettings, UInt32 receiveRingSize=4095, WatchService &watch=NicWatch::service())
Constructor.
NetFeedEngineProcessResult process()
Carries out pending actions like data retrieval and event dispatching.
EfViFeedEngine(UInt32 receiveRingSize=4095, WatchService &watch=NicWatch::service())
A pool of threads executing feed engine tasks.
Definition FeedEngine.h:462
FeedEngineThreadPool(const FeedEngineThreadPoolSettings &, const std::vector< FeedEngine * > &, FeedEngineThreadPoolListener *=nullptr)
const FeedEngineThreadPoolSettings & settings() const
FeedEngineThreadPool(const FeedEngineThreadPoolSettings &, FeedEngine *, FeedEngineThreadPoolListener *=nullptr)
The Feed Engine machinery.
Definition FeedEngine.h:128
FeedEngine & operator=(const FeedEngine &)=delete
std::string info()
Provides information about the actual implementation of the feed engine.
FeedEngine(const FeedEngine &)=delete
Designed to reflect various aspects of feed engine processing flow.
Definition FeedEngine.h:62
void reserved(Flags flags) noexcept
Reserved (unused) flags.
Definition FeedEngine.h:104
void ioWaited(bool state) noexcept
Indicates whether processing had to sleep in kernel while checking data availability.
Definition FeedEngine.h:92
Flags reserved() const noexcept
Reserved (unused) flags.
Definition FeedEngine.h:98
bool ioWaited() const noexcept
Indicates whether processing had to sleep in kernel while checking data availability.
Definition FeedEngine.h:86
bool eventsDispatched() const noexcept
Indicates whether feed-related events like data reception or absence have been dispatched.
Definition FeedEngine.h:74
void eventsDispatched(bool state) noexcept
Indicates whether feed-related events like data reception or absence have been dispatched.
Definition FeedEngine.h:80
UInt32 Flags
Aliases integral type whose bits are used to indicate flag presence.
Definition FeedEngine.h:65
static NicWatch & service()
Returns watch service.
SingleThreadedEfViFeedEngine(const LoggerSettings &loggerSettings, const std::string &ifName, UInt16 memregSize=512, UInt32 receiveRingSize=1024)
Constructor.
SingleThreadedEfViFeedEngine(const std::string &ifName, UInt16 memregSize=512, UInt32 receiveRingSize=1024)
Constructor.
NetFeedEngineProcessResult process()
Carries out pending actions like data retrieval and event dispatching.
Definition FeedEngine.h:309
SingleThreadedHardwareTimestampSocketFeedEngine(const LoggerSettings &loggerSettings, UInt32 socketBufferSize=8 *1024 *1024)
Constructor.
SingleThreadedHardwareTimestampSocketFeedEngine(UInt32 socketBufferSize=8 *1024 *1024)
NetFeedEngineProcessResult process()
Carries out pending actions like data retrieval and event dispatching.
Definition FeedEngine.h:231
SingleThreadedSocketFeedEngine(UInt32 socketBufferSize=8 *1024 *1024)
NetFeedEngineProcessResult process()
Carries out pending actions like data retrieval and event dispatching.
Definition FeedEngine.h:198
SingleThreadedSocketFeedEngine(const LoggerSettings &loggerSettings, UInt32 socketBufferSize=8 *1024 *1024)
Constructor.
SocketFeedEngine(const LoggerSettings &loggerSettings, UInt32 dataWaitTime=10, UInt32 socketBufferSize=8 *1024 *1024, WatchService &watch=UtcWatch::service())
Constructor.
NetFeedEngineProcessResult process()
Carries out pending actions like data retrieval and event dispatching.
SocketFeedEngine(UInt32 dataWaitTime=10, UInt32 socketBufferSize=8 *1024 *1024, WatchService &watch=UtcWatch::service())
static void affinity(const System::ThreadAffinity &)
Sets the processor affinity mask for the current thread.
static void affinity(System::CpuIndex)
static UtcWatch & service()
Returns watch service.
size_t CpuIndex
Zero-based index of CPU.
Definition Defines.h:97
Messaging::UInt16 UInt16
Definition Integral.h:34
Messaging::UInt32 UInt32
Definition Integral.h:37
std::enable_if< std::is_base_of< FeedEngine, EngineT >::value, bool >::type process(EngineT &engine)
Carries out pending actions like data retrieval and event dispatching.
Definition FeedEngine.h:327
Identifies reasons feed engine threads becomes idle.
Definition FeedEngine.h:340
@ DataWaitTimeout
Thread waited for incoming data using corresponding I/O operations (like 'select') and exited waiting...
Definition FeedEngine.h:346
@ Redundant
Thread entered idle state due to absence of any data and while other threads are waiting for new inco...
Definition FeedEngine.h:350
virtual void onFeedEngineThreadBegin(const FeedEngineThreadPool &)
Member invoked by feed engine when a new processing thread is spawned.
Definition FeedEngine.h:441
virtual void onFeedEngineThreadIdle(const FeedEngineThreadPool &, FeedEngineThreadIdle::Reason, UInt32 &)
Is called when feed engine's thread is idle.
Definition FeedEngine.h:454
virtual void onFeedEngineThreadEnd(const FeedEngineThreadPool &)
Member is invoked by feed engine when processing thread is about to end.
Definition FeedEngine.h:448
Settings for a thread pool executing feed engine tasks.
Definition FeedEngine.h:356
void threadCount(UInt32 value)
Sets threadsCount.
Definition FeedEngine.h:397
UInt32 spinBeforeIdleTime() const
Defines amount of time Feed Engine keeps cycling before going to sleep when no useful activity can be...
Definition FeedEngine.h:410
System::ThreadAffinity & threadAffinity()
Defines set of CPUs allowed for each working thread to be executed on while processing market data by...
Definition FeedEngine.h:383
void spinBeforeIdleTime(UInt32 value)
Sets redundancySpinTime.
Definition FeedEngine.h:416
const System::ThreadAffinity & threadAffinity() const
Defines set of CPUs allowed for each working thread to be executed on while processing market data by...
Definition FeedEngine.h:371
UInt32 threadCount() const
Number of working threads to be used by feed engine.
Definition FeedEngine.h:391