Class DatabasePostgresMutex

java.lang.Object
com.echothree.util.server.persistence.mutex.DatabasePostgresMutex
All Implemented Interfaces:
DatabaseMutex

@ApplicationScoped public class DatabasePostgresMutex extends Object implements DatabaseMutex
Postgres session advisory locks keyed by the first 64 bits of SHA-256. Hash collisions cause otherwise distinct names to share a lock.
  • Constructor Details

  • Method Details

    • acquireLock

      public boolean acquireLock(String lockName, int timeoutSeconds)
      Description copied from interface: DatabaseMutex
      Attempts to acquire the named lock within the specified timeout.
      Specified by:
      acquireLock in interface DatabaseMutex
      Parameters:
      lockName - the name of the lock
      timeoutSeconds - zero to try once, positive to wait up to that many seconds, or negative to wait indefinitely
      Returns:
      true only when the lock was acquired; false on timeout or a null database result. Postgres also returns false when interrupted, preserving the interrupt flag. SQL execution errors propagate to the caller.
    • releaseLock

      public boolean releaseLock(String lockName)
      Description copied from interface: DatabaseMutex
      Releases one acquisition of the named lock on the session's connection.
      Specified by:
      releaseLock in interface DatabaseMutex
      Parameters:
      lockName - the name of the lock
      Returns:
      true only when the database confirms release; false when the lock is not owned by this session, does not exist, or the result is null. SQL execution errors propagate to the caller.