Base type for a collection of delayed submissions. More...
#include <delayed_submission.h>
Public Member Functions | |
BaseDelayedSubmissionCollection (const std::string name, const bool enabled) | |
Constructor for a thread-safe delayed submission collection. More... | |
BaseDelayedSubmissionCollection (const BaseDelayedSubmissionCollection &)=delete | |
BaseDelayedSubmissionCollection & | operator= (BaseDelayedSubmissionCollection const &)=delete |
BaseDelayedSubmissionCollection (BaseDelayedSubmissionCollection &&o)=delete | |
BaseDelayedSubmissionCollection & | operator= (BaseDelayedSubmissionCollection &&o)=delete |
virtual ItemIdType | schedule (T item) |
Register a callable or complex-type for delayed submission. More... | |
void | process () |
Process all pending callbacks. More... | |
void | cancel (ItemIdType id) |
Cancel a pending callback. More... | |
Protected Member Functions | |
virtual void | scheduleLog (ItemIdType id, T item)=0 |
Log message during schedule() . More... | |
virtual void | processItem (ItemIdType id, T item)=0 |
Process a single item during process() . More... | |
Protected Attributes | |
std::string | _name {"undefined"} |
The human-readable name of the collection, used for logging. | |
bool | _enabled {true} |
Whether the resource required to process the collection is enabled. | |
ItemIdType | _itemId {0} |
The item ID counter, used to allow cancelation. | |
std::optional< ItemIdType > | _processing |
The ID of the item being processed, if any. More... | |
std::deque< std::pair< ItemIdType, T > > | _collection {} |
The collection. | |
std::set< ItemIdType > | _canceled {} |
IDs of canceled items. | |
std::mutex | _mutex {} |
Mutex to provide access to _collection . | |
Base type for a collection of delayed submissions.
Base type for a collection of delayed submission. Delayed submissions may have different purposes and this class encapsulates generic data for all derived types.
|
inlineexplicit |
Constructor for a thread-safe delayed submission collection.
Construct a thread-safe delayed submission collection. A delayed submission collection provides two operations: schedule and process. The schedule()
method will push an operation into the collection, whereas the process()
will invoke all callbacks that were previously pushed into the collection and clear the collection.
[in] | name | human-readable name of the collection, used for logging. |
[in] | enabled | whether the resource is enabled, if false an exception is raised when attempting to schedule a callable. Disabled instances of this class should only be used to provide a consistent interface among implementations. |
|
inline |
Cancel a pending callback.
Cancel a pending callback and thus do not execute it, unless the execution has already begun, in which case cancelation cannot be done.
std::runtime_error | if the item is being processed and canceling is not possible anymore. |
[in] | id | the ID of the scheduled item, as returned by schedule() . |
|
inline |
Process all pending callbacks.
Process all pending generic. Generic callbacks are deemed completed when their execution completes.
|
protectedpure virtual |
Process a single item during process()
.
Method called by process()
to process a single item of the collection.
[in] | id | the ID of the scheduled item, as returned by schedule() . |
[in] | item | the callback that was passed as argument to schedule() when the first registered. |
Implemented in ucxx::RequestDelayedSubmissionCollection, and ucxx::GenericDelayedSubmissionCollection.
|
inlinevirtual |
Register a callable or complex-type for delayed submission.
Register a simple callback, or complex-type with a callback (requires specialization), for delayed submission that will be executed when the request is in fact submitted when process()
is called.
Raise an exception if false
was specified as the enabled
argument to the constructor.
std::runtime_error | if _enabled is false . |
[in] | item | the callback that will be executed by process() when the operation is submitted. |
|
protectedpure virtual |
Log message during schedule()
.
Log a specialized message while schedule()
is being executed.
[in] | id | the ID of the scheduled item, as returned by schedule() . |
[in] | item | the callback that was passed as argument to schedule() . |
Implemented in ucxx::RequestDelayedSubmissionCollection, and ucxx::GenericDelayedSubmissionCollection.
|
protected |
The ID of the item being processed, if any.