#include <data_batcher.h>
Public Member Functions | |
virtual bool | batchData (const T &data_to_batch) |
DataBatcher (size_t max_allowable_batch_size=DataBatcher::kDefaultMaxBatchSize, size_t trigger_size=DataBatcher::kDefaultTriggerSize, std::chrono::microseconds try_enqueue_duration=std::chrono::duration_cast< std::chrono::microseconds >(std::chrono::seconds(2))) | |
size_t | getCurrentBatchSize () |
size_t | getMaxAllowableBatchSize () |
size_t | getTriggerBatchSize () |
std::chrono::microseconds | getTryEnqueueDuration () |
virtual bool | publishBatchedData ()=0 |
void | resetBatchedData () |
void | resetTriggerBatchSize () |
void | setMaxAllowableBatchSize (int new_value) |
void | setTriggerBatchSize (size_t new_value) |
void | setTryEnqueueDuration (std::chrono::microseconds duration) |
bool | shutdown () override |
~DataBatcher () override=default | |
Public Member Functions inherited from Service | |
ServiceState | getState () |
virtual std::string | getStatusString () |
Service () | |
virtual bool | start () |
virtual | ~Service ()=default |
Static Public Member Functions | |
static void | validateConfigurableSizes (size_t batch_max_queue_size, size_t batch_trigger_publish_size) |
Static Public Attributes | |
static const size_t | kDefaultMaxBatchSize = 1024 |
static const size_t | kDefaultTriggerSize = SIZE_MAX |
Protected Member Functions | |
virtual void | emptyCollection () |
Protected Member Functions inherited from Service | |
void | setState (ServiceState new_state) |
Protected Attributes | |
std::shared_ptr< std::list< T > > | batched_data_ |
std::recursive_mutex | mtx |
Private Attributes | |
std::atomic< size_t > | max_allowable_batch_size_ {} |
std::atomic< size_t > | trigger_batch_size_ {} |
std::atomic< std::chrono::microseconds > | try_enqueue_duration_ {} |
Abstract class used to define a batching interface.
T | the type of data to be batched. |
Definition at line 37 of file data_batcher.h.
|
inline |
Create a DataBatcher instance
max_allowable_batch_size | if this limit is reached then the queue is emptied via the emptyCollection method |
trigger_size | if this limit is reached then the queue is emptied via the publish method |
try_enqueue_duration | maximum amount of time to attempt to empty queue during the publish method |
Definition at line 54 of file data_batcher.h.
|
overridedefault |
Destruct a DataBatcher instance
|
inlinevirtual |
Batch an item.
data_to_batch |
Definition at line 78 of file data_batcher.h.
|
inlineprotectedvirtual |
Safeguard in case the handleTriggerSize method does not properly drain the collection. This will clear the currently batched data. If other behavior is desired to empty the collection implementing classes should override.
Definition at line 231 of file data_batcher.h.
|
inline |
Return the number of currently batched items.
Definition at line 103 of file data_batcher.h.
|
inline |
Return the maximum allowable batch size. When this limit is reached the queue is emptied via the emptyCollection method.
Definition at line 146 of file data_batcher.h.
|
inline |
Return the trigger value. Note: this is set to kDefaultTriggerSize = SIZE_MAX by default, which means the trigger is not used and publish must be called manually.
Definition at line 135 of file data_batcher.h.
|
inline |
|
pure virtual |
|
inline |
Reset the batched data shared pointer.
Definition at line 112 of file data_batcher.h.
|
inline |
Reset the trigger batch size to the default value, which means the mechanism is no longer set. Publish will need to be called manually.
Definition at line 167 of file data_batcher.h.
|
inline |
Set the maximum allowable batch size. When this limit is reached the queue is emptied via the emptyCollection method.
max_allowable_batch_size |
Definition at line 156 of file data_batcher.h.
|
inline |
Set the trigger value, which will call the publish method when the number of batched items is greater than this limit. Note: this value must be strictly less than the max_allowable_batch_size_.
new_value |
Definition at line 123 of file data_batcher.h.
|
inline |
Set the maximum amount of time publish can attempt to empty the queue.
duration |
Definition at line 176 of file data_batcher.h.
|
inlineoverridevirtual |
Shutdown the batcher: this blocks until publish has completed in order to attempt to empty any unpublished data.
Reimplemented from Service.
Definition at line 217 of file data_batcher.h.
|
inlinestatic |
invalid | argument if the batch_trigger_publish_size is strictly greater than max_allowable_batch_size |
batch_max_queue_size | |
batch_trigger_publish_size |
Definition at line 202 of file data_batcher.h.
|
protected |
Definition at line 236 of file data_batcher.h.
|
static |
Definition at line 44 of file data_batcher.h.
|
static |
SIZE_MAX is used as the NOT set default.
Definition at line 43 of file data_batcher.h.
|
private |
Size used for the internal storage
Definition at line 243 of file data_batcher.h.
|
mutableprotected |
Definition at line 237 of file data_batcher.h.
|
private |
Definition at line 244 of file data_batcher.h.
|
private |
Definition at line 245 of file data_batcher.h.