morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::offline::InMemoryOfflineQueue Class Reference

In-memory implementation of IOfflineQueue, owned by one executor. More...

#include <offline_queue.hpp>

Inheritance diagram for morph::offline::InMemoryOfflineQueue:
morph::offline::IOfflineQueue

Public Member Functions

 InMemoryOfflineQueue (::morph::exec::IExecutor &owner, std::optional< std::size_t > maxDepth=std::nullopt)
 Constructs an in-memory queue belonging to owner, optionally bounded.
uint64_t enqueue (std::string payload) override
 Appends payload and returns a monotonically increasing id. On the owner.
uint64_t enqueue (std::string payload, std::string idempotencyKey) override
 Appends payload carrying idempotencyKey and returns a monotonically increasing id. On the owner.
std::vector< QueueItem > drain () const override
 Returns a snapshot of all pending items. On the owner.
std::size_t size () const override
 Returns the number of pending items. On the owner.
std::optional< std::size_t > maxDepth () const override
 Returns the configured maximum depth, or std::nullopt if unbounded. Callable anywhere: fixed at construction.
void markDone (uint64_t itemId) override
 Removes the item with itemId from the queue, on the owner.
void setAttempts (uint64_t itemId, Attempts attempts) override
 Updates the persisted attempt count on the in-deque item with itemId, on the owner. No-op if itemId is not found.
::morph::async::Completion< std::vector< QueueItem > > drain (::morph::exec::IExecutor &replyExec) const
 Snapshots the pending items on the queue's owner; delivered on replyExec.
::morph::async::Completion< uint64_t > enqueue (::morph::exec::IExecutor &replyExec, std::string payload, std::string idempotencyKey={})
 Appends payload carrying idempotencyKey on the queue's owner; the new item's id is delivered on replyExec.
::morph::async::Completion< std::size_t > size (::morph::exec::IExecutor &replyExec) const
 Counts the pending items on the queue's owner; delivered on replyExec.
Public Member Functions inherited from morph::offline::IOfflineQueue
::morph::async::Completion< uint64_t > enqueue (::morph::exec::IExecutor &replyExec, std::string payload, std::string idempotencyKey={})
 Appends payload carrying idempotencyKey on the queue's owner; the new item's id is delivered on replyExec.
::morph::async::Completion< std::vector< QueueItem > > drain (::morph::exec::IExecutor &replyExec) const
 Snapshots the pending items on the queue's owner; delivered on replyExec.
::morph::async::Completion< std::size_t > size (::morph::exec::IExecutor &replyExec) const
 Counts the pending items on the queue's owner; delivered on replyExec.

Protected Member Functions

::morph::async::Completion< uint64_t > askEnqueue (::morph::exec::IExecutor &replyExec, std::string payload, std::string idempotencyKey) override
 Enqueues on the owner, answered on replyExec.
::morph::async::Completion< std::vector< QueueItem > > askDrain (::morph::exec::IExecutor &replyExec) const override
 Snapshots on the owner, answered on replyExec.
::morph::async::Completion< std::size_t > askSize (::morph::exec::IExecutor &replyExec) const override
 Counts on the owner, answered on replyExec.
Protected Member Functions inherited from morph::offline::IOfflineQueue
virtual void setIdempotencyKey (uint64_t itemId, std::string idempotencyKey)
 Stamps an idempotency key onto an already-enqueued item.

Detailed Description

In-memory implementation of IOfflineQueue, owned by one executor.

Suitable for testing and for applications that do not require persistence across process restarts. Items are stored in a std::deque that belongs to the executor given at construction (see IOfflineQueue, "One owner").

Definition at line 425 of file offline_queue.hpp.

Constructor & Destructor Documentation

◆ InMemoryOfflineQueue()

morph::offline::InMemoryOfflineQueue::InMemoryOfflineQueue ( ::morph::exec::IExecutor & owner,
std::optional< std::size_t > maxDepth = std::nullopt )
inlineexplicit

Constructs an in-memory queue belonging to owner, optionally bounded.

Parameters
ownerThe executor every access runs on; must run one task at a time. Borrowed: it must outlive this queue and run what it posts.
maxDepthMaximum number of pending items enqueue() will admit before throwing OfflineQueueFullError; std::nullopt (the default) means unbounded.

Definition at line 437 of file offline_queue.hpp.

Member Function Documentation

◆ enqueue() [1/3]

uint64_t morph::offline::InMemoryOfflineQueue::enqueue ( std::string payload)
inlinenodiscardoverridevirtual

Appends payload and returns a monotonically increasing id. On the owner.

Parameters
payloadSerialised action to store.
Returns
Unique id for this item.

Implements morph::offline::IOfflineQueue.

Definition at line 444 of file offline_queue.hpp.

◆ enqueue() [2/3]

uint64_t morph::offline::InMemoryOfflineQueue::enqueue ( std::string payload,
std::string idempotencyKey )
inlinenodiscardoverridevirtual

Appends payload carrying idempotencyKey and returns a monotonically increasing id. On the owner.

Parameters
payloadSerialised action to store.
idempotencyKeyStable dedup token; stored verbatim on the item.
Returns
Unique id for this item.
Exceptions
OfflineQueueFullErrorif the queue is already at maxDepth().

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 452 of file offline_queue.hpp.

◆ drain() [1/2]

std::vector< QueueItem > morph::offline::InMemoryOfflineQueue::drain ( ) const
inlinenodiscardoverridevirtual

Returns a snapshot of all pending items. On the owner.

Returns
Copy of all items in insertion order.

Implements morph::offline::IOfflineQueue.

Definition at line 459 of file offline_queue.hpp.

◆ size() [1/2]

std::size_t morph::offline::InMemoryOfflineQueue::size ( ) const
inlinenodiscardoverridevirtual

Returns the number of pending items. On the owner.

Returns
Current pending item count.

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 466 of file offline_queue.hpp.

◆ maxDepth()

std::optional< std::size_t > morph::offline::InMemoryOfflineQueue::maxDepth ( ) const
inlinenodiscardoverridevirtual

Returns the configured maximum depth, or std::nullopt if unbounded. Callable anywhere: fixed at construction.

Returns
The capacity enqueue() enforces, or std::nullopt if none.

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 471 of file offline_queue.hpp.

◆ markDone()

void morph::offline::InMemoryOfflineQueue::markDone ( uint64_t itemId)
inlineoverridevirtual

Removes the item with itemId from the queue, on the owner.

No-op if itemId is not found.

Parameters
itemIdId of the item to remove.

Implements morph::offline::IOfflineQueue.

Definition at line 477 of file offline_queue.hpp.

◆ setAttempts()

void morph::offline::InMemoryOfflineQueue::setAttempts ( uint64_t itemId,
Attempts attempts )
inlineoverridevirtual

Updates the persisted attempt count on the in-deque item with itemId, on the owner. No-op if itemId is not found.

InMemoryOfflineQueue does not itself survive a process restart, but overriding this hook lets a fresh SyncWorker constructed over the same instance observe a durable-style cumulative attempt count — used to simulate cross-restart dead-lettering in tests.

Parameters
itemIdId of the item to update.
attemptsNew attempt count to store.

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 496 of file offline_queue.hpp.

◆ askEnqueue()

::morph::async::Completion< uint64_t > morph::offline::InMemoryOfflineQueue::askEnqueue ( ::morph::exec::IExecutor & replyExec,
std::string payload,
std::string idempotencyKey )
inlinenodiscardoverrideprotectedvirtual

Enqueues on the owner, answered on replyExec.

Parameters
replyExecWhere the answer is delivered.
payloadSerialised action to store.
idempotencyKeyStable dedup token; may be empty.
Returns
The new item's id, or OfflineQueueFullError.

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 512 of file offline_queue.hpp.

◆ askDrain()

::morph::async::Completion< std::vector< QueueItem > > morph::offline::InMemoryOfflineQueue::askDrain ( ::morph::exec::IExecutor & replyExec) const
inlinenodiscardoverrideprotectedvirtual

Snapshots on the owner, answered on replyExec.

Parameters
replyExecWhere the answer is delivered.
Returns
The pending items.

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 525 of file offline_queue.hpp.

◆ askSize()

::morph::async::Completion< std::size_t > morph::offline::InMemoryOfflineQueue::askSize ( ::morph::exec::IExecutor & replyExec) const
inlinenodiscardoverrideprotectedvirtual

Counts on the owner, answered on replyExec.

Parameters
replyExecWhere the answer is delivered.
Returns
The pending item count.

Reimplemented from morph::offline::IOfflineQueue.

Definition at line 535 of file offline_queue.hpp.

◆ drain() [2/2]

Snapshots the pending items on the queue's owner; delivered on replyExec.

Parameters
replyExecWhere the answer is delivered. Borrowed: it must outlive the completion.
Returns
What drain() would have returned.

Definition at line 335 of file offline_queue.hpp.

◆ enqueue() [3/3]

::morph::async::Completion< uint64_t > morph::offline::IOfflineQueue::enqueue ( ::morph::exec::IExecutor & replyExec,
std::string payload,
std::string idempotencyKey = {} )
inlinenodiscard

Appends payload carrying idempotencyKey on the queue's owner; the new item's id is delivered on replyExec.

The form of enqueue() for a caller that is not on the queue's owner. A full queue rejects the completion with OfflineQueueFullError.

Parameters
replyExecWhere the answer is delivered, and where the caller attaches to it. Borrowed: it must outlive the completion.
payloadSerialised action to persist.
idempotencyKeyStable dedup token for the logical op; may be empty.
Returns
The id enqueue(payload, idempotencyKey) would have returned, or the error it would have thrown.

Definition at line 325 of file offline_queue.hpp.

◆ size() [2/2]

Counts the pending items on the queue's owner; delivered on replyExec.

Parameters
replyExecWhere the answer is delivered. Borrowed: it must outlive the completion.
Returns
What size() would have returned.

Definition at line 345 of file offline_queue.hpp.


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