Interface FencedLockStorage<UOW extends UnitOfWork,​LOCK extends DBFencedLock>

    • Method Detail

      • initializeLockStorage

        void initializeLockStorage​(DBFencedLockManager<UOW,​LOCK> lockManager,
                                   UOW uow)
        Initialize the database storage (e.g. create table, collection, etc.)
        Parameters:
        lockManager - the lock manager
        uow - 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 manager
        uow - the active unit of work
        fencedLock - the fenced lock instance that is being confirmed
        confirmedTimestamp - the new confirmed timestamp
        Returns:
        true if the update in the DB was successful or false if we couldn't confirm the lock (e.g. because another lock manager instance had acquired the lock and updated the FencedLock.getCurrentToken() value in the DB
      • releaseLockInDB

        boolean releaseLockInDB​(DBFencedLockManager<UOW,​LOCK> lockManager,
                                UOW uow,
                                LOCK fencedLock)
        Update the database status for the lock as being released
        Parameters:
        lockManager - the lock manager
        uow - the active unit of work
        fencedLock - the fenced lock instance that is being released
        Returns:
        true if the update in the DB was successful or false if we couldn't release the lock (e.g. because another lock manager instance had acquired the lock and updated the FencedLock.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 manager
        uow - the active unit of work
        lockName - the name of the lock to find in the DB
        Returns:
        the result of the search
      • 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 manager
        name - the name of the lock
        currentToken - the current token value
        lockedByLockManagerInstanceId - the id (if any) of the local managed that has acquired the lock
        lockAcquiredTimestamp - the lock Acquired Timestamp
        lockLastConfirmedTimestamp - the lock Last Confirmed Timestamp
        Returns:
        the concrete DB specific DBFencedLock subclass
      • getUninitializedTokenValue

        Long getUninitializedTokenValue()
        Return the DB specific uninitialized value for a FencedLock.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
      • 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 manager
        uow - the unit of work
        initialLock - the initial and no yet persisted lock (with no FencedLock.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 manager
        uow - the unit of work
        timedOutLock - the lock that has timed out
        newLockReadyToBeAcquiredLocally - the lock that was acquired by this lock manager instance
        Returns:
        true if the update in the DB was successful or false if 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 manager
        uow - the unit of work
        nameOfLockToDelete - the name of the lock to delete
      • deleteAllLocksInDB

        void deleteAllLocksInDB​(DBFencedLockManager<UOW,​LOCK> lockManager,
                                UOW uow)
        Delete all locks in the DB. Should be used with caution and typically only for testing purposes
        Parameters:
        lockManager - the lock manager
        uow - the unit of work