Skip to main content
Table of Contents

Interface IProjectionReplayState

Namespace
Stratara.Abstractions.Projections
Assembly
Stratara.Abstractions.dll

In-memory coordination handle for the projection-replay state-machine. Dispatchers and readers query IsReplayActive to hold back while a replay runs; admin endpoints request a replay with RequestReplay(Guid) and watch it with GetProgress().

public interface IProjectionReplayState
Extension Methods

Remarks

Implementations should be process-singleton and thread-safe; the replay handshake crosses worker boundaries via the SubscribeToReplayRequestAsync(Func<Guid, Task>, CancellationToken) + RequestReplay(Guid) channel. IsReplayActive is read on every dispatch, every publication and every catch-up, so an implementation answers it from memory and never waits on a shared store for it; a marking shared between hosts is learned asynchronously, within a bounded period.

Properties

IsReplayActive

true while a replay is in progress; false in steady-state. Answered from the host's memory: a change made through this instance is seen at once, a change made in another host sharing the marking within the refresh period the host configures, and a host that cannot reach the shared store keeps its last answer.

bool IsReplayActive { get; }

Property Value

bool

Methods

Activate()

Mark the replay as started.

void Activate()

Complete(ReplayCompletion)

Mark the replay of RequestId as ended and keep its outcome, readable through LastReplay until the next replay ends.

void Complete(ReplayCompletion completion)

Parameters

completion ReplayCompletion

How the replay ended.

Remarks

The marking is ended only while it still belongs to that request: a replay that outlived its lease, while another request started, records its outcome and leaves the other replay's marking alone. The default implementation calls SetFailed(string) for a failure and Deactivate() otherwise, and keeps no outcome.

Exceptions

ArgumentNullException

completion is null.

Deactivate()

Mark the replay as completed (success or graceful stop).

void Deactivate()

GetProgress()

Snapshot the current replay progress.

ReplayProgress GetProgress()

Returns

ReplayProgress

RequestReplay()

Signal that a replay should start — fires every subscribed callback.

void RequestReplay()

Remarks

The request is given a new identity; use RequestReplay(Guid) to choose it.

RequestReplay(Guid)

Signal that a replay should start, under an identity the requester chose — fires every subscribed callback with requestId.

void RequestReplay(Guid requestId)

Parameters

requestId Guid

The identity of the request; a new Guid per request.

Remarks

The running replay's RequestId and, once it has ended, RequestId name the request, so a requester that polls can tell its own replay from an older one. Among the hosts that share the coordination state, one request starts at most one replay. The default implementation forwards to RequestReplay(), which loses the identity.

Exceptions

ArgumentException

requestId is Empty.

SetFailed(string)

Mark the current replay as failed and record errorMessage.

void SetFailed(string errorMessage)

Parameters

errorMessage string

SetProgress(long, long)

Update the replay progress counters.

void SetProgress(long processedEvents, long totalEvents)

Parameters

processedEvents long
totalEvents long

SubscribeToReplayRequestAsync(Func<Guid, Task>, CancellationToken)

Register a callback fired with the request's identity whenever a replay is requested.

Task SubscribeToReplayRequestAsync(Func<Guid, Task> onReplayRequested, CancellationToken cancellationToken = default)

Parameters

onReplayRequested Func<Guid, Task>

The callback, given the identity of the request.

cancellationToken CancellationToken

Cancels the subscription's establishment.

Returns

Task

A task that completes once the callback is registered.

Remarks

The default implementation subscribes through SubscribeToReplayRequestAsync(Func<Task>, CancellationToken) and passes Empty, because that member carries no identity.

SubscribeToReplayRequestAsync(Func<Task>, CancellationToken)

Register a callback fired whenever a replay is requested.

Task SubscribeToReplayRequestAsync(Func<Task> onReplayRequested, CancellationToken cancellationToken = default)

Parameters

onReplayRequested Func<Task>
cancellationToken CancellationToken

Returns

Task

TryActivate(Guid)

Claim the request requestId and mark its replay as started, unless another host has claimed it already or another replay is active.

bool TryActivate(Guid requestId)

Parameters

requestId Guid

The identity of the request to run.

Returns

bool

true when this caller is to run the replay.

Remarks

Returns false — and starts nothing — when the request was claimed before, so a request seen by several hosts, or seen again after its replay ended, runs once; and when another replay is active, so a second replay never empties what a running one is rebuilding. The default implementation refuses while IsReplayActive and otherwise calls Activate(); it cannot tell one request from another.