OnixS C++ CME MDP Premium Market Data Handler  5.8.9
API Documentation
Replay.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 <string>
24 #include <vector>
25 #include <map>
26 #include <functional>
27 
28 #include <OnixS/CME/MDH/Integral.h>
29 #include <OnixS/CME/MDH/Time.h>
30 
31 #include <OnixS/CME/MDH/Domain.h>
35 
37 
38 // A bit of forward declarations.
40 
41 /// Ordered list of logs to be replayed.
42 typedef std::vector<std::string> FileList;
43 
44 /// Gathers log files logs which are available for
45 /// given channel and are stored in a given folder.
46 /// Gathering assumes log files are named by log file
47 /// naming routine exposed by given SDK.
49 void gatherLogFiles(FileList&, ChannelId, const std::string&);
50 
51 /// Gathers log files logs which are available for
52 /// given channel and are stored in a given folder.
53 /// Gathering assumes log files are named by log file
54 /// naming routine exposed by given SDK. In contrast
55 /// to other overloads, given one allows to define
56 /// prefix pattern for logs to be gathered.
58 void gatherLogFiles(FileList&, ChannelId, const std::string&, const std::string&);
59 
60 /// Gathers files which are stored in the given folder with
61 /// the given extension. Gathered files are sorted by name.
62 ///
63 /// In contrast to the gatherLogFiles function gathering log
64 /// files, which collects log files in exact order the files
65 /// were produced by a logger, the given one represents a generic
66 /// routine finding files according to the given pattern (extension).
68 void gatherFiles(FileList&, const std::string&, const std::string&);
69 
70 #if !defined(ONIXS_CMEMDH_NO_DEPRECATED)
71 
72 /// Gathers files which are stored in the given folder with
73 /// the given extension. Gathered files are sorted by name.
74 ///
75 /// \warning The given function is deprecated.
76 /// Consider using `gatherFiles` instead.
77 inline void gatherPcapFiles(FileList& files, const std::string& location, const std::string& ext)
78 {
79  gatherFiles(files, location, ext);
80 }
81 
82 #endif // !ONIXS_CMEMDH_NO_DEPRECATED
83 
84 /// Defines whether processing and other settings
85 /// must be extracted from logs and used during the
86 /// replay, or the original settings as they were
87 /// defined by replay invoker must be used.
89 {
90  enum Enum
91  {
92  /// Handler settings aren't touched and
93  /// used as they are during the replay.
95 
96  /// Settings affecting the way the data
97  /// is processed must be extracted from
98  /// the logs and applied to the Handlers
99  /// before replay starts.
100  Suggested
101  };
102 };
103 
104 /// Defines range of log entries to be replayed.
106 {
107 public:
108  /// Initializes empty span.
110  : begin_()
111  , end_()
112  {
113  }
114 
115  /// Initializes the instance
116  /// according to the given bounds.
117  ReplaySpan(const Timestamp& begin, const Timestamp& end)
118  : begin_(begin)
119  , end_(end)
120  {
121  }
122 
123  /// Initializes the instance
124  /// as a copy of the other one.
125  ReplaySpan(const ReplaySpan& other)
126  : begin_(other.begin_)
127  , end_(other.end_)
128  {
129  }
130 
131  /// Indicates whether span is empty or not.
132  bool empty() const
133  {
134  return (begin_ >= end_);
135  }
136 
137  /// Indicates whether the given timestamp
138  /// belongs to the given time span.
139  bool contain(const Timestamp& timestamp) const
140  {
141  return (begin_ <= timestamp && timestamp < end_);
142  }
143 
144  /// Indicates the beginning of the range.
145  const Timestamp& begin() const
146  {
147  return begin_;
148  }
149 
150  /// Updates the beginning of the range.
151  void begin(const Timestamp& value)
152  {
153  begin_ = value;
154  }
155 
156  /// Indicates the end of the range.
157  const Timestamp& end() const
158  {
159  return end_;
160  }
161 
162  /// Indicates the end of the range.
163  void end(const Timestamp& value)
164  {
165  end_ = value;
166  }
167 
168  /// Re-initializes as a copy of the other one.
170  {
171  begin_ = other.begin_;
172  end_ = other.end_;
173 
174  return *this;
175  }
176 
177 private:
178  Timestamp begin_;
179  Timestamp end_;
180 };
181 
182 /// Controls speed of market data replay.
184 {
185  /// Controls speed of market data replay.
186  enum Enum
187  {
188  /// Replays run at maximal speed.
189  NoDelay = 0,
190 
191  /// Data is replayed with the original speed.
192  Original = 1,
193 
194  /// Data is replayed two times faster in
195  /// compare to the original speed at which
196  /// the Handler was receiving that data.
197  X2 = 2
198  };
199 };
200 
201 /// Controls the replay delay.
203 {
204  /// Implements the delay between packets.
205  virtual void onDelay(const TimeSpan& delay) = 0;
206 };
207 
208 /// Implements the replay delay using the `sleep` system call.
210 {
211  /// Implements the delay between packets.
212  void onDelay(const TimeSpan& delay) ONIXS_CMEMDH_OVERRIDE;
213 
214  /// Returns the instance reference.
215  static ReplayDelayer& service();
216 };
217 
218 /// Implements the replay delay by polling in the userspace
220 {
221  /// Implements the delay between packets.
222  void onDelay(const TimeSpan& delay) ONIXS_CMEMDH_OVERRIDE;
223 
224  /// Returns the instance reference.
225  static ReplayDelayer& service();
226 };
227 
228 /// Various supplemental settings affecting
229 /// the way the logged data is replayed.
230 template <class DataSource, class DataSourceLess = std::less<DataSource> >
232 {
233 public:
234  /// The table of data source aliases.
235  typedef std::map<DataSource, DataSource, DataSourceLess> Aliases;
236 
237  /// Initializes the settings with the default values.
239  : delayer_(&SleepReplayDelayer::service())
240  , settingsUse_(HandlerSettingsUse::Suggested)
241  , aliases_()
242  , timeSpan_()
243  , speed_(ReplaySpeed::NoDelay)
244  {
245  }
246 
247  /// Initializes as a copy of the other one.
249  : delayer_(other.delayer_)
250  , settingsUse_(other.settingsUse_)
251  , aliases_(other.aliases_)
252  , timeSpan_(other.timeSpan_)
253  , speed_(other.speed_)
254  {
255  }
256 
257  /// Handler settings use policy.
259  {
260  return settingsUse_;
261  }
262 
263  /// Defines handler settings use policy.
265  {
266  settingsUse_ = policy;
267  }
268 
269  /// Aliases to be used during the replay.
270  ///
271  /// Aliases allow redirecting data from one source
272  /// (feed, multicast group, channel, etc.) to the other
273  /// one.
274  const Aliases& aliases() const
275  {
276  return aliases_;
277  }
278 
279  /// Aliases to be used during the replay.
280  ///
281  /// Aliases allow redirecting data from one source
282  /// (feed, multicast group, channel, etc.) to the other
283  /// one.
284  Aliases& aliases()
285  {
286  return aliases_;
287  }
288 
289  /// Time span for which entries are to be processed.
290  const ReplaySpan& timeSpan() const
291  {
292  return timeSpan_;
293  }
294 
295  /// Time span for which entries are to be processed.
297  {
298  return timeSpan_;
299  }
300 
301  /// Indicates processing speed policy.
303  {
304  return speed_;
305  }
306 
307  /// Defines processing speed.
309  {
310  speed_ = policy;
311  }
312 
313  /// Sets a policy for implementing replay delay.
314  void delayPolicy(ReplayDelayer& delayer)
315  {
316  delayer_ = &delayer;
317  }
318 
319  /// Indicates policy for implementing replay delay.
321  {
322  assert(delayer_);
323  return *delayer_;
324  }
325 
326  /// Re-initializes as a copy of the other one.
328  {
329  delayer_ = other.delayer_;
330 
331  settingsUse_ = other.settingsUse_;
332 
333  aliases_ = other.aliases_;
334 
335  timeSpan_ = other.timeSpan_;
336 
337  speed_ = other.speed_;
338 
339  return *this;
340  }
341 
342 private:
343  ReplayDelayer* delayer_;
344  HandlerSettingsUse::Enum settingsUse_;
345  Aliases aliases_;
346 
347  ReplaySpan timeSpan_;
348  ReplaySpeed::Enum speed_;
349 };
350 
351 /// Replay supplements for log replay functionality.
353 
354 /// Collection of logged data sources (feed
355 /// identifiers) to be used by the Log Replay
356 /// to replace logged sources with the sources
357 /// used by Handlers involved into replay.
359 
360 /// Replay supplements for the PCAP replay functionality.
361 class ONIXS_CMEMDH_LTWT PcapReplaySettings : public ReplaySettings<NetFeedConnection, NetFeedConnectionLess>
362 {
363 public:
364  /// Initializes settings with the default values.
366  {
367  settingsUse(HandlerSettingsUse::AsIs);
368  }
369 
370  /// Settings aren't stored in PCAPs
371  /// thus constant value is returned.
373  {
374  return HandlerSettingsUse::AsIs;
375  }
376 
377 private:
379 
380  // Not applicable for the PCAP replay as no
381  // parameters are stored in the captured files.
382  using Base::settingsUse;
383 };
384 
385 /// Collection of data sources (feed identifiers)
386 /// to be used by the PCAP file replay to replace
387 /// captured sources with the sources used by Handlers
388 /// involved into replay.
390 
391 /// Replay supplements for the CME DataMine
392 /// historical data replay functionality.
394 {
395 public:
396  /// Initializes settings with the default values.
398  {
399  settingsUse(HandlerSettingsUse::AsIs);
400  }
401 
402  /// Settings aren't stored in Datamine
403  /// thus constant value is returned.
405  {
406  return HandlerSettingsUse::AsIs;
407  }
408 
409 private:
411 
412  // Not applicable for the Datamine replay as no
413  // parameters are stored in the captured files.
414  using Base::settingsUse;
415 };
416 
417 /// Collection of channels to be used by the CME Datamine
418 /// historical file replay to replace captured sources
419 /// with the sources used by Handlers involved into replay.
421 
422 /// Extracts market data stored in the given
423 /// log files and pushes it to the given handlers
424 /// for further processing.
426 void replayLogFiles(const FileList&, Handler**, size_t, const LogReplaySettings&);
427 
428 /// Extracts market data stored in the given
429 /// log files and pushes it to the given handler
430 /// for further processing.
431 inline void replayLogFiles(const FileList& logs, Handler& handler, const LogReplaySettings& supplements)
432 {
433  Handler* handlers[] = {&handler};
434 
435  replayLogFiles(logs, handlers, 1, supplements);
436 }
437 
438 /// Processes market data stored in the log
439 /// files according to specified settings.
440 inline void replayLogFiles(const FileList& logs, Handler** handlers, size_t handlerQty)
441 {
442  replayLogFiles(logs, handlers, handlerQty, LogReplaySettings());
443 }
444 
445 /// Processes market data stored in the log
446 /// files according to specified settings.
447 inline void replayLogFiles(const FileList& logs, Handler& handler)
448 {
449  Handler* handlers[] = {&handler};
450 
451  replayLogFiles(logs, handlers, 1);
452 }
453 
454 /// A Marker instructing the log replay procedure to
455 /// use Handler settings as they are without applying
456 /// any modifications based on logged information.
458 {};
459 
460 /// Processes market data stored in the log
461 /// files according to specified settings.
462 inline void replayLogFiles(const FileList& logs, Handler** handlers, size_t handlerQty, const UseHandlerSettingsAsIs&)
463 {
464  LogReplaySettings supplements;
465 
466  supplements.settingsUse(HandlerSettingsUse::AsIs);
467 
468  replayLogFiles(logs, handlers, handlerQty, supplements);
469 }
470 
471 /// Processes market data stored in the log
472 /// files according to specified settings.
473 inline void replayLogFiles(const FileList& logs, Handler& handler, const UseHandlerSettingsAsIs& marker)
474 {
475  Handler* handlers[] = {&handler};
476 
477  replayLogFiles(logs, handlers, 1, marker);
478 }
479 
480 /// Replays the given list of PCAP files for the
481 /// given Handlers according to the given settings.
483 void replayPcapFiles(const FileList&, Handler**, size_t, const PcapReplaySettings&);
484 
485 /// Applies the given list of PCAP files with snapshots then
486 /// replays the given list of PCAP files with incrementals for the
487 /// given Handlers according to the given settings.
488 /// @note snapshots are being applied with no delay
489 /// @note only the first snapshot cycle from the given snapshots is applied, the rest are skipped
491 void replayPcapFiles(
492  const FileList& snapshots,
493  MarketRecoveryOptions::Enum snapshotsApplyOptions,
494  const FileList& incrementals,
495  Handler** handlers,
496  size_t handlerQty,
497  const PcapReplaySettings& supplements
498 );
499 
500 /// Applies the given list of PCAP files with snapshots then
501 /// replays the given list of PCAP files with incrementals for the
502 /// given Handler according to the given settings.
503 /// @note snapshots are being applied with no delay
504 /// @note only the first snapshot cycle from the given snapshots is applied, the rest are skipped
505 inline void replayPcapFiles(
506  const FileList& snapshots,
507  MarketRecoveryOptions::Enum snapshotsApplyOptions,
508  const FileList& incrementals,
509  Handler& handler,
510  const PcapReplaySettings& supplements = PcapReplaySettings()
511 )
512 {
513  Handler* handlers[] = {&handler};
514 
515  replayPcapFiles(snapshots, snapshotsApplyOptions, incrementals, handlers, 1, supplements);
516 }
517 
518 /// Replays the given list of PCAP files for the
519 /// given Handler according to the given settings.
520 inline void replayPcapFiles(const FileList& logs, Handler& handler, const PcapReplaySettings& supplements)
521 {
522  Handler* handlers[] = {&handler};
523 
524  replayPcapFiles(logs, handlers, 1, supplements);
525 }
526 
527 /// Replays the given list of PCAP files for the
528 /// given Handler according to the default settings.
529 inline void replayPcapFiles(const FileList& logs, Handler& handler)
530 {
531  replayPcapFiles(logs, handler, PcapReplaySettings());
532 }
533 
534 /// Merges the given Datamine files into a single one. The output file is gzipped.
536 void mergeDatamineFiles(const FileList& inFileNames, std::string outFileName, const ReplaySpan& timeSpan = ReplaySpan());
537 
538 /// Replays the given list of Datamine files for the
539 /// given Handlers according to the given settings.
541 void replayDatamineFiles(const FileList&, Handler**, size_t, const DatamineReplaySettings&);
542 
543 /// Replays the given list of Datamine files for the
544 /// given Handlers according to the given settings.
545 inline void replayDatamineFiles(const FileList& logs, Handler& handler, const DatamineReplaySettings& supplements)
546 {
547  Handler* handlers[] = {&handler};
548 
549  replayDatamineFiles(logs, handlers, 1, supplements);
550 }
551 
552 /// Replays the given list of historical data for the
553 /// given Handler according to the default settings.
554 inline void replayDatamineFiles(const FileList& logs, Handler& handler)
555 {
557 }
558 
Defines range of log entries to be replayed.
Definition: Replay.h:105
ReplaySpan(const ReplaySpan &other)
Initializes the instance as a copy of the other one.
Definition: Replay.h:125
#define ONIXS_CMEMDH_OVERRIDE
Definition: Compiler.h:165
Handler settings aren&#39;t touched and used as they are during the replay.
Definition: Replay.h:94
Replay supplements for the CME DataMine historical data replay functionality.
Definition: Replay.h:393
Replay supplements for the PCAP replay functionality.
Definition: Replay.h:361
std::vector< std::string > FileList
Ordered list of logs to be replayed.
Definition: Replay.h:39
Encapsulates all the machinery related with market data processing from CME Market Data Platform...
Definition: Handler.h:55
DatamineReplaySettings()
Initializes settings with the default values.
Definition: Replay.h:397
UInt32 ChannelId
Identifies CME channel.
Definition: Domain.h:28
void settingsUse(HandlerSettingsUse::Enum policy)
Defines handler settings use policy.
Definition: Replay.h:264
ReplaySpan()
Initializes empty span.
Definition: Replay.h:109
void gatherPcapFiles(FileList &files, const std::string &location, const std::string &ext)
Gathers files which are stored in the given folder with the given extension.
Definition: Replay.h:77
Represents time point without time-zone information.
Definition: Time.h:387
Implements the replay delay by polling in the userspace.
Definition: Replay.h:219
ReplaySettings< NetFeedId > LogReplaySettings
Replay supplements for log replay functionality.
Definition: Replay.h:352
Implements the replay delay using the sleep system call.
Definition: Replay.h:209
const Aliases & aliases() const
Aliases to be used during the replay.
Definition: Replay.h:274
Timestamp timestamp(const MultiContainer &, Tag)
Retrieves last update time field value.
ReplayDelayer & delayPolicy() const
Indicates policy for implementing replay delay.
Definition: Replay.h:320
void delayPolicy(ReplayDelayer &delayer)
Sets a policy for implementing replay delay.
Definition: Replay.h:314
Controls the replay delay.
Definition: Replay.h:202
PcapReplaySettings()
Initializes settings with the default values.
Definition: Replay.h:365
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:35
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
const ReplaySpan & timeSpan() const
Time span for which entries are to be processed.
Definition: Replay.h:290
Various supplemental settings affecting the way the logged data is replayed.
Definition: Replay.h:231
std::map< DataSource, DataSource, DataSourceLess > Aliases
The table of data source aliases.
Definition: Replay.h:235
void replayLogFiles(const FileList &logs, Handler &handler, const UseHandlerSettingsAsIs &marker)
Processes market data stored in the log files according to specified settings.
Definition: Replay.h:473
void replayDatamineFiles(const FileList &logs, Handler &handler)
Replays the given list of historical data for the given Handler according to the default settings...
Definition: Replay.h:554
bool value(Number &number, const MultiContainer &container, Tag tag)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
Represents time interval.
Definition: Time.h:104
void mergeDatamineFiles(const FileList &inFileNames, std::string outFileName, const ReplaySpan &timeSpan=ReplaySpan())
Merges the given Datamine files into a single one. The output file is gzipped.
bool empty() const
Indicates whether span is empty or not.
Definition: Replay.h:132
Defines whether processing and other settings must be extracted from logs and used during the replay...
Definition: Replay.h:88
DatamineReplaySettings::Aliases ChannelIdAliases
Collection of channels to be used by the CME Datamine historical file replay to replace captured sour...
Definition: Replay.h:420
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
void begin(const Timestamp &value)
Updates the beginning of the range.
Definition: Replay.h:151
A Marker instructing the log replay procedure to use Handler settings as they are without applying an...
Definition: Replay.h:457
ReplaySpan & timeSpan()
Time span for which entries are to be processed.
Definition: Replay.h:296
HandlerSettingsUse::Enum settingsUse() const
Settings aren&#39;t stored in Datamine thus constant value is returned.
Definition: Replay.h:404
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:160
void speed(ReplaySpeed::Enum policy)
Defines processing speed.
Definition: Replay.h:308
HandlerSettingsUse::Enum settingsUse() const
Handler settings use policy.
Definition: Replay.h:258
const Timestamp & end() const
Indicates the end of the range.
Definition: Replay.h:157
ReplaySpeed::Enum speed() const
Indicates processing speed policy.
Definition: Replay.h:302
Controls speed of market data replay.
Definition: Replay.h:183
ReplaySettings & operator=(const ReplaySettings &other)
Re-initializes as a copy of the other one.
Definition: Replay.h:327
Aliases & aliases()
Aliases to be used during the replay.
Definition: Replay.h:284
LogReplaySettings::Aliases FeedIdAliases
Collection of logged data sources (feed identifiers) to be used by the Log Replay to replace logged s...
Definition: Replay.h:358
const Timestamp & begin() const
Indicates the beginning of the range.
Definition: Replay.h:145
HandlerSettingsUse::Enum settingsUse() const
Settings aren&#39;t stored in PCAPs thus constant value is returned.
Definition: Replay.h:372
PcapReplaySettings::Aliases NetAddressAliases
Collection of data sources (feed identifiers) to be used by the PCAP file replay to replace captured ...
Definition: Replay.h:389
ReplaySettings(const ReplaySettings &other)
Initializes as a copy of the other one.
Definition: Replay.h:248
ReplaySettings()
Initializes the settings with the default values.
Definition: Replay.h:238
Enum
Controls speed of market data replay.
Definition: Replay.h:186
void gatherFiles(FileList &, const std::string &, const std::string &)
Gathers files which are stored in the given folder with the given extension.
bool contain(const Timestamp &timestamp) const
Indicates whether the given timestamp belongs to the given time span.
Definition: Replay.h:139
ReplaySpan(const Timestamp &begin, const Timestamp &end)
Initializes the instance according to the given bounds.
Definition: Replay.h:117
ReplaySpan & operator=(const ReplaySpan &other)
Re-initializes as a copy of the other one.
Definition: Replay.h:169
void end(const Timestamp &value)
Indicates the end of the range.
Definition: Replay.h:163
void gatherLogFiles(FileList &, ChannelId, const std::string &, const std::string &)
Gathers log files logs which are available for given channel and are stored in a given folder...
void replayPcapFiles(const FileList &logs, Handler &handler)
Replays the given list of PCAP files for the given Handler according to the default settings...
Definition: Replay.h:529
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68