Class PostgresConversationLock

java.lang.Object
at.aimon.session.postgres.PostgresConversationLock
All Implemented Interfaces:
at.aimon.session.web.spi.ConversationLock

public final class PostgresConversationLock extends Object implements at.aimon.session.web.spi.ConversationLock
Postgres-backed ConversationLock per design §4.1.

Row-level lease with a separate fencing-token counter — no pg_advisory_lock. The conversation_lock_fence table issues a monotonically increasing token per conversation; the conversation_lock row is upserted with ON CONFLICT DO UPDATE WHERE lease_expires_at < now() so a stale lease gets stomped while a live lease is left alone. RETURNING fencing_token after the upsert tells the caller whether they won the race (token matches the freshly-reserved one) or another holder still owns the row (return value differs / nothing returned).

Failure semantics:

  • Constructor Details

    • PostgresConversationLock

      public PostgresConversationLock(DataSource dataSource)
    • PostgresConversationLock

      public PostgresConversationLock(DataSource dataSource, Clock clock)
  • Method Details

    • tryAcquire

      public Optional<at.aimon.session.web.spi.ConversationLock.LockHandle> tryAcquire(at.aimon.core.agent.conversation.ConversationId id, String holderId, Duration lease)
      Specified by:
      tryAcquire in interface at.aimon.session.web.spi.ConversationLock
    • extend

      public boolean extend(at.aimon.session.web.spi.ConversationLock.LockHandle handle, Duration lease)
      Specified by:
      extend in interface at.aimon.session.web.spi.ConversationLock
    • release

      public void release(at.aimon.session.web.spi.ConversationLock.LockHandle handle)
      Specified by:
      release in interface at.aimon.session.web.spi.ConversationLock