Package at.aimon.session.postgres
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:
- Lock held by another holder → empty
OptionalfromtryAcquire(at.aimon.core.agent.conversation.ConversationId, java.lang.String, java.time.Duration). - JDBC failure →
ConversationLockException.
-
Nested Class Summary
Nested classes/interfaces inherited from interface at.aimon.session.web.spi.ConversationLock
at.aimon.session.web.spi.ConversationLock.LockHandle -
Constructor Summary
ConstructorsConstructorDescriptionPostgresConversationLock(DataSource dataSource) PostgresConversationLock(DataSource dataSource, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidrelease(at.aimon.session.web.spi.ConversationLock.LockHandle handle) Optional<at.aimon.session.web.spi.ConversationLock.LockHandle> tryAcquire(at.aimon.core.agent.conversation.ConversationId id, String holderId, Duration lease)
-
Constructor Details
-
PostgresConversationLock
-
PostgresConversationLock
-
-
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:
tryAcquirein interfaceat.aimon.session.web.spi.ConversationLock
-
extend
- Specified by:
extendin interfaceat.aimon.session.web.spi.ConversationLock
-
release
public void release(at.aimon.session.web.spi.ConversationLock.LockHandle handle) - Specified by:
releasein interfaceat.aimon.session.web.spi.ConversationLock
-