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

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

#include <action_log.hpp>

Inheritance diagram for morph::journal::InMemoryActionLog:
morph::journal::IActionLog

Public Member Functions

 InMemoryActionLog (::morph::exec::IExecutor &owner)
 Constructs an empty log belonging to owner.
void append (LogEntry entry) override
 Appends entry, assigning a monotonically increasing seq, on the owner.
void flush () override
 No-op — there is no external backend to flush to. Callable anywhere.
std::vector< LogEntry > entries (std::string_view entityKey={}) const override
 Returns a snapshot of matching entries in append order. On the owner.
::morph::exec::IExecutor * owner () const noexcept override
 The executor given at construction.
::morph::async::Completion< std::vector< LogEntry > > entries (::morph::exec::IExecutor &replyExec, std::string entityKey={}) const
 Returns recorded entries in append order, read on the log's owner and delivered on replyExec.
::morph::async::Completion< bool > flush (::morph::exec::IExecutor &replyExec)
 Pushes buffered entries to the durable backend on the log's owner; the answer is delivered on replyExec.
Public Member Functions inherited from morph::journal::IActionLog
::morph::async::Completion< std::vector< LogEntry > > entries (::morph::exec::IExecutor &replyExec, std::string entityKey={}) const
 Returns recorded entries in append order, read on the log's owner and delivered on replyExec.
::morph::async::Completion< bool > flush (::morph::exec::IExecutor &replyExec)
 Pushes buffered entries to the durable backend on the log's owner; the answer is delivered on replyExec.

Protected Member Functions

::morph::async::Completion< std::vector< LogEntry > > askEntries (::morph::exec::IExecutor &replyExec, std::string entityKey) const override
 Reads the entries on the owner, delivered on replyExec.
Protected Member Functions inherited from morph::journal::IActionLog
virtual ::morph::async::Completion< bool > askFlush (::morph::exec::IExecutor &replyExec)
 What flush(replyExec) asks. The default flushes where it is called, for an implementation with no owner; one with an owner flushes there.

Detailed Description

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

Suitable for testing and for applications that do not need cross-process durability. Mirrors morph::offline::InMemoryOfflineQueue's shape. Dedups append() on a non-empty LogEntry::idempotencyKey — see IActionLog's class docs.

One owner
The entries belong to the executor given at construction, which must run one task at a time. append() runs there: at once when called on it, posted from anywhere else (a model's strand). entries() answers only on it; a caller elsewhere uses entries(replyExec, entityKey). See docs/spec/journal/journal.md, "One owner".

Definition at line 322 of file action_log.hpp.

Constructor & Destructor Documentation

◆ InMemoryActionLog()

morph::journal::InMemoryActionLog::InMemoryActionLog ( ::morph::exec::IExecutor & owner)
inlineexplicit

Constructs an empty log belonging to owner.

Parameters
ownerThe executor every access runs on; must run one task at a time. Borrowed: it must outlive this log and run what it posts.

Definition at line 330 of file action_log.hpp.

Member Function Documentation

◆ append()

void morph::journal::InMemoryActionLog::append ( LogEntry entry)
inlineoverridevirtual

Appends entry, assigning a monotonically increasing seq, on the owner.

Parameters
entryEntry to append; seq is overwritten regardless of the input value.

Implements morph::journal::IActionLog.

Definition at line 336 of file action_log.hpp.

◆ flush() [1/2]

void morph::journal::InMemoryActionLog::flush ( )
inlineoverridevirtual

No-op — there is no external backend to flush to. Callable anywhere.

Implements morph::journal::IActionLog.

Definition at line 347 of file action_log.hpp.

◆ entries() [1/2]

std::vector< LogEntry > morph::journal::InMemoryActionLog::entries ( std::string_view entityKey = {}) const
inlinenodiscardoverridevirtual

Returns a snapshot of matching entries in append order. On the owner.

Parameters
entityKeyIf non-empty, restricts the result to that entity's entries.
Returns
Matching entries, in append order.

Implements morph::journal::IActionLog.

Definition at line 352 of file action_log.hpp.

◆ owner()

::morph::exec::IExecutor * morph::journal::InMemoryActionLog::owner ( ) const
inlinenodiscardoverridevirtualnoexcept

The executor given at construction.

Returns
The owner.

Reimplemented from morph::journal::IActionLog.

Definition at line 358 of file action_log.hpp.

◆ askEntries()

::morph::async::Completion< std::vector< LogEntry > > morph::journal::InMemoryActionLog::askEntries ( ::morph::exec::IExecutor & replyExec,
std::string entityKey ) const
inlinenodiscardoverrideprotectedvirtual

Reads the entries on the owner, delivered on replyExec.

Parameters
replyExecWhere the answer is delivered.
entityKeyIf non-empty, restricts the result to that entity's entries.
Returns
The matching entries.

Reimplemented from morph::journal::IActionLog.

Definition at line 365 of file action_log.hpp.

◆ entries() [2/2]

::morph::async::Completion< std::vector< LogEntry > > morph::journal::IActionLog::entries ( ::morph::exec::IExecutor & replyExec,
std::string entityKey = {} ) const
inlinenodiscard

Returns recorded entries in append order, read on the log's owner and delivered on replyExec.

The form for a caller that is not on the owner: a model's strand, an application thread the log does not belong to. The read is ordered after every append() posted to the owner before it.

Parameters
replyExecWhere the answer is delivered, and where the caller attaches to it. Borrowed: it must outlive the completion.
entityKeyIf non-empty, restricts the result to that entity's entries.
Returns
The matching entries, in append order.

Definition at line 231 of file action_log.hpp.

◆ flush() [2/2]

Pushes buffered entries to the durable backend on the log's owner; the answer is delivered on replyExec.

The form of flush() for a caller that is not on the owner. It is ordered after every append() posted to the owner before it.

Parameters
replyExecWhere the answer is delivered. Borrowed: it must outlive the completion.
Returns
true once the entries are durable; rejected with the error flush() would have thrown.

Definition at line 245 of file action_log.hpp.


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