Interface FencedLock
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DBFencedLock
Represents a named fenced lock, where the
The fence locking concept is described here https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
getCurrentToken() can be passed on to down stream logic, which can keep track of the token value to identify if a timed out lock is being used to request logic.The fence locking concept is described here https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Closing aFencedLockwill automatically callrelease()The current token value as of thegetLockLastConfirmedTimestamp()for this Lock across allFencedLockManagerinstances
Every time a lock is acquired or confirmed a new token is issued (i.e.At what time did the JVM/FencedLockManager.getLockManagerInstanceId()that currently has acquired the lock acquire it (at first acquiring thegetLockLastConfirmedTimestamp()is set togetLockAcquiredTimestamp())Which JVM/FencedLockManager.getLockManagerInstanceId()that has acquired this lockAt what time did the JVM/FencedLockManager.getLockManagerInstanceId(), that currently has acquired the lock, last confirm that it still has access to the lockgetName()The name of the LockbooleanisLocked()Is this lock locked?booleanIs this Lock locked by this JVM nodevoidregisterCallback(LockCallback lockCallback) voidrelease()Release/Unlock the lock.
-
Method Details
-
getName
LockName getName()The name of the Lock- Returns:
- the lock name
-
getCurrentToken
Long getCurrentToken()The current token value as of thegetLockLastConfirmedTimestamp()for this Lock across allFencedLockManagerinstances
Every time a lock is acquired or confirmed a new token is issued (i.e. it's ever-growing value) -
getLockedByLockManagerInstanceId
String getLockedByLockManagerInstanceId()Which JVM/FencedLockManager.getLockManagerInstanceId()that has acquired this lock -
getLockAcquiredTimestamp
OffsetDateTime getLockAcquiredTimestamp()At what time did the JVM/FencedLockManager.getLockManagerInstanceId()that currently has acquired the lock acquire it (at first acquiring thegetLockLastConfirmedTimestamp()is set togetLockAcquiredTimestamp()) -
getLockLastConfirmedTimestamp
OffsetDateTime getLockLastConfirmedTimestamp()At what time did the JVM/FencedLockManager.getLockManagerInstanceId(), that currently has acquired the lock, last confirm that it still has access to the lock -
isLocked
boolean isLocked()Is this lock locked? -
isLockedByThisLockManagerInstance
boolean isLockedByThisLockManagerInstance()Is this Lock locked by this JVM node -
release
void release()Release/Unlock the lock. Only works ifisLockedByThisLockManagerInstance()is true -
registerCallback
-
close
Closing aFencedLockwill automatically callrelease()- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-