Class EventsPublisher

java.lang.Object
app.l2nx.gs.adapter.core.events.EventsPublisher

public final class EventsPublisher extends Object
Bounded-queue + single-daemon-thread fan-out for outbound events. Caller threads (NxEventsImpl.publishX(...)) call enqueue(EventEnvelope) which is O(1) and never blocks on Kafka latency. The daemon nx-events-publisher drains the queue, builds a ProducerRecord, stamps the Nx-Message-Type header, and hands off to the supplied EventsPublisher.Sender (production: NxKafka.sendBytesKeyRecord).

Drop policy on full queue:

Counters expose the publisher's health via currentStatus() for the heartbeat events module slot.

  • Constructor Details

  • Method Details

    • start

      public void start()
      Spawn the publisher daemon. Idempotent.
    • stop

      public void stop()
      Stop the publisher. Signals the daemon, waits up to shutdownDrainMs for in-flight envelopes to drain, then cancels. Idempotent.
    • enqueue

      public void enqueue(@Nullable app.l2nx.gs.adapter.core.events.EventEnvelope envelope)
      Append an envelope to the publish queue. On full queue, applies the configured EventsPublisher.DropPolicy; never blocks longer than the ArrayBlockingQueue.offer() fast path.

      Drop counter accounts for every lost envelope, including races. With EventsPublisher.DropPolicy.OLDEST and concurrent callers, an enqueue may evict the head AND lose its own envelope to another caller filling the freed slot first — both losses are counted (droppedTotal += 2).

    • currentStatus

      public app.l2nx.gs.adapter.api.kafka.ops.ModuleStatus currentStatus()
      Build a heartbeat slot snapshot.

      State semantics: ACTIVE when the daemon is running, DISABLED when it has not been started or has been stopped. TODO(messaging-r14): emit DEGRADED when the failed-total / published-total ratio exceeds an internal threshold (spec suggests ~5% over the last minute). Operators can still derive degradation from the raw counters today; the rolling-window tracking is deferred until a real ops case demands it.

    • isFamilyEnabled

      public boolean isFamilyEnabled(String familyKey)
      True when the family key has a non-empty topic configured.