public interface LockRepository extends RepositoryIndexable, Process
Repository interface to manage lock in database, which will be used by LockManager
| Modifier and Type | Method and Description |
|---|---|
void |
deleteAll()
Only for testing
|
LockEntry |
findByKey(String lockKey)
Retrieves a lock by key
|
void |
insertUpdate(LockEntry newLock)
a) If there is an existing lock in the database for the same key and owner
(existingLock.key==newLock.key &&
existingLoc.owner==newLock.owner), then the lock in database is updated/refreshed with the new values. |
void |
removeByKeyAndOwner(String lockKey,
String owner)
Removes from database all the locks with the same key(only can be one) and owner
|
void |
updateIfSameOwner(LockEntry newLock)
The only goal of this method is to update(mainly to extend the expiry date) the lock in case is already owned.
|
setIndexCreationinitializevoid insertUpdate(LockEntry newLock) throws LockPersistenceException
(existingLock.key==newLock.key &&
existingLoc.owner==newLock.owner), then the lock in database is updated/refreshed with the new values. The most
common scenario is to extend the lock's expiry date.
b) If there is a existing lock in the database for the same key and different owner, but expired (existingLock.key==newLock.key &&
existingLock.owner!=newLock.owner && now > expiredAt), the lock is replaced with the newLock, so the owner of the lock for
that key is newLock.owner
c) If scenario b, but lock is not expired yet, should throw an LockPersistenceException.
d) If there isn't any lock with key=newLock.key, newLock is inserted.
newLock - lock to replace the existing one or be inserted.LockPersistenceException - if there is a lock in database with same key, but is expired and belong to
another owner or cannot insert/update the lock for any other reasonvoid updateIfSameOwner(LockEntry newLock) throws LockPersistenceException
(existingLock.key==newLock.key && existingLoc.owner==newLock.owner).
If there is no lock for the key or it doesn't belong to newLock.owner, a LockPersistenceException is thrown. Take into account that if it's already expired, but still with the same owner, we are lucky, no one has taken it yet, so we can still extend the expiration time.
newLock - lock to replace the existing one or be inserted.LockPersistenceException - if there is a lock in database with same key, but is expired and belong to
another owner or cannot insert/update the lock for any other reasonLockEntry findByKey(String lockKey)
lockKey - keyvoid removeByKeyAndOwner(String lockKey, String owner)
lockKey - lock keyowner - lock ownervoid deleteAll()
Copyright © 2024. All rights reserved.