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

Sequences reconnect → activate → bind → replay when connectivity returns. More...

#include <reconnect_coordinator.hpp>

Classes

struct  Deps
 Injected, host-supplied side effects. None may be null. Each is called on the offline strand. More...

Public Types

using Config = ReconnectCoordinatorConfig
 Alias for the configuration struct.

Public Member Functions

 ReconnectCoordinator (Deps deps, ::morph::exec::IExecutor &executor, Config cfg=Config{})
 Constructs a coordinator with injected dependencies and tuning, running its sequences on a strand over executor.
 ~ReconnectCoordinator ()
 Closes the offline strand: a sequence not yet started is dropped, one running on another thread is waited for.
 ReconnectCoordinator (const ReconnectCoordinator &)=delete
ReconnectCoordinator & operator= (const ReconnectCoordinator &)=delete
 ReconnectCoordinator (ReconnectCoordinator &&)=delete
ReconnectCoordinator & operator= (ReconnectCoordinator &&)=delete
::morph::async::Completion< ReconnectOutcome > onOnline (::morph::exec::IExecutor &replyExec)
 Runs the reconnect → activate → bind → replay sequence on the offline strand.
void onOffline ()
 Switches to the local backend and rebinds context, on the offline strand.
::morph::exec::IExecutor & strand () noexcept
 The offline strand, as an executor: what a SyncWorker that replays for this coordinator is given as its owner.

Detailed Description

Sequences reconnect → activate → bind → replay when connectivity returns.

All side effects are injected via Deps. The coordinator contains only the retry loop, the ordering guarantees, and the abort checks. It performs no I/O and owns no thread: it owns a strand over the executor it is given, the offline strand, and runs onOnline()'s and onOffline()'s bodies there.

Ordering guarantee (the reason this class exists)
Within a successful onOnline(), the steps run in this strict order:
  1. tryReconnect() returns true (backend usable)
  2. activatePrimary() (make primary the active backend)
  3. bindContext() (rebind per-connection / per-session state)
  4. replay() (drain + replay the offline queue) Step 4 MUST NOT run before step 3 completes, and step 3 MUST NOT run before step 2. Implementations and tests should treat this as an invariant.
One owner
onOnline() posts its whole sequence, retry sleeps included, as one task on the offline strand; onOffline() posts its two steps as another. A strand runs one task at a time, in post order, so the two never overlap and an onOffline() can never land between bindContext() and replay(). Both are callable from any thread and return at once. The executor should be a worker pool, not the I/O loop that runs NetworkMonitor's callbacks: the retry sleeps block the thread the task runs on.

A SyncWorker given strand() as its owner drains inside the replay step when the step calls its run(), rather than after the task.

Definition at line 97 of file reconnect_coordinator.hpp.

Member Typedef Documentation

◆ Config

Alias for the configuration struct.

Definition at line 100 of file reconnect_coordinator.hpp.

Constructor & Destructor Documentation

◆ ReconnectCoordinator()

morph::offline::ReconnectCoordinator::ReconnectCoordinator ( Deps deps,
::morph::exec::IExecutor & executor,
Config cfg = Config{} )
inline

Constructs a coordinator with injected dependencies and tuning, running its sequences on a strand over executor.

Parameters
depsSide-effect callbacks (all required, none null).
executorWhere the offline strand's tasks run: a worker pool. Borrowed: it must outlive this coordinator and keep running tasks until the coordinator is destroyed.
cfgRetry tuning.

A null Deps member is logged via morph::log::logError in all builds; construction still succeeds. Invoking the coordinator with any null member is undefined behaviour.

Definition at line 152 of file reconnect_coordinator.hpp.

◆ ~ReconnectCoordinator()

morph::offline::ReconnectCoordinator::~ReconnectCoordinator ( )
inline

Closes the offline strand: a sequence not yet started is dropped, one running on another thread is waited for.

Definition at line 159 of file reconnect_coordinator.hpp.

Member Function Documentation

◆ onOnline()

::morph::async::Completion< ReconnectOutcome > morph::offline::ReconnectCoordinator::onOnline ( ::morph::exec::IExecutor & replyExec)
inline

Runs the reconnect → activate → bind → replay sequence on the offline strand.

Posted as one task, after any onOnline()/onOffline() posted before it. Callable from any thread; returns at once.

Parameters
replyExecExecutor the outcome is delivered on and the caller attaches its callbacks on: the caller's own, or strand() for a caller that does not wait for it. Borrowed: it must outlive the returned Completion.
Returns
A Completion settled on the offline strand with how the sequence ended (see ReconnectOutcome), delivered on replyExec.

Definition at line 179 of file reconnect_coordinator.hpp.

◆ onOffline()

void morph::offline::ReconnectCoordinator::onOffline ( )
inline

Switches to the local backend and rebinds context, on the offline strand.

Idempotent at the policy level: safe to call when already local. Posted after any onOnline()/onOffline() posted before it. Callable from any thread; returns at once.

Definition at line 195 of file reconnect_coordinator.hpp.

◆ strand()

::morph::exec::IExecutor & morph::offline::ReconnectCoordinator::strand ( )
inlinenodiscardnoexcept

The offline strand, as an executor: what a SyncWorker that replays for this coordinator is given as its owner.

Returns
The strand every onOnline()/onOffline() body runs on.

Definition at line 207 of file reconnect_coordinator.hpp.


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