|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
Full-fidelity, in-memory log of one model instance's executed actions. More...
#include <journal.hpp>
Public Member Functions | |
| SessionLog (::morph::exec::IExecutor &owner) | |
Constructs an empty session log belonging to owner. | |
| void | append (LogEntry entry) override |
Appends entry, assigning a monotonically increasing seq, on the owner. | |
| void | flush () override |
| No-op — checkpoint() is this class's real commit point. Callable anywhere. | |
| std::vector< LogEntry > | entries (std::string_view entityKey={}) const override |
| Returns the full history (or one entity's slice of it) in append order. On the owner. | |
| ::morph::exec::IExecutor * | owner () const noexcept override |
| The executor given at construction. | |
| std::unique_ptr<::morph::model::detail::IModelHolder > | undoLast (std::string_view modelTypeId, ::morph::model::detail::ModelRegistryFactory ®istry=::morph::model::detail::defaultRegistry(), ::morph::model::detail::ActionDispatcher &dispatcher=::morph::model::detail::defaultDispatcher()) |
| Drops the most recently appended entry and replays everything that remains against a fresh model instance, reconstructing the state the model was in immediately before that entry executed. On the owner. | |
| void | checkpoint (IActionLog &durableSink, ::morph::model::detail::ActionDispatcher &dispatcher=::morph::model::detail::defaultDispatcher()) |
Coalesces entries appended since the last checkpoint and forwards the reduced set, in order, to durableSink; then flushes it. On the owner. | |
| ::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 history 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. | |
Full-fidelity, in-memory log of one model instance's executed actions.
Attach directly via IModelHolder::attachActionLog — every successfully executed loggable action is appended here in order, regardless of any ActionLogPolicy::coalesce setting. This full history is the raw material for undoLast(). checkpoint() is the one place coalescing actually happens: entries accumulated since the last checkpoint are reduced by (modelType, entityKey, actionType) — keeping only the latest occurrence where the action's policy says coalesce == true, keeping every occurrence otherwise — and only that reduced set reaches the durable sink.
Definition at line 338 of file journal.hpp.
|
inlineexplicit |
Constructs an empty session log belonging to owner.
| owner | The 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 346 of file journal.hpp.
|
inlineoverridevirtual |
Appends entry, assigning a monotonically increasing seq, on the owner.
Always full fidelity: this is what undoLast() walks back through, so nothing is coalesced or dropped here.
| entry | Entry to append; seq is overwritten regardless of the input value. |
Implements morph::journal::IActionLog.
Definition at line 355 of file journal.hpp.
|
inlineoverridevirtual |
No-op — checkpoint() is this class's real commit point. Callable anywhere.
Implements morph::journal::IActionLog.
Definition at line 363 of file journal.hpp.
|
inlinenodiscardoverridevirtual |
Returns the full history (or one entity's slice of it) in append order. On the owner.
| entityKey | If non-empty, restricts the result to that entity's entries. |
Implements morph::journal::IActionLog.
Definition at line 369 of file journal.hpp.
|
inlinenodiscardoverridevirtualnoexcept |
The executor given at construction.
Reimplemented from morph::journal::IActionLog.
Definition at line 375 of file journal.hpp.
|
inline |
Drops the most recently appended entry and replays everything that remains against a fresh model instance, reconstructing the state the model was in immediately before that entry executed. On the owner.
No inverse/undo operations are needed on the action types themselves — this reuses replay() over a shorter prefix of the same log. A no-op (returns a freshly created, un-replayed holder) if the log is empty.
Undo only rewinds this in-memory history; it never moves the checkpoint watermark, which is keyed by entry seq (see checkpoint()). Undoing an entry a prior checkpoint() already forwarded does not un-forward it: the durable sink is append-only, so that entry stays durable while the reconstructed history diverges from it. A later checkpoint() never re-forwards a coalesced-away, already-committed entry. Applications that need to durably reverse a checkpointed action must record a compensating action, not rely on undoLast().
Replays through replay() with its default payload-schema settings. That gate cannot fire here in practice: the entries being replayed were appended by this same process, so their fingerprints are this build's by construction. Undo is not a cross-version path.
Synchronous: it returns the reconstructed holder, and its caller — the application — is the owner.
| modelTypeId | String type-id of the model to reconstruct. |
| registry | Model factory registry; defaults to the process-level singleton. |
| dispatcher | Action dispatcher; defaults to the process-level singleton. |
Definition at line 406 of file journal.hpp.
|
inline |
Coalesces entries appended since the last checkpoint and forwards the reduced set, in order, to durableSink; then flushes it. On the owner.
Advances the checkpoint watermark (the seq of the last committed entry) before forwarding, so the batch is consumed even if durableSink's append() or flush() throws: a checkpoint is a forward-only commit point (at-most-once), not a transaction to retry. A no-op if nothing has been appended since the last checkpoint.
| durableSink | Receives only the coalesced entries — never the raw stream. Driven from this log's owner, so it must share it: its flush() answers only on its own owner. |
| dispatcher | Supplies each action's coalesce policy; defaults to the process-level singleton (the same one actions were registered against via BRIDGE_REGISTER_ACTION). |
Definition at line 443 of file journal.hpp.
|
inlinenodiscardoverrideprotectedvirtual |
Reads the history on the owner, delivered on replyExec.
| replyExec | Where the answer is delivered. |
| entityKey | If non-empty, restricts the result to that entity's entries. |
Reimplemented from morph::journal::IActionLog.
Definition at line 473 of file journal.hpp.
|
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.
| replyExec | Where the answer is delivered, and where the caller attaches to it. Borrowed: it must outlive the completion. |
| entityKey | If non-empty, restricts the result to that entity's entries. |
Definition at line 231 of file action_log.hpp.
|
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.
| replyExec | Where the answer is delivered. Borrowed: it must outlive the completion. |
Definition at line 245 of file action_log.hpp.