|
24 | 24 | namespace Bloomberg { |
25 | 25 | namespace quantum { |
26 | 26 |
|
| 27 | +//============================================================================================== |
| 28 | +// class ConfigurationSchemaProvider |
| 29 | +//============================================================================================== |
| 30 | +/// @class ConfigurationSchemaProvider |
| 31 | +/// @brief Provides static accessors to a json schema representing a Configuration object |
| 32 | +struct ConfigurationSchemaProvider |
| 33 | +{ |
| 34 | + /// @brief Get the JSON schema corresponding to this configuration object. |
| 35 | + /// @return The draft-04 compatible schema. |
| 36 | + static const std::string& getJsonSchema(); |
| 37 | + |
| 38 | + /// @brief Get the schema URI used to resolve remote JSON references '$ref'. |
| 39 | + /// @return The URI. |
| 40 | + static const std::string& getJsonSchemaUri(); |
| 41 | +}; |
| 42 | + |
27 | 43 | //============================================================================================== |
28 | 44 | // class Configuration |
29 | 45 | //============================================================================================== |
30 | 46 | /// @class class Configuration. |
31 | 47 | /// @brief Configuration parameters for the Quantum library. |
32 | | -class Configuration |
| 48 | +class Configuration : public ConfigurationSchemaProvider |
33 | 49 | { |
34 | 50 | public: |
35 | 51 | enum class BackoffPolicy : int { |
36 | 52 | Linear = QUANTUM_BACKOFF_LINEAR, ///< Linear backoff |
37 | 53 | Exponential = QUANTUM_BACKOFF_EXPONENTIAL ///< Exponential backoff (doubles every time) |
38 | 54 | }; |
39 | | - /// @brief Get the JSON schema corresponding to this configuration object. |
40 | | - /// @return The draft-04 compatible schema. |
41 | | - static const std::string& getJsonSchema(); |
42 | | - |
43 | | - /// @brief Get the schema URI used to resolve remote JSON references '$ref'. |
44 | | - /// @return The URI. |
45 | | - static const std::string& getJsonSchemaUri(); |
46 | 55 |
|
47 | 56 | /// @brief Set the number of threads running coroutines. |
48 | 57 | /// @param[in] num The number of threads. Set to -1 to have one coroutine thread per core. |
49 | 58 | /// Default is -1. |
50 | | - void setNumCoroutineThreads(int num); |
| 59 | + /// @return A reference to itself |
| 60 | + Configuration& setNumCoroutineThreads(int num); |
51 | 61 |
|
52 | 62 | /// @brief Set the number of threads running IO tasks. |
53 | 63 | /// @param[in] num The number of threads. Default is 5. |
54 | | - void setNumIoThreads(int num); |
| 64 | + /// @return A reference to itself |
| 65 | + Configuration& setNumIoThreads(int num); |
55 | 66 |
|
56 | 67 | /// @brief Indicate if coroutine threads should be pinned to a core. |
57 | 68 | /// @param[in] value True or False. Default is False. |
58 | 69 | /// @note For best performance, the number of coroutine threads should |
59 | 70 | /// be <= the number of cores in the system. |
60 | | - void setPinCoroutineThreadsToCores(bool value); |
| 71 | + /// @return A reference to itself |
| 72 | + Configuration& setPinCoroutineThreadsToCores(bool value); |
61 | 73 |
|
62 | | - /// @brief Load balancee the shared IO queues. |
| 74 | + /// @brief Load balance the shared IO queues. |
63 | 75 | /// @param[in] value If set to true, posting to the 'any' IO queue will result in |
64 | 76 | /// the load being spread among N queues. This mode can provide higher |
65 | 77 | /// throughput if dealing with high task loads. Default is false. |
66 | 78 | /// @note To achieve higher performance, the threads run in polling mode which |
67 | 79 | /// increases CPU usage even when idle. |
68 | | - void setLoadBalanceSharedIoQueues(bool value); |
| 80 | + /// @return A reference to itself |
| 81 | + Configuration& setLoadBalanceSharedIoQueues(bool value); |
69 | 82 |
|
70 | 83 | /// @brief Set the interval between IO thread polls. |
71 | 84 | /// @param[in] interval Interval in milliseconds. Default is 100ms. |
72 | 85 | /// @note Setting this to a higher value means it may take longer to react to the first |
73 | 86 | /// IO task posted, and vice-versa if the interval is lower. |
74 | | - void setLoadBalancePollIntervalMs(std::chrono::milliseconds interval); |
| 87 | + /// @return A reference to itself |
| 88 | + Configuration& setLoadBalancePollIntervalMs(std::chrono::milliseconds interval); |
75 | 89 |
|
76 | 90 | /// @brief Set a backoff policy for the shared queue polling interval. |
77 | 91 | /// @param[in] policy The backoff policy to use. Default is 'Linear'. |
78 | | - void setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy); |
| 92 | + /// @return A reference to itself |
| 93 | + Configuration& setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy); |
79 | 94 |
|
80 | 95 | /// @brief Set the number of backoffs. |
81 | 96 | /// @param[in] numBackoffs The number of backoff increments. Default is 0. |
82 | 97 | /// When the number of backoffs is reached, the poll interval remains unchanged thereafter. |
83 | | - void setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs); |
| 98 | + /// @return A reference to itself |
| 99 | + Configuration& setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs); |
84 | 100 |
|
85 | 101 | /// @brief Sets the range of coroutine queueIds covered by IQueue::QueueId::Any when using Dispatcher::post |
86 | 102 | /// @param[in] coroQueueIdRangeForAny The range [minQueueId, maxQueueId] of queueIds that IQueue::QueueId::Any |
87 | 103 | /// will cover. |
88 | 104 | /// @remark if the provided range is empty or invalid, then the default range of |
89 | 105 | /// std::pair<int, int>(0, getNumCoroutineThreads()-1) will be used |
90 | | - void setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny); |
| 106 | + /// @return A reference to itself |
| 107 | + Configuration& setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny); |
91 | 108 |
|
92 | 109 | /// @brief Enables or disables the shared-coro-queue-for-any settings |
93 | 110 | /// @param[in] isSharedCoroQueueForAny sets the shared-coro-queue-for any setting |
94 | 111 | /// @warning When the coroutine sharing feature is enabled, then after each yield |
95 | 112 | /// (explicit or implicit) a coroutine sent to the Any queue may be executed by |
96 | 113 | /// a different thread. As a result, coroutines using thread-local-storage (e.g., via thread_local), |
97 | 114 | /// will _not_ work as expected. |
98 | | - void setCoroutineSharingForAny(bool sharing); |
| 115 | + /// @return A reference to itself |
| 116 | + Configuration& setCoroutineSharingForAny(bool sharing); |
99 | 117 |
|
100 | 118 | /// @brief Get the number of coroutine threads. |
101 | 119 | /// @return The number of threads. |
|
0 commit comments