OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.0.3
API documentation
BaseHandlerImp.cpp
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 #include <boost/scope_exit.hpp>
20 #include <boost/foreach.hpp>
21 
22 #include <OnixS/HandlerCore/MulticastFeedHandler.h>
23 
25 
26 #include "BaseHandlerImp.h"
27 
28 
29 using namespace OnixS;
30 using namespace OnixS::Util;
31 using namespace OnixS::HandlerCore::Common;
32 
33 
34 namespace OnixS {
35 namespace Eurex {
36 namespace MarketData {
37 namespace Implementation {
38 
39 
40 const size_t MaxUdpPacketSize = 1470;
41 const Licensing::ProductId productId = 67;
42 
43 BaseHandlerImp::BaseHandlerImp(
44  const std::string& name,
45  Logging::LogFacility* parent, unsigned short maxPacketSize, const std::string& licenseDir)
46  : Licensing::LicenseChecker(licenseDir, productId)
47  , MulticastFeedHandler(name, parent, maxPacketSize)
48 {
49 }
50 
52 {
53  BOOST_ASSERT(getState() == State::Stopped);
54 }
55 
57 {
58  try
59  {
60  BOOST_ASSERT(lock());
61 
62  lock()->acquire();
63 
64  BOOST_SCOPE_EXIT(this_) {
65  this_->lock()->release();
66  } BOOST_SCOPE_EXIT_END
67 
68  MulticastFeedHandler::start();
69  }
70  catch (const std::exception& ex)
71  {
72  TextBuilder tb;
73  tb << "Exception while starting: " << ex.what();
74  log(ONIXS_LOG_ERROR[this] << tb.toString());
75  invokeError(ErrorCode::General, tb.toString());
76  throw;
77  }
78  catch (...)
79  {
80  TextBuilder tb;
81  tb << "Unknown exception while stopping!";
82  log(ONIXS_LOG_ERROR[this] << "Unknown exception while starting!");
83  invokeError(ErrorCode::General, tb.toString());
84  throw;
85  }
86 }
87 
89 {
90  try
91  {
92  BOOST_ASSERT(lock());
93 
94  lock()->acquire();
95 
96  BOOST_SCOPE_EXIT(this_) {
97  this_->lock()->release();
98  } BOOST_SCOPE_EXIT_END
99 
100  MulticastFeedHandler::stop();
101  }
102  catch (const std::exception& ex)
103  {
104  TextBuilder tb;
105  tb << "Exception while stopping: " << ex.what();
106  log(ONIXS_LOG_ERROR[this] << tb.toString());
107  invokeError(ErrorCode::General, tb.toString());
108  throw;
109  }
110  catch (...)
111  {
112  TextBuilder tb;
113  tb << "Unknown exception while stopping!";
114  log(ONIXS_LOG_ERROR[this] << "Unknown exception while stopping!");
115  invokeError(ErrorCode::General, tb.toString());
116  throw;
117  }
118 }
119 
120 void BaseHandlerImp::start(const ReplayOptions& options, const LogPlayerLinks& links, const std::string& feedName)
121 {
122  if (options.logs.size() > 0)
123  {
124  TextBuilder tb;
125  tb << "Log file to replay: ";
126 
127  BOOST_FOREACH(const std::string& item, options.logs)
128  {
129  tb << '\n' << item;
130  }
131 
132  log(ONIXS_LOG_INFO[this] << tb.toString());
133  }
134 
135 
136  // 20141013-05:36:50.893 [EOBI.Incremental] 490913 Packet received (IADLMv////+hfQcAZwAAAAIBAAAAAAAAkP8wdyywnBMQAMky/////3liAAAAAAAA).
137  const std::string parser = "(\\S+).*\\[" + feedName + "\\.(\\w+)\\].*Packet received \\((.*)\\)\\.";
138 
139  const float playSpeedMultiplier = options.replayMode == ReplayMode::ConstantPacketReplayDelay ? 0 : options.playSpeedMultiplier;
140 
141  HandlerCore::MarketData::MulticastFeedHandler::startReplay(
142  options.logs,
143  playSpeedMultiplier,
144  options.packetReplayDelay,
145  links,
146  boost::bind(&ReplayListener::onReplayError, options.listener, _1),
147  boost::bind(&ReplayListener::onReplayFinished, options.listener),
148  parser,
149  0,
150  1,
151  2
152  );
153 }
154 
155 std::string os()
156 {
157 #if BOOST_OS_WINDOWS
158  return "Windows";
159 #elif BOOST_OS_UNIX
160  std::string res = "Linux";
161  res += ", ";
162  res += __VERSION__;
163  return res;
164 #else
165 # error "Unknown OS"
166 #endif
167 }
168 
169 }
170 }
171 }
172 }
const Licensing::ProductId productId
virtual void invokeError(ErrorCode::Enum, const std::string &)
Util::TextBuilder TextBuilder
Definition: Formatting.h:42
Definition: Group.h:25
ReplayMode::Enum replayMode
Replay mode. The default value is ReplayMode::ConstantPacketReplayDelay.
Definition: Replay.h:93
Defines params which affect logs replay.
Definition: Replay.h:74
virtual void onReplayFinished()=0
Is called once all the logs are replayed.
ReplayListener * listener
Instance to notify about replay events.
Definition: Replay.h:81
virtual void onReplayError(const std::string &errorDescription)=0
Is called once error occurs while replaying logs.
Identifiers errors of generic nature.
Definition: ErrorListener.h:38