Class ListenDispatcher

java.lang.Object
at.aimon.session.postgres.internal.ListenDispatcher
All Implemented Interfaces:
AutoCloseable

public final class ListenDispatcher extends Object implements AutoCloseable
Owns the dedicated LISTEN connection for conversation_signal_doorbell.

The LISTEN connection lives outside HikariCP because LISTEN state is connection-bound and cannot survive being returned to a pool — see design §6.2. A second short-lived DataSource (typically the bus's signal pool) is used for the row-fetch SELECTs so the dedicated LISTEN connection only ever blocks on PGConnection.getNotifications().

Reconnect semantics (design §6.2 / §8 #2): on any SQLException the dispatcher closes the listen connection, sleeps 500 ms, opens a new one, re-issues LISTEN, runs a backlog query starting at the highest id seen so far, and resumes. No signal loss because the rows live in the table independent of NOTIFY delivery.

Backstop self-poll (design §4.2): every selfPollMillis ms the dispatcher re-runs the fetch query without waiting for a doorbell, catching any rows that arrived while a NOTIFY was dropped (e.g. backend crash, network blip).

  • Field Details

  • Constructor Details

  • Method Details

    • start

      public void start()
      Starts the listener thread. Idempotent.
    • track

      public void track(at.aimon.core.agent.conversation.ConversationId id, Consumer<at.aimon.session.web.spi.ConversationSignal> handler)
    • untrack

      public void untrack(at.aimon.core.agent.conversation.ConversationId id)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable