OnixS C++ FIX Engine  4.12.0
API Documentation
Throttler.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 
22 #include <cstddef>
23 
24 #include <OnixS/FIXEngine/ABI.h>
25 
26 namespace OnixS {
27 namespace FIX {
28 
29 /// The throttler class to perform the throttling.
31 {
32 public:
33 
34  /// The constructor.
35  ///
36  /// @param messagesCount The message limit per time unit.
37  /// @param intervalInMs The time interval to limit messages.
38  Throttler(size_t messagesCount, size_t intervalInMs = 1000);
39 
40  /// The destructor.
41  ~Throttler();
42 
43  /// Performs the throttling. This method must be called before each action that should be throttled.
44  /// If the count of messages per time unit exceeds the throttling limit, the function will be blocked until the given time interval is passed.
45  void throttle();
46 
47  /// Checks the throttling. This method must be called before each action that should be throttled.
48  /// If the count of messages per time unit exceeds the throttling limit, the function returns the delay (in milliseconds) until the action becomes possible. Otherwise, it returns 0.
49  ///
50  /// @param resetWhenDelay The flag indicates if the calculation of messages per throttling interval should be reset and started again when a delay is returned.
51  size_t tryThrottle(bool resetWhenDelay = false);
52 
53  /// Resets the throttling parameters.
54  ///
55  /// @param messagesCount The message limit per time unit.
56  /// @param intervalInMs The time interval to limit messages.
57  void reset(size_t messagesCount, size_t intervalInMs = 1000);
58 
59 private:
60 
61  Throttler(const Throttler &);
62  Throttler & operator = (const Throttler &);
63 
64  class Impl;
65  Impl * const impl_;
66 };
67 
68 }
69 }
The throttler class to perform the throttling.
Definition: Throttler.h:30
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45