OnixS C++ CME MDP Conflated TCP Handler  1.2.1
API Documentation
SessionSettings.h
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 
20 #pragma once
21 
25 
26 #include <climits>
27 #include <set>
28 #include <string>
29 #include <vector>
30 
31 namespace OnixS {
32 namespace CME {
33 namespace ConflatedTCP {
34 
35 /**
36  * Session settings.
37  */
39 {
40 public:
43 
44  /// \return the session id that was assigned by the exchange.
45  ///
46  /// The default value is empty.
48  const std::string & sessionId() const {
49  return sessionId_;
50  }
51 
52  /// Sets the session id that was assigned by the exchange.
54  SessionSettings& sessionId(const std::string & value);
55 
56  /// \return the firm id that was assigned by the exchange.
57  ///
58  /// The default value is empty.
60  const std::string & firmId() const {
61  return firmId_;
62  }
63 
64  /// Sets the firm id that was assigned by the exchange.
66  SessionSettings& firmId(const std::string & value);
67 
68  /// \return the access key that was assigned by the exchange.
69  ///
70  /// The default value is empty.
72  const std::string & accessKey() const {
73  return accessKey_;
74  }
75 
76  /// Sets the access key that was assigned by the exchange.
78  SessionSettings& accessKey(const std::string & value);
79 
80  /// \return the secret key that was assigned by the exchange.
81  ///
82  /// The default value is empty.
84  const std::string & secretKey() const {
85  return secretKey_;
86  }
87 
88  /// Sets the secret key that was assigned by the exchange.
90  SessionSettings& secretKey(const std::string & value);
91 
92  /// \return the threading model.
93  ///
94  /// The defaul value is Default::ThreadingModelValue.
97  return threadingModel_;
98  }
99 
100  /// Sets the threading model.
102  SessionSettings& threadingModel(ThreadingModel::Enum value);
103 
104  /// The maximum spinning timeout (microseconds).
105  static const unsigned MaxSpinningTimeoutUsec = 1000000; //1 sec
106 
107  /// \return the receive spinning timeout (microseconds).
108  ///
109  /// The defaul value is Default::ReceiveSpinningTimeout.
111  unsigned receiveSpinningTimeout() const {
112  return receiveSpinningTimeout_;
113  }
114 
115  /// Sets the receive spinning timeout (microseconds).
117  SessionSettings& receiveSpinningTimeout(unsigned usecTimeout);
118 
119  /// \return the send spinning timeout (microseconds).
120  ///
121  /// The defaul value is Default::SendSpinningTimeout.
123  unsigned sendSpinningTimeout() const
124  {
125  return sendSpinningTimeout_;
126  }
127 
128  /// Sets the send spinning timeout (microseconds).
130  SessionSettings& sendSpinningTimeout(unsigned usecTimeout);
131 
132  /// \return the message grouping mode.
133  ///
134  /// - `0` means default grouping - the messages are sent immediately, and pending messages (if any) are grouped till reaching of TCP buffer size.
135  /// - `1` means the messages are sent immediately and never grouped.
136  /// - `2` (or higher) means the messages are sent immediately, and pending messages are grouped by 2 (or higher).
137  ///
138  /// The defaul value is Default::MessageGrouping.
140  unsigned messageGrouping() const {
141  return messageGrouping_;
142  }
143 
144  /// Sets the message grouping mode.
146  SessionSettings& messageGrouping(unsigned value);
147 
148  /// Resets the settings to the default values.
149  SessionSettings& resetToDefaults();
150 
151  /// Adds the path to the folder that contains license file(s).
153  SessionSettings& addLicenseStore(const std::string& value);
154 
155  /// Sets the path to the folder that contains license file(s).
157  SessionSettings& licenseStore(const std::string & value);
158 
159  /// Folders that contain license file(s).
160  typedef std::vector<std::string> LicenseStores;
161 
162  /// \return path(s) to the folder that contains license file(s).
163  ///
164  /// The default value is '.'.
166  const LicenseStores& licenseStores() const
167  {
168  return licenseStores_;
169  }
170 
171  /// \return the number of days to alert before the license expiration.
172  ///
173  /// The defaul value is Default::LicenseAlertingDaysBeforeExpiration.
176  return licenseAlertingDaysBeforeExpiration_;
177  }
178 
179  /// Sets the number of days to alert before the license expiration.
180  ///
181  /// If the amount of remaining license days is less or equal to this number,
182  /// then the warning is reported to the Handler's log.
183  ///
184  /// The verification is performed during the Session::connect call.
186  SessionSettings& licenseAlertingDaysBeforeExpiration(unsigned days) {
187  licenseAlertingDaysBeforeExpiration_ = days;
188  return *this;
189  }
190 
191  /// \return The interface name or IP-address from which the Handler connects to the counterparty.
192  ///
193  /// The default value is empty.
195  const std::string & localNetworkInterface() const {
196  return localNetworkInterface_;
197  }
198 
199  /// Specifies the local interface from which the Handler connects to the counterparty.
200  ///
201  /// Each local interface specification could specify the local IP address and port.
202  /// For instance, `localhost` and `192.168.0.1:4501` are valid values.
204  SessionSettings& localNetworkInterface(const std::string & value);
205 
206  /// \return the Handler log file name.
207  ///
208  /// The default value is `HandlerLog.txt`.
210  const std::string & logFileName() const {
211  return logFileName_;
212  }
213 
214  /// Specifies the Handler log file name.
216  SessionSettings& logFileName(const std::string & value);
217 
218  /// \return the Session Storage directory.
219  ///
220  /// Inbound and outbound messages, session's state data and the Handler log file are stored in this directory.
221  ///
222  /// The default value is `MsgStorage`.
224  const std::string & storageDirectory() const {
225  return storageDirectory_;
226  }
227 
228  /// Sets the Session Storage directory.
229  ///
230  /// Inbound and outbound messages, session's state data and the Handler log file are stored in this directory.
232  SessionSettings& storageDirectory(const std::string & value);
233 
234  /// \return the usage of the local time in Handler events and log files.
235  ///
236  /// The defaul value is Default::LocalTimeUsage.
238  bool localTimeUsage() const {
239  return localTimeUsage_;
240  }
241 
242  /// Specifies the usage of the local time in Handler events and log files.
243  ///
244  /// If it is `true`, then the local time is used, otherwise - UTC.
246  SessionSettings& localTimeUsage(bool);
247 
248  /// \return the segment size for the file-based session storage.
249  ///
250  /// The defaul value is Default::FileBasedStorageSegmentSize.
253  return fileBasedStorageSegmentSize_;
254  }
255 
256  /// Sets the segment size for file-based session storage.
258  SessionSettings& fileBasedStorageSegmentSize(Messaging::UInt64 value);
259 
260  /// \return the maximum size of the asynchronous session storage queue.
261  ///
262  /// By default, the size is unlimited.
265  return asyncFileBasedStorageQueueMaxSize_;
266  }
267 
268  /// Sets the maximum size of the asynchronous session storage queue.
270  SessionSettings& asyncFileBasedStorageQueueMaxSize(unsigned value);
271 
272  /// \return the CPU index(es) for affinity of the asynchronous session storage threads.
273  ///
274  /// By default, the affinity is not set.
277  return asyncFileBasedStorageThreadAffinity_;
278  }
279 
280  /// Specifies the CPU index(es) for affinity of the asynchronous session storage threads.
282  SessionSettings& asyncFileBasedStorageThreadAffinity(const CpuIndexes & cpuIndexes);
283 
284  /// \return The file-based storage integrity errors checking mode:
285  ///
286  /// - `true` - ignore errors and create a new storage
287  /// - `false` - throw an exception
288  ///
289  /// The defaul value is Default::IgnoreFileBasedStorageIntegrityErrors.
292  return ignoreFileBasedStorageIntegrityErrors_;
293  }
294 
295  /// Sets the file-based storage integrity errors checking mode.
297  SessionSettings& ignoreFileBasedStorageIntegrityErrors(bool);
298 
299  /// \return `true` if outbound messages are logged before sending, 'false' otherwise.
300  ///
301  /// The defaul value is Default::LogBeforeSending.
303  bool logBeforeSending() const {
304  return logBeforeSending_;
305  }
306 
307  /// Controls the order of logging and sending outbound messages.
308  ///
309  /// \param before if 'true' then outbound messages are logged before sending.
311  SessionSettings& logBeforeSending(bool before);
312 
313  /// \return the maximum number of tries to restore the telecommunications link.
314  ///
315  /// The defaul value is Default::ReconnectAttempts.
317  unsigned reconnectAttempts() const {
318  return reconnectAttempts_;
319  }
320 
321  /// Sets the maximum number of tries to restore the telecommunications link.
323  SessionSettings& reconnectAttempts(unsigned reconnectAttempts);
324 
325  /// \return the time interval between retries to restore the telecommunications link (seconds).
326  ///
327  /// The defaul value is Default::ReconnectInterval.
329  unsigned reconnectInterval() const {
330  return reconnectInterval_;
331  }
332 
333  /// Sets the time interval between retries to restore the telecommunications link (seconds).
335  SessionSettings& reconnectInterval(unsigned value);
336 
337  /// Specifies the usage of the operating system default socket buffer size.
338  static const int UseOsDefaultSocketBufferSize = -1;
339 
340  /// \return the socket receive buffer size.
341  ///
342  /// The default value is Default::SocketReceiveBufferSize.
345  return socketReceiveBufferSize_;
346  }
347 
348  /// Sets the socket receive buffer size.
349  ///
350  /// \param bufferSize the size of the socket receive buffer size.
351  /// If SessionSettings::UseOsDefaultSocketBufferSize then the default operating system value is used.
353  SessionSettings& socketReceiveBufferSize(int bufferSize);
354 
355  /// \return the reasonable transmission time - as the percentage from the `KeepAliveInterval` value.
356  ///
357  /// The defaul value is Default::ReasonableTransmissionTime.
359  unsigned reasonableTransmissionTime() const {
360  return reasonableTransmissionTime_;
361  }
362 
363  /// Sets the reasonable transmission time - as the percentage from the `KeepAliveInterval` value.
365  SessionSettings& reasonableTransmissionTime(unsigned percentage);
366 
367  /// \return the size of the socket send buffer size.
368  ///
369  /// The default value is Default::SocketSedndBufferSize.
371  int socketSendBufferSize() const {
372  return socketSendBufferSize_;
373  }
374 
375  /// Sets the size of the socket send buffer size.
376  ///
377  /// \param bufferSize the size of the socket send buffer size.
378  /// If SessionSettings::UseOsDefaultSocketBufferSize then the default operating system value is used.
380  SessionSettings& socketSendBufferSize(int bufferSize);
381 
382  /// \return the thread pool affinity.
384  const CpuIndexes & threadPoolAffinity() const {
385  return threadPoolAffinity_;
386  }
387 
388  /// Sets the thread pool affinity.
390  SessionSettings& threadPoolAffinity(const CpuIndexes & cpuIndexes);
391 
392  /// \return the thread pool priority.
394  int threadPoolPriority() const {
395  return threadPoolPriority_;
396  }
397 
398  /// Sets the thread pool priority.
400  SessionSettings& threadPoolPriority(int priority);
401 
402  /// \return the thread pool policy.
404  int threadPoolPolicy() const {
405  return threadPoolPolicy_;
406  }
407 
408  /// Sets the thread pool policy.
410  SessionSettings& threadPoolPolicy(int policy);
411 
412  /// \return the value of the option to improve latency at the expense of message throughput (the `TCP_NODELAY` socket option).
413  ///
414  /// The default value is Default::TcpNoDelayOption.
416  bool tcpNoDelayOption() const {
417  return tcpNoDelayOption_;
418  }
419 
420  /// Sets the value of the option to improve latency at the expense of message throughput (the `TCP_NODELAY` socket option).
422  SessionSettings& tcpNoDelayOption(bool value);
423 
424  /// \return the size of the shared thread pool.
425  ///
426  /// The default value is Default::ThreadPoolSize.
428  unsigned threadPoolSize() const {
429  return threadPoolSize_;
430  }
431 
432  /// Sets the size of the shared thread pool.
434  SessionSettings& threadPoolSize(unsigned numberOfThreads);
435 
436  /// \return the longest time in milliseconds the client system can remain silent before sending a message.
437  ///
438  /// The default value is Default::KeepAliveInterval.
440  unsigned keepAliveInterval() const
441  {
442  return keepAliveInterval_;
443  }
444 
445  /// Sets the longest time in milliseconds the client system can remain silent before sending
446  /// a message.
447  ///
448  /// \note Allowed range is between `5000` - `60000`. Any value outside this range will be rejected.
450  SessionSettings& keepAliveInterval(unsigned milliseconds);
451 
452  /// Loads the settings from the given configuration file.
453  ///
454  /// \see Key
456  SessionSettings& load(const std::string& configFile);
457 
458  /// \return the human-friendly description.
460  std::string toString() const;
461 
462  /// Default session settings.
464  static const ThreadingModel::Enum ThreadingModelValue = ThreadingModel::DedicatedThreads;
465  static const bool CreateLogFile = true;
466  static const int KeepAliveInterval = 30000;
467  static const bool LogBeforeSending = true;
468  static const int SocketSendBufferSize = UseOsDefaultSocketBufferSize;
469  static const int SocketReceiveBufferSize = UseOsDefaultSocketBufferSize;
470  static const bool TcpNoDelayOption = true;
471  static const int ReceiveSpinningTimeout = 0;
472  static const int SendSpinningTimeout = 0;
473  static const char LicenseStore[] ;
474  static const unsigned LicenseAlertingDaysBeforeExpiration = 0;
475  static const char LogDir[];
476  static const char LogFileName[];
477  static const bool LocalTimeUsage = false;
478  static const unsigned MessageGrouping = 0;
479  static const int ReasonableTransmissionTime = 20;
480  static const int ReconnectAttempts = 3;
481  static const int ReconnectInterval = 180;
482  static const unsigned long long FileBasedStorageSegmentSize = 0;
483  static const bool IgnoreFileBasedStorageIntegrityErrors = false;
484  static const int ThreadPoolSize = 0;
485  static const unsigned AsyncFileBasedStorageQueueMaxSize = UINT_MAX;
486  };
487 
488  /// The keys that are used to load settings from the configuration file.
490  static const char * SessionId; ///< = "SessionId"
491  static const char * FirmId; ///< = "FirmId"
492  static const char * AccessKey; ///< = "AccessKey"
493  static const char * SecretKey; ///< = "SecretKey"
494 
495  static const char * AsyncFileBasedStorageQueueMaxSize; ///< = "AsyncFileBasedStorage.QueueMaxSize"
496  static const char * AsyncFileBasedStorageThreadAffinity; ///< = "AsyncFileBasedStorage.ThreadAffinity"
497  static const char * ThreadingModel; ///< = "ThreadingModel"
498  static const char * TcpNoDelayOption; ///< = "TcpNoDelayOption"
499  static const char * MessageGrouping; ///< = "MessageGrouping"
500  static const char * FileBasedStorageSegmentSize; ///< = "FileBasedStorageSegmentSize"
501  static const char * IgnoreFileBasedStorageIntegrityErrors; ///< = "IgnoreFileBasedStorageIntegrityErrors"
502  static const char * KeepAliveInterval; ///< = "KeepAliveInterval"
503  static const char * LicenseFile; ///< = "LicenseFile"
504  static const char * LicenseStore; ///< = "LicenseStore"
505  static const char * LicenseAlertingDaysBeforeExpiration; ///< = "LicenseAlertingDaysBeforeExpiration"
506  static const char * LocalNetworkInterface; ///< = "LocalNetworkInterface"
507  static const char * LogFileName; ///< = "Log.FileName"
508  static const char * LocalTimeUsage; ///< = "LocalTimeUsage"
509  static const char * LogBeforeSending; ///< = "Log.BeforeSending"
510  static const char * ReasonableTransmissionTime; ///< = "ReasonableTransmissionTime"
511  static const char * ReceiveSpinningTimeout; ///< = "ReceiveSpinningTimeout"
512  static const char * ReconnectAttempts; ///< = "Reconnect.Attempts"
513  static const char * ReconnectInterval; ///< = "Reconnect.Interval"
514  static const char * SendSpinningTimeout; ///< = "SendSpinningTimeout"
515  static const char * ThreadPoolAffinity; ///< = "ThreadPool.Affinity"
516  static const char * ThreadPoolSize; ///< = "ThreadPool.Size"
517  static const char * ThreadPoolPriority; ///< = "ThreadPool.Priority"
518  static const char * ThreadPoolPolicy; ///< = "ThreadPool.Policy"
519  static const char * SocketReceiveBufferSize; ///< = "Socket.ReceiveBufferSize"
520  static const char * SocketSendBufferSize; ///< = "Socket.SendBufferSize"
521  static const char * StorageDirectory; ///< = "Log.Directory"
522  };
523 
524 private:
525  void processLicenseStores(const std::string& licenseStore);
526 
527  std::string accessKey_;
528 
529  unsigned asyncFileBasedStorageQueueMaxSize_;
530 
531  CpuIndexes asyncFileBasedStorageThreadAffinity_;
532 
533  bool createEngineLogFile_;
534 
535  Messaging::UInt64 fileBasedStorageSegmentSize_;
536 
537  std::string firmId_;
538 
539  bool ignoreFileBasedStorageIntegrityErrors_;
540 
541  unsigned keepAliveInterval_;
542 
543  unsigned licenseAlertingDaysBeforeExpiration_;
544 
545  std::string licenseFilePath_;
546 
547  LicenseStores licenseStores_;
548 
549  std::string localNetworkInterface_;
550 
551  bool localTimeUsage_;
552 
553  bool logBeforeSending_;
554 
555  std::string logFileName_;
556 
557  unsigned messageGrouping_;
558 
559  unsigned reasonableTransmissionTime_;
560 
561  int receiveSpinningTimeout_;
562 
563  unsigned reconnectAttempts_;
564 
565  unsigned reconnectInterval_;
566 
567  std::string secretKey_;
568 
569  int sendSpinningTimeout_;
570 
571  std::string sessionId_;
572 
573  int socketReceiveBufferSize_;
574 
575  int socketSendBufferSize_;
576 
577  std::string storageDirectory_;
578 
579  bool tcpNoDelayOption_;
580 
581  ThreadingModel::Enum threadingModel_;
582 
583  CpuIndexes threadPoolAffinity_;
584 
585  int threadPoolPolicy_;
586 
587  int threadPoolPriority_;
588 
589  unsigned threadPoolSize_;
590 };
591 
592 }
593 }
594 }
static const unsigned MaxSpinningTimeoutUsec
The maximum spinning timeout (microseconds).
static const char * LicenseFile
= "LicenseFile"
const CpuIndexes & threadPoolAffinity() const
static const char * LogFileName
= "Log.FileName"
const std::string & firmId() const
const std::string & sessionId() const
static const char * KeepAliveInterval
= "KeepAliveInterval"
SessionSettings & addLicenseStore(const std::string &value)
Adds the path to the folder that contains license file(s).
static const char * SessionId
= "SessionId"
static const char * FileBasedStorageSegmentSize
= "FileBasedStorageSegmentSize"
static const char * LocalTimeUsage
= "LocalTimeUsage"
Each session has a sender thread and a receiving thread.
const LicenseStores & licenseStores() const
const std::string & localNetworkInterface() const
const CpuIndexes & asyncFileBasedStorageThreadAffinity() const
static const char * StorageDirectory
= "Log.Directory"
static const char * ThreadPoolPolicy
= "ThreadPool.Policy"
#define ONIXS_CONFLATEDTCP_EXPORTED
Definition: Compiler.h:187
SessionSettings & resetToDefaults()
Resets the settings to the default values.
static const char * LocalNetworkInterface
= "LocalNetworkInterface"
static const char * ReconnectInterval
= "Reconnect.Interval"
static const char * SendSpinningTimeout
= "SendSpinningTimeout"
static const char * TcpNoDelayOption
= "TcpNoDelayOption"
static const char * SecretKey
= "SecretKey"
static const char * LogBeforeSending
= "Log.BeforeSending"
static const char * LicenseStore
= "LicenseStore"
static const int UseOsDefaultSocketBufferSize
Specifies the usage of the operating system default socket buffer size.
static const char * LicenseAlertingDaysBeforeExpiration
= "LicenseAlertingDaysBeforeExpiration"
static const char * SocketSendBufferSize
= "Socket.SendBufferSize"
static const char * ReasonableTransmissionTime
= "ReasonableTransmissionTime"
Definition: Defines.h:40
const std::string & secretKey() const
SessionSettings & load(const std::string &configFile)
Loads the settings from the given configuration file.
static const char * ThreadPoolAffinity
= "ThreadPool.Affinity"
static const char * SocketReceiveBufferSize
= "Socket.ReceiveBufferSize"
std::set< CpuIndex > CpuIndexes
Definition: Defines.h:74
#define ONIXS_CONFLATEDTCP_NODISCARD
Definition: Compiler.h:198
SessionSettings & licenseAlertingDaysBeforeExpiration(unsigned days)
Sets the number of days to alert before the license expiration.
static const char * ReceiveSpinningTimeout
= "ReceiveSpinningTimeout"
const std::string & logFileName() const
static const char * ThreadingModel
= "ThreadingModel"
const std::string & accessKey() const
static const char * IgnoreFileBasedStorageIntegrityErrors
= "IgnoreFileBasedStorageIntegrityErrors"
static const char * ReconnectAttempts
= "Reconnect.Attempts"
The keys that are used to load settings from the configuration file.
Messaging::UInt64 fileBasedStorageSegmentSize() const
static const char * ThreadPoolSize
= "ThreadPool.Size"
const std::string & storageDirectory() const
static const char * ThreadPoolPriority
= "ThreadPool.Priority"
ThreadingModel::Enum threadingModel() const
static const char * AccessKey
= "AccessKey"
static const char * MessageGrouping
= "MessageGrouping"
static const char * AsyncFileBasedStorageThreadAffinity
= "AsyncFileBasedStorage.ThreadAffinity"
std::vector< std::string > LicenseStores
Folders that contain license file(s).
static const char * AsyncFileBasedStorageQueueMaxSize
= "AsyncFileBasedStorage.QueueMaxSize"
SessionSettings & licenseStore(const std::string &value)
Sets the path to the folder that contains license file(s).