public class SingleInstanceLockManager extends Object
Semaphore
based or ReentrantLock
based to facilitate synchronization. This will give the sequence number generating functionality as well. This will only
be useful for VM level locks or sequence numbers which won't be applicable for clustered deploymentConstructor and Description |
---|
SingleInstanceLockManager() |
Modifier and Type | Method and Description |
---|---|
static SingleInstanceLockManager |
getInstance() |
Optional<Integer> |
getNextSequenceNumber(String keyPath)
Generate the next sequence number for the given keyPath
|
boolean |
isAcquired(String lockPath)
Checks whether a
Semaphore based lock is acquired |
void |
releaseLock(String lockPath)
Releases the acquired
Semaphore based lock for the given lockPath |
void |
releaseReentrantLock(String lockPath)
Release the acquired
ReentrantLock for the given lockPath |
boolean |
tryLock(String lockPath)
Attempts to get a
Semaphore based lock for the given lockPath. |
boolean |
tryLock(String lockPath,
long timeout)
Attempts to get a
Semaphore based lock for the given lockPath within the given timeout value. |
boolean |
tryReentrantLock(String lockPath)
Attempts to get a
ReentrantLock lock for the given lockPath which will be useful only for acquire and
release using the same thread. |
public static SingleInstanceLockManager getInstance()
public Optional<Integer> getNextSequenceNumber(String keyPath)
keyPath
- the key to associate the sequence numberpublic boolean tryReentrantLock(String lockPath)
ReentrantLock
lock for the given lockPath which will be useful only for acquire and
release using the same thread. If it's going to acquire the lock from one thread and release from anther thread,
then this API won't help to facilitate the required synchronization. For those type of scenarios instead of this,
use the tryLock() APIlockPath
- the key to get the ReentrantLock
public void releaseReentrantLock(String lockPath)
ReentrantLock
for the given lockPathlockPath
- the key to find the lock which should be acquired beforepublic boolean tryLock(String lockPath)
Semaphore
based lock for the given lockPath. In this method, it's not required to acquire
and release the lock using the same threadlockPath
- the key to get the Semaphore
public boolean tryLock(String lockPath, long timeout)
Semaphore
based lock for the given lockPath within the given timeout value. In this method,
it's not required to acquire and release the lock using the same thread.lockPath
- the key to get the Semaphore
timeout
- maximum time in milliseconds that should wait trying to acquire the lockpublic boolean isAcquired(String lockPath)
Semaphore
based lock is acquiredlockPath
- the key to find the Semaphore
that is related to this lockCopyright © 2016–2019 AdroitLogic. All rights reserved.