OnixS C++ CME Market Data Handler  5.4.0
API documentation
TcpRecovery.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 <stdexcept>
25 
26 #include <OnixS/CME/MDH/Watch.h>
27 #include <OnixS/CME/MDH/String.h>
28 #include <OnixS/CME/MDH/Integral.h>
29 
30 
32 
33 /// Throws error on zero TCP recovery request limit value.
34 inline
35 void
37 {
38  throw std::runtime_error
39  (
40  "Maximal number of TCP Recovery requests "
41  "per second must be greater than zero. "
42  );
43 }
44 
45 /// TCP recovery service configuration settings.
48 {
49  std::string username_;
50  std::string password_;
51 
52  UInt32 acquisitionTimeout_;
53 
54  UInt32 maxRequests_;
55 
56  WatchService* watch_;
57 
58 public:
59  /// Initializes parameters with default values.
61  : username_()
62  , password_()
63  , acquisitionTimeout_(500)
64  , maxRequests_(15)
65  , watch_(&UtcWatch::service())
66  {
67  }
68 
69  /// Cleans everything up.
71  {
72  }
73 
74  /// Username to identify a requester while
75  /// logging on to a TCP Recovery service.
76  const
77  std::string&
78  username() const
79  {
80  return username_;
81  }
82 
83  /// Assigns username to identify a requester
84  /// while logging on to a TCP Recovery service.
85  void
87  const std::string& username)
88  {
89  username_ = username;
90  }
91 
92  /// Password to identify a requester while
93  /// logging on to TCP Recovery service.
94  const
95  std::string&
96  password() const
97  {
98  return password_;
99  }
100 
101  /// Assigns password to identify a requester
102  /// while logging on to TCP Recovery service.
103  void
105  const std::string& password)
106  {
107  password_ = password;
108  }
109 
110  /// Timeout on a TCP recovery service acquisition.
111  ///
112  /// TCP recovery service may process only
113  /// single request at a time. If TCP recovery
114  /// service can't be acquired within time defined
115  /// by given parameter, recovery request will be
116  /// rejected.
117  ///
118  /// Timeout is measured in milliseconds.
119  ///
120  /// @note Default value is '500'.
121  UInt32
123  {
124  return acquisitionTimeout_;
125  }
126 
127  /// Defines the wait time limit while
128  /// acquiring a TCP recovery service.
129  ///
130  /// If TCP recovery service is used and the
131  /// other Handler instance gained access to
132  /// the service to recover missing data, the
133  /// Handler instance will wait for the given
134  /// time to acquire the service and will cancel
135  /// the TCP recovery request if service wasn't
136  /// acquired for the given time period.
137  ///
138  /// Timeout is measured in milliseconds.
139  void
141  UInt32 acquisitionTimeout)
142  {
143  acquisitionTimeout_ =
144  acquisitionTimeout;
145  }
146 
147  /// Maximal number of requests per second.
148  ///
149  /// By default, the service is limited
150  /// to serve 15 requests per second.
152  {
153  return maxRequests_;
154  }
155 
156  /// Limits number of requests per second.
157  ///
158  /// If the established limit is exceeded a
159  /// recovery attempt is rejected by service.
160  void
162  UInt32 maxRequests)
163  {
164  if (0 < maxRequests)
165  {
166  maxRequests_ = maxRequests;
167  }
168  else
169  {
171  }
172  }
173 
174  /// Watch service to be used by the service.
175  ///
176  /// Watch is used by the service while restricting
177  /// number of incoming requests.
178  ///
179  /// @note By default, UTC watch service is used.
181  {
182  return *watch_;
183  }
184 
185  /// Watch service to be used by the service.
186  ///
187  /// If no instance associated, UTC watch is used.
188  void
190  WatchService& watch)
191  {
192  watch_ = &watch;
193  }
194 };
195 
196 /// Serializes TCP recovery settings.
197 ONIXS_CMEMDH_EXPORTED
198 void
199 toStr(
200  std::string&,
201  const
203 
204 /// Serializes TCP recovery settings.
205 inline
206 std::string
208  const
209  TcpRecoverySettings& settings)
210 {
211  std::string str;
212 
213  toStr(str, settings);
214 
215  return str;
216 }
217 
218 // A bit of declarations.
220 (
221  Handler
222 );
223 
224 /// TCP Recovery Service.
227 {
228  class Details;
229 
230  // Shared details.
231  Details* details_;
232 
233  // Copying is not assumed.
234 
236  const TcpRecoveryService&);
237 
239  operator =(
240  const TcpRecoveryService&);
241 
242 protected:
243  /// Services as a marker for special construction.
244  struct NoDetails {};
245 
246  /// Initializes without synchronization resource.
247  explicit
249  const NoDetails&);
250 
251 public:
252  /// Initializes instance according to given settings.
254  const TcpRecoverySettings&);
255 
256  /// Finalizes instance and cleans everything up.
257  virtual ~TcpRecoveryService();
258 
259  /// Basic information on the service.
260  virtual
261  void
262  brief(
263  std::string&);
264 
265  /// Gains access to the service.
266  ///
267  /// Returns login credentials through the
268  /// parameters upon successful acquisition.
269  virtual
270  bool
271  tryAcquire(
272  const Handler&,
273  StrRef&, StrRef&);
274 
275  /// Releases previously acquired lock on the service.
276  virtual
277  void
278  release(
279  const Handler&);
280 };
281 
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
void acquisitionTimeout(UInt32 acquisitionTimeout)
Definition: TcpRecovery.h:140
void username(const std::string &username)
Definition: TcpRecovery.h:86
UInt32 UInt32
uInt32.
Definition: Fields.h:247
const std::string & username() const
Definition: TcpRecovery.h:78
std::string toStr(const TcpRecoverySettings &settings)
Serializes TCP recovery settings.
Definition: TcpRecovery.h:207
TcpRecoverySettings()
Initializes parameters with default values.
Definition: TcpRecovery.h:60
WatchService & watch() const
Definition: TcpRecovery.h:180
~TcpRecoverySettings()
Cleans everything up.
Definition: TcpRecovery.h:70
void maxRequests(UInt32 maxRequests)
Definition: TcpRecovery.h:161
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:46
Abstract watch service.
Definition: Watch.h:29
#define ONIXS_CMEMDH_EXPORTED_CLASS
Definition: Bootstrap.h:54
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
const std::string & password() const
Definition: TcpRecovery.h:96
TCP recovery service configuration settings.
Definition: TcpRecovery.h:46
ONIXS_CMEMDH_EXPORTED void brief(std::string &, const ConsolidatedBook &)
Book brief info.
void throwZeroTcpRecoveryRequestLimit()
Throws error on zero TCP recovery request limit value.
Definition: TcpRecovery.h:36
void watch(WatchService &watch)
Definition: TcpRecovery.h:189
Services as a marker for special construction.
Definition: TcpRecovery.h:244
void password(const std::string &password)
Definition: TcpRecovery.h:104
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156