OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.2.2
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 #include <boost/format.hpp>
22 
23 #include <OnixS/HandlerCore/MulticastFeedHandler.h>
24 
26 
28 
29 #include "BaseHandlerImp.h"
30 
31 
32 using namespace OnixS;
33 using namespace OnixS::Util;
34 using namespace OnixS::HandlerCore::Common;
35 
36 
37 namespace OnixS {
38 namespace Eurex {
39 namespace MarketData {
40 namespace Implementation {
41 
42 
43 const Licensing::ProductId productId = 67;
44 
45 BaseHandlerImp::BaseHandlerImp(
46  const std::string& name,
47  Logging::LogFacility* parent, unsigned short maxPacketSize, const std::string& licenseDir)
48  : Licensing::LicenseChecker(licenseDir, productId)
49  , MulticastFeedHandler(name, parent, maxPacketSize)
50 {
51 }
52 
54 {
55  BOOST_ASSERT(getState() == State::Stopped);
56 }
57 
58 void BaseHandlerImp::commonLog(int logLevel, const char * msg, size_t length)
59 {
60  BOOST_ASSERT(msg != nullptr);
61  BOOST_ASSERT(length != 0);
62 
63  if (logLevel < OnixS::Logging::MIN_LOG_LEVEL || logLevel > OnixS::Logging::MAX_LOG_LEVEL)
64  throw OperationException (
65  BOOST_CURRENT_FUNCTION,
66  (boost::format("An error occurred during log operation. Invalid log level (logLevel=%d).")
67  % logLevel).str().c_str()
68  );
69 
70  static const std::string userLogFacilityName = "USER";
71 
72  log (
73  OnixS::Logging::LogMsg(
74  OnixS::Logging::LogLevel(logLevel))[userLogFacilityName] << OnixS::Util::ValuePtr(msg, length)
75  );
76 }
77 
79 {
80  try
81  {
82  BOOST_ASSERT(lock());
83 
84  lock()->acquire();
85 
86  BOOST_SCOPE_EXIT(this_) {
87  this_->lock()->release();
88  } BOOST_SCOPE_EXIT_END
89 
90  MulticastFeedHandler::start();
91  }
92  catch (const std::exception& ex)
93  {
94  TextBuilder tb;
95  tb << "Exception while starting: " << ex.what();
96  log(ONIXS_LOG_ERROR[this] << tb.toString());
97  invokeError(ErrorCode::General, tb.toString());
98  throw;
99  }
100  catch (...)
101  {
102  TextBuilder tb;
103  tb << "Unknown exception while stopping!";
104  log(ONIXS_LOG_ERROR[this] << "Unknown exception while starting!");
105  invokeError(ErrorCode::General, tb.toString());
106  throw;
107  }
108 }
109 
111 {
112  try
113  {
114  BOOST_ASSERT(lock());
115 
116  lock()->acquire();
117 
118  BOOST_SCOPE_EXIT(this_) {
119  this_->lock()->release();
120  } BOOST_SCOPE_EXIT_END
121 
122  MulticastFeedHandler::stop();
123  }
124  catch (const std::exception& ex)
125  {
126  TextBuilder tb;
127  tb << "Exception while stopping: " << ex.what();
128  log(ONIXS_LOG_ERROR[this] << tb.toString());
129  invokeError(ErrorCode::General, tb.toString());
130  throw;
131  }
132  catch (...)
133  {
134  TextBuilder tb;
135  tb << "Unknown exception while stopping!";
136  log(ONIXS_LOG_ERROR[this] << "Unknown exception while stopping!");
137  invokeError(ErrorCode::General, tb.toString());
138  throw;
139  }
140 }
141 
142 void BaseHandlerImp::start(const ReplayOptions& options, const LogPlayerLinks& links, const std::string& feedName)
143 {
144  if (options.logs.size() > 0)
145  {
146  TextBuilder tb;
147  tb << "Log file to replay: ";
148 
149  BOOST_FOREACH(const std::string& item, options.logs)
150  {
151  tb << '\n' << item;
152  }
153 
154  log(ONIXS_LOG_INFO[this] << tb.toString());
155  }
156 
157 
158  // 20141013-05:36:50.893 [EOBI.Incremental] 490913 Packet received (IADLMv////+hfQcAZwAAAAIBAAAAAAAAkP8wdyywnBMQAMky/////3liAAAAAAAA).
159  const std::string parser = "(\\S+).*\\[" + feedName + "\\.(\\w+)\\].*Packet received \\((.*)\\)\\.";
160 
161  const float playSpeedMultiplier = options.replayMode == ReplayMode::ConstantPacketReplayDelay ? 0 : options.playSpeedMultiplier;
162 
163  HandlerCore::MarketData::MulticastFeedHandler::startReplay(
164  options.logs,
165  playSpeedMultiplier,
166  options.packetReplayDelay,
167  links,
168  boost::bind(&ReplayListener::onReplayError, options.listener, _1),
169  boost::bind(&ReplayListener::onReplayFinished, options.listener),
170  parser,
171  0,
172  1,
173  2
174  );
175 }
176 
177 std::string os()
178 {
179 #if BOOST_OS_WINDOWS
180  return "Windows";
181 #elif BOOST_OS_UNIX
182  std::string res = "Linux";
183  res += ", ";
184  res += __VERSION__;
185  return res;
186 #else
187 # error "Unknown OS"
188 #endif
189 }
190 
191 }
192 }
193 }
194 }
const Licensing::ProductId productId
virtual void invokeError(ErrorCode::Enum, const std::string &)
Util::TextBuilder TextBuilder
Definition: Formatting.h:42
void commonLog(int logLevel, const char *msg, size_t length)
User&#39;s common log.
Definition: Defines.h:30
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