All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ucxx::BaseDelayedSubmissionCollection< T > Class Template Referenceabstract

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
 
BaseDelayedSubmissionCollectionoperator= (BaseDelayedSubmissionCollection const &)=delete
 
 BaseDelayedSubmissionCollection (BaseDelayedSubmissionCollection &&o)=delete
 
BaseDelayedSubmissionCollectionoperator= (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.
 

Detailed Description

template<typename T>
class ucxx::BaseDelayedSubmissionCollection< T >

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.

Constructor & Destructor Documentation

◆ BaseDelayedSubmissionCollection()

template<typename T >
ucxx::BaseDelayedSubmissionCollection< T >::BaseDelayedSubmissionCollection ( const std::string  name,
const bool  enabled 
)
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.

Parameters
[in]namehuman-readable name of the collection, used for logging.
[in]enabledwhether 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.

Member Function Documentation

◆ cancel()

template<typename T >
void ucxx::BaseDelayedSubmissionCollection< T >::cancel ( ItemIdType  id)
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.

Exceptions
std::runtime_errorif the item is being processed and canceling is not possible anymore.
Parameters
[in]idthe ID of the scheduled item, as returned by schedule().

◆ process()

template<typename T >
void ucxx::BaseDelayedSubmissionCollection< T >::process ( )
inline

Process all pending callbacks.

Process all pending generic. Generic callbacks are deemed completed when their execution completes.

◆ processItem()

template<typename T >
virtual void ucxx::BaseDelayedSubmissionCollection< T >::processItem ( ItemIdType  id,
item 
)
protectedpure virtual

Process a single item during process().

Method called by process() to process a single item of the collection.

Parameters
[in]idthe ID of the scheduled item, as returned by schedule().
[in]itemthe callback that was passed as argument to schedule() when the first registered.

Implemented in ucxx::RequestDelayedSubmissionCollection, and ucxx::GenericDelayedSubmissionCollection.

◆ schedule()

template<typename T >
virtual ItemIdType ucxx::BaseDelayedSubmissionCollection< T >::schedule ( item)
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.

Exceptions
std::runtime_errorif _enabled is false.
Parameters
[in]itemthe callback that will be executed by process() when the operation is submitted.
Returns
the ID of the scheduled item which can be used cancelation requests.

◆ scheduleLog()

template<typename T >
virtual void ucxx::BaseDelayedSubmissionCollection< T >::scheduleLog ( ItemIdType  id,
item 
)
protectedpure virtual

Log message during schedule().

Log a specialized message while schedule() is being executed.

Parameters
[in]idthe ID of the scheduled item, as returned by schedule().
[in]itemthe callback that was passed as argument to schedule().

Implemented in ucxx::RequestDelayedSubmissionCollection, and ucxx::GenericDelayedSubmissionCollection.

Member Data Documentation

◆ _processing

template<typename T >
std::optional<ItemIdType> ucxx::BaseDelayedSubmissionCollection< T >::_processing
protected
Initial value:
{
std::nullopt}

The ID of the item being processed, if any.


The documentation for this class was generated from the following file: