Class DatabasePostgresMutex
java.lang.Object
com.echothree.util.server.persistence.mutex.DatabasePostgresMutex
- All Implemented Interfaces:
DatabaseMutex
Postgres session advisory locks keyed by the first 64 bits of SHA-256.
Hash collisions cause otherwise distinct names to share a lock.
-
Field Summary
Fields inherited from interface com.echothree.util.server.persistence.mutex.DatabaseMutex
DEFAULT_TIMEOUT_SECONDS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanacquireLock(String lockName, int timeoutSeconds) Attempts to acquire the named lock within the specified timeout.booleanreleaseLock(String lockName) Releases one acquisition of the named lock on the session's connection.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.echothree.util.server.persistence.mutex.DatabaseMutex
acquireLock
-
Constructor Details
-
DatabasePostgresMutex
public DatabasePostgresMutex()
-
-
Method Details
-
acquireLock
Description copied from interface:DatabaseMutexAttempts to acquire the named lock within the specified timeout.- Specified by:
acquireLockin interfaceDatabaseMutex- Parameters:
lockName- the name of the locktimeoutSeconds- 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
Description copied from interface:DatabaseMutexReleases one acquisition of the named lock on the session's connection.- Specified by:
releaseLockin interfaceDatabaseMutex- 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.
-