Interface FencedLockStorage<UOW extends UnitOfWork,LOCK extends DBFencedLock>
public interface FencedLockStorage<UOW extends UnitOfWork,LOCK extends DBFencedLock>
-
Method Summary
Modifier and TypeMethodDescriptionbooleanconfirmLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK fencedLock, OffsetDateTime confirmedTimestamp) Update the database status for the lock as being confirmed by this lock manager instancecreateInitializedLock(DBFencedLockManager<UOW, LOCK> lockManager, LockName name, long currentToken, String lockedByLockManagerInstanceId, OffsetDateTime lockAcquiredTimestamp, OffsetDateTime lockLastConfirmedTimestamp) Create an initialized lockcreateUninitializedLock(DBFencedLockManager<UOW, LOCK> lockManager, LockName lockName) Create an un-initialized lock (with a default DB specific un-initialized value for theDBFencedLock.getCurrentToken())voiddeleteAllLocksInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow) Delete all locks in the DB.voiddeleteLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LockName nameOfLockToDelete) Delete a lock in the DB.longReturn the DB specific value for aFencedLock.getCurrentToken()that is being persisted the very first timeReturn the DB specific uninitialized value for aFencedLock.getCurrentToken()that has yet to be persisted for the very first timevoidinitializeLockStorage(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow) Initialize the database storage (e.g.booleaninsertLockIntoDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK initialLock, OffsetDateTime lockAcquiredAndLastConfirmedTimestamp) Insert the local into the DB for the very first timelookupLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LockName lockName) Lookup a Lock in the underlying databasebooleanreleaseLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK fencedLock) Update the database status for the lock as being releasedbooleanupdateLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK timedOutLock, LOCK newLockReadyToBeAcquiredLocally) Update the lock in the DB.
-
Method Details
-
initializeLockStorage
Initialize the database storage (e.g. create table, collection, etc.)- Parameters:
lockManager- the lock manageruow- the active unit of work
-
confirmLockInDB
boolean confirmLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK fencedLock, OffsetDateTime confirmedTimestamp) Update the database status for the lock as being confirmed by this lock manager instance- Parameters:
lockManager- the lock manageruow- the active unit of workfencedLock- the fenced lock instance that is being confirmedconfirmedTimestamp- the new confirmed timestamp- Returns:
trueif the update in the DB was successful orfalseif we couldn't confirm the lock (e.g. because another lock manager instance had acquired the lock and updated theFencedLock.getCurrentToken()value in the DB
-
releaseLockInDB
Update the database status for the lock as being released- Parameters:
lockManager- the lock manageruow- the active unit of workfencedLock- the fenced lock instance that is being released- Returns:
trueif the update in the DB was successful orfalseif we couldn't release the lock (e.g. because another lock manager instance had acquired the lock and updated theFencedLock.getCurrentToken()value in the DB
-
lookupLockInDB
Optional<LOCK> lookupLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LockName lockName) Lookup a Lock in the underlying database- Parameters:
lockManager- the lock manageruow- the active unit of worklockName- the name of the lock to find in the DB- Returns:
- the result of the search
-
createUninitializedLock
Create an un-initialized lock (with a default DB specific un-initialized value for theDBFencedLock.getCurrentToken())- Parameters:
lockManager- the lock managerlockName- the name of the lock- Returns:
- the concrete DB specific
DBFencedLocksubclass
-
createInitializedLock
LOCK createInitializedLock(DBFencedLockManager<UOW, LOCK> lockManager, LockName name, long currentToken, String lockedByLockManagerInstanceId, OffsetDateTime lockAcquiredTimestamp, OffsetDateTime lockLastConfirmedTimestamp) Create an initialized lock- Parameters:
lockManager- the lock managername- the name of the lockcurrentToken- the current token valuelockedByLockManagerInstanceId- the id (if any) of the local managed that has acquired the locklockAcquiredTimestamp- the lock Acquired TimestamplockLastConfirmedTimestamp- the lock Last Confirmed Timestamp- Returns:
- the concrete DB specific
DBFencedLocksubclass
-
getUninitializedTokenValue
Long getUninitializedTokenValue()Return the DB specific uninitialized value for aFencedLock.getCurrentToken()that has yet to be persisted for the very first time- Returns:
- the DB specific uninitialized value for a
FencedLock.getCurrentToken()that has yet to be persisted for the very first time
-
getInitialTokenValue
long getInitialTokenValue()Return the DB specific value for aFencedLock.getCurrentToken()that is being persisted the very first time- Returns:
- the DB specific value for a
FencedLock.getCurrentToken()that is being persisted the very first time
-
insertLockIntoDB
boolean insertLockIntoDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK initialLock, OffsetDateTime lockAcquiredAndLastConfirmedTimestamp) Insert the local into the DB for the very first time- Parameters:
lockManager- the lock manageruow- the unit of workinitialLock- the initial and no yet persisted lock (with noFencedLock.getCurrentToken()value set yet)lockAcquiredAndLastConfirmedTimestamp- the timestamp of when the lock is being acquired and last confirmed- Returns:
-
updateLockInDB
boolean updateLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LOCK timedOutLock, LOCK newLockReadyToBeAcquiredLocally) Update the lock in the DB.- Parameters:
lockManager- the lock manageruow- the unit of worktimedOutLock- the lock that has timed outnewLockReadyToBeAcquiredLocally- the lock that was acquired by this lock manager instance- Returns:
trueif the update in the DB was successful orfalseif we couldn't confirm the lock (e.g. because another lock manager instance had acquired the lock)
-
deleteLockInDB
void deleteLockInDB(DBFencedLockManager<UOW, LOCK> lockManager, UOW uow, LockName nameOfLockToDelete) Delete a lock in the DB. Should be used with caution (i.e. when you're sure that the lock is no longer used by any nodes- Parameters:
lockManager- the lock manageruow- the unit of worknameOfLockToDelete- the name of the lock to delete
-
deleteAllLocksInDB
Delete all locks in the DB. Should be used with caution and typically only for testing purposes- Parameters:
lockManager- the lock manageruow- the unit of work
-