Class InMemoryProgressSink

java.lang.Object
com.tnsai.reliability.InMemoryProgressSink
All Implemented Interfaces:
ProgressSink

public final class InMemoryProgressSink extends Object implements ProgressSink
Process-local ProgressSink (TNS-299). Maintains a per-run CopyOnWriteArrayList of subscribers and dispatches each publish synchronously on the publisher's thread.

Concurrency

Subscribers may register and cancel from any thread. Publish iterates the COW list snapshot, so subscribers added or removed mid-publish don't break the iteration. A subscriber that throws is logged and skipped — one bad listener never starves the others.

Replay

This sink does NOT replay events to late subscribers. Subscribers see only events published after their subscribe(java.lang.String, java.util.function.Consumer<com.tnsai.reliability.Progress>) call. Operators that need history should query the CheckpointStore directly or wire a buffering sink in front.
Since:
0.10.0 (TNS-299)
  • Constructor Details

    • InMemoryProgressSink

      public InMemoryProgressSink()
  • Method Details

    • publish

      public void publish(String runId, Progress event)
      Description copied from interface: ProgressSink
      Broadcast event to every subscriber registered for runId. Returns once delivery has been queued — does not block on slow subscribers (implementations decide their queueing / back-pressure strategy).
      Specified by:
      publish in interface ProgressSink
    • subscribe

      public ProgressSink.Subscription subscribe(String runId, Consumer<Progress> listener)
      Description copied from interface: ProgressSink
      Register listener for events on runId. The returned ProgressSink.Subscription must be cancelled when the consumer is done; not cancelling leaks subscriber state.

      The listener may be invoked concurrently with itself for different events — implementations don't serialize calls.

      Specified by:
      subscribe in interface ProgressSink
    • subscriberCount

      public int subscriberCount(String runId)
      Test helper: count of active (non-cancelled) subscribers for a run.