OnixS C++ CME MDP Premium Market Data Handler  5.8.3
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 
31 
32 /// Throws error on zero TCP recovery request limit value.
34 {
35  throw std::runtime_error("Maximal number of TCP Recovery requests per second must be greater than zero.");
36 }
37 
38 /// TCP Recovery settings.
40 {
41 public:
42  /// <summary>
43  /// The default value of acquisitionTimeout().
44  /// </summary>
45  enum { DefaultAcquisitionTimeout = 500 };
46 
47  /// <summary>
48  /// The default value of maxRequests().
49  /// </summary>
50  enum { DefaultMaxRequests = 15 };
51 
53  : username_()
54  , password_()
55  , acquisitionTimeout_(DefaultAcquisitionTimeout)
56  , maxRequests_(DefaultMaxRequests)
57  , watch_(&UtcWatch::service())
58  {
59  }
60 
61  TcpRecoverySettings(const std::string& username, const std::string& password)
62  : username_(username)
63  , password_(password)
64  , acquisitionTimeout_(DefaultAcquisitionTimeout)
65  , maxRequests_(DefaultMaxRequests)
66  , watch_(&UtcWatch::service())
67  {
68  }
69 
71 
72  /// Username to identify a requester while
73  /// logging on to a TCP Recovery service.
74  const std::string& username() const
75  {
76  return username_;
77  }
78 
79  /// Assigns username to identify a requester
80  /// while logging on to a TCP Recovery service.
81  TcpRecoverySettings& username(const std::string& username)
82  {
83  username_ = username;
84 
85  return *this;
86  }
87 
88  /// Password to identify a requester while
89  /// logging on to TCP Recovery service.
90  const std::string& password() const
91  {
92  return password_;
93  }
94 
95  /// Assigns password to identify a requester while logging on to TCP Recovery service.
96  TcpRecoverySettings& password(const std::string& password)
97  {
98  password_ = password;
99 
100  return *this;
101  }
102 
103  /// Returns the timeout (in milliseconds) on a TCP Recovery service acquisition.
104  ///
105  /// The recovery request will be rejected if the TCP recovery service cannot be acquired within this period.
106  ///
107  /// The default value is DefaultAcquisitionTimeout.
109  {
110  return acquisitionTimeout_;
111  }
112 
113  /// Sets the timeout (in milliseconds) on a TCP Recovery service acquisition.
114  ///
115  /// The recovery request will be rejected if the TCP recovery service cannot be acquired within this period.
117  {
118  acquisitionTimeout_ = acquisitionTimeout;
119 
120  return *this;
121  }
122 
123  /// Returns the maximum number of requests per second.
124  ///
125  /// When this limit is exceeded the recovery attempt is rejected.
126  ///
127  /// The default value is DefaultMaxRequests.
129  {
130  return maxRequests_;
131  }
132 
133  /// Sets the maximum number of requests per second.
134  ///
135  /// When this limit is exceeded the recovery attempt is rejected.
137  {
138  if (0 < maxRequests)
139  {
140  maxRequests_ = maxRequests;
141  }
142  else
143  {
145  }
146 
147  return *this;
148  }
149 
150  /// Watch service to be used by the service.
151  ///
152  /// Watch is used by the service while restricting
153  /// number of incoming requests.
154  ///
155  /// @note By default, UTC watch service is used.
157  {
158  return *watch_;
159  }
160 
161  /// Watch service to be used by the service.
162  ///
163  /// If no instance associated, UTC watch is used.
165  {
166  watch_ = &watch;
167 
168  return *this;
169  }
170 
171  private:
172  std::string username_;
173  std::string password_;
174 
175  UInt32 acquisitionTimeout_;
176 
177  UInt32 maxRequests_;
178 
179  WatchService* watch_;
180 };
181 
182 /// Serializes TCP recovery settings.
184 void toStr(std::string&, const TcpRecoverySettings&);
185 
186 /// Serializes TCP recovery settings.
187 inline std::string toStr(const TcpRecoverySettings& settings)
188 {
189  std::string str;
190 
191  toStr(str, settings);
192 
193  return str;
194 }
195 
196 // A bit of declarations.
198 
199 /// TCP Recovery Service.
201 {
202 public:
203  /// Initializes instance according to given settings.
205 
206  /// Finalizes instance and cleans everything up.
207  virtual ~TcpRecoveryService();
208 
209  /// Basic information on the service.
210  virtual void brief(std::string&);
211 
212  /// Gains access to the service.
213  ///
214  /// Returns login credentials through the
215  /// parameters upon successful acquisition.
216  virtual bool tryAcquire(const Handler&, StrRef&, StrRef&);
217 
218  /// Releases previously acquired lock on the service.
219  virtual void release(const Handler&);
220 
221 protected:
222  /// Services as a marker for special construction.
223  struct NoDetails
224  {};
225 
226  /// Initializes without synchronization resource.
227  explicit TcpRecoveryService(const NoDetails&);
228 
229 private:
230  class Details;
231 
232  // Shared details.
233  Details* details_;
234 
235  // Copying is not assumed.
236 
238 
239  TcpRecoveryService& operator=(const TcpRecoveryService&);
240 };
241 
UInt32 UInt32
uInt32.
Definition: Fields.h:192
Encapsulates all the machinery related with market data processing from CME Market Data Platform...
Definition: Handler.h:55
UInt32 acquisitionTimeout() const
Returns the timeout (in milliseconds) on a TCP Recovery service acquisition.
Definition: TcpRecovery.h:108
void brief(std::string &, const ConsolidatedBook &)
Book brief info.
const std::string & username() const
Username to identify a requester while logging on to a TCP Recovery service.
Definition: TcpRecovery.h:74
std::string toStr(const TcpRecoverySettings &settings)
Serializes TCP recovery settings.
Definition: TcpRecovery.h:187
WatchService & watch() const
Watch service to be used by the service.
Definition: TcpRecovery.h:156
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:35
Abstract watch service.
Definition: Watch.h:29
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
UInt32 maxRequests() const
Returns the maximum number of requests per second.
Definition: TcpRecovery.h:128
TcpRecoverySettings & watch(WatchService &watch)
Watch service to be used by the service.
Definition: TcpRecovery.h:164
TcpRecoverySettings & password(const std::string &password)
Assigns password to identify a requester while logging on to TCP Recovery service.
Definition: TcpRecovery.h:96
TcpRecoverySettings(const std::string &username, const std::string &password)
Definition: TcpRecovery.h:61
TcpRecoverySettings & maxRequests(UInt32 maxRequests)
Sets the maximum number of requests per second.
Definition: TcpRecovery.h:136
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition: String.h:41
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:135
const std::string & password() const
Password to identify a requester while logging on to TCP Recovery service.
Definition: TcpRecovery.h:90
TCP Recovery settings.
Definition: TcpRecovery.h:39
void throwZeroTcpRecoveryRequestLimit()
Throws error on zero TCP recovery request limit value.
Definition: TcpRecovery.h:33
TcpRecoverySettings & acquisitionTimeout(UInt32 acquisitionTimeout)
Sets the timeout (in milliseconds) on a TCP Recovery service acquisition.
Definition: TcpRecovery.h:116
Services as a marker for special construction.
Definition: TcpRecovery.h:223
TcpRecoverySettings & username(const std::string &username)
Assigns username to identify a requester while logging on to a TCP Recovery service.
Definition: TcpRecovery.h:81
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68