morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::journal::IActionLog Struct Referenceabstract

Interface for durable storage of executed-action entries. More...

#include <action_log.hpp>

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

Public Member Functions

virtual void append (LogEntry entry)=0
 Appends entry. Implementations assign entry.seq.
virtual void flush ()=0
 Pushes any buffered entries to the durable backend. No-op for sinks with nothing to buffer (e.g. InMemoryActionLog).
virtual std::vector< LogEntry > entries (std::string_view entityKey={}) const =0
 Returns recorded entries in append order.
virtual ::morph::exec::IExecutor * owner () const noexcept
 The executor this log's state belongs to, or null for an implementation that has none.
::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

virtual ::morph::async::Completion< std::vector< LogEntry > > askEntries (::morph::exec::IExecutor &replyExec, std::string entityKey) const
 What entries(replyExec, entityKey) asks. The default reads entries(entityKey) where it is called, for an implementation with no owner; one with an owner reads there.
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

Interface for durable storage of executed-action entries.

Entries are never removed by the framework — this is a permanent, append-only record, unlike morph::offline::IOfflineQueue (whose markDone() deletes items once retried successfully). Implementations range from in-memory (InMemoryActionLog) to file, SQL, or network-backed stores supplied by the host application.

Idempotency-key dedup (optional)
An implementation MAY treat a non-empty LogEntry::idempotencyKey as a dedup key on append(): if an entry with the same key was already recorded, treat the call as a no-op. This is not required by the interface, but InMemoryActionLog and FileActionLog both do it, which is what makes them safe choices for journal::OutboxRelay::sink (see outbox.hpp) — a re-relayed row after a crash between append() and marking it relayed lands here twice but is stored once. An entry with an empty idempotencyKey is never deduped.

Definition at line 174 of file action_log.hpp.

Member Function Documentation

◆ append()

virtual void morph::journal::IActionLog::append ( LogEntry entry)
pure virtual

Appends entry. Implementations assign entry.seq.

An implementation that can fail to record the entry must throw. Returning normally is the sink's promise that the entry is recorded (or, for a buffering sink, that it will be by the next successful flush()); see flush() for why silence is not an option here.

Parameters
entryEntry to append.
Exceptions
std::exception(implementation-defined) if the entry could not be recorded.

Implemented in morph::journal::FileActionLog, morph::journal::InMemoryActionLog, and morph::journal::SessionLog.

◆ flush() [1/2]

virtual void morph::journal::IActionLog::flush ( )
pure virtual

Pushes any buffered entries to the durable backend. No-op for sinks with nothing to buffer (e.g. InMemoryActionLog).

Must throw if the data did not reach the backend. The return type is void, so throwing is the only channel an implementation has, and callers rely on it: OutboxRelay::relay() calls markRelayed() directly after this, and a silently-failed flush would mark rows relayed in the model's own store while nothing was durably written — dropping them from the outbox and from the log, with no error anywhere. An implementation that cannot fail (nothing to buffer) simply never throws.

Exceptions
std::exception(implementation-defined) if buffered entries could not be made durable.

Implemented in morph::journal::FileActionLog, morph::journal::InMemoryActionLog, and morph::journal::SessionLog.

◆ entries() [1/2]

virtual std::vector< LogEntry > morph::journal::IActionLog::entries ( std::string_view entityKey = {}) const
nodiscardpure virtual

Returns recorded entries in append order.

An implementation with an owner answers only there (see owner()); a caller elsewhere asks through entries(replyExec, entityKey).

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

Implemented in morph::journal::FileActionLog, morph::journal::InMemoryActionLog, and morph::journal::SessionLog.

◆ owner()

virtual ::morph::exec::IExecutor * morph::journal::IActionLog::owner ( ) const
inlinenodiscardvirtualnoexcept

The executor this log's state belongs to, or null for an implementation that has none.

Every log morph ships has one: its append() runs there (posted from anywhere else), and its entries()/flush() answer only there. What a caller on a model's strand names as the reply executor of entries(replyExec, …) or flush(replyExec).

Returns
The owner, or nullptr.

Reimplemented in morph::journal::FileActionLog, morph::journal::InMemoryActionLog, and morph::journal::SessionLog.

Definition at line 219 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]

::morph::async::Completion< bool > morph::journal::IActionLog::flush ( ::morph::exec::IExecutor & replyExec)
inlinenodiscard

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.

◆ askEntries()

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

What entries(replyExec, entityKey) asks. The default reads entries(entityKey) where it is called, for an implementation with no owner; one with an owner reads there.

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

Reimplemented in morph::journal::FileActionLog, morph::journal::InMemoryActionLog, and morph::journal::SessionLog.

Definition at line 256 of file action_log.hpp.

◆ askFlush()

virtual ::morph::async::Completion< bool > morph::journal::IActionLog::askFlush ( ::morph::exec::IExecutor & replyExec)
inlinenodiscardprotectedvirtual

What flush(replyExec) asks. The default flushes where it is called, for an implementation with no owner; one with an owner flushes there.

Parameters
replyExecWhere the answer is delivered.
Returns
true once durable, or the flush's error.

Reimplemented in morph::journal::FileActionLog.

Definition at line 274 of file action_log.hpp.


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