Class HazelcastLockProvider
- All Implemented Interfaces:
LockProvider
public class HazelcastLockProvider extends Object implements LockProvider
Implementation of LockProvider using Hazelcast for store and share locks informations and mechanisms between a cluster members
Below, the mechanims :
- The Lock, an instance of HazelcastLock, is obtained / created when :
-- the lock is not not already locked by other process (lock - referenced by its name - is not present in the Hazelcast locks store OR unlockable)
-- the lock is expired : Instant.now() > HazelcastLock.timeToLive where unlockTime have by default the same value of HazelcastLock.lockAtMostUntil
and can have the value of HazelcastLock.lockAtLeastUntil if unlock action is used
--- expired object is removed
-- the lock is owned by not available member of Hazelcast cluster member
--- no owner objectis removed
- Unlock action :
-- removes lock object when HazelcastLock.lockAtLeastUntil is not come
-- override value of HazelcastLock.timeToLive with HazelcastLock.lockAtLeastUntil (its default value is the same of HazelcastLock.lockAtLeastUntil
-
Constructor Summary
Constructors Constructor Description HazelcastLockProvider(com.hazelcast.core.HazelcastInstance hazelcastInstance)Instantiate the provider.HazelcastLockProvider(com.hazelcast.core.HazelcastInstance hazelcastInstance, String lockStoreKey)Instantiate the provider.HazelcastLockProvider(com.hazelcast.core.HazelcastInstance hazelcastInstance, String lockStoreKey, Duration lockLeaseTime)Instantiate the provider. -
Method Summary
Modifier and Type Method Description Optional<SimpleLock>lock(LockConfiguration lockConfiguration)
-
Constructor Details
-
HazelcastLockProvider
public HazelcastLockProvider(com.hazelcast.core.HazelcastInstance hazelcastInstance)Instantiate the provider.- Parameters:
hazelcastInstance- The Hazelcast engine used by the application.
-
HazelcastLockProvider
public HazelcastLockProvider(com.hazelcast.core.HazelcastInstance hazelcastInstance, String lockStoreKey)Instantiate the provider.- Parameters:
hazelcastInstance- The Hazelcast engine used by the applicationlockStoreKey- The key where the locks store is associatehazelcastInstance(by defaultLOCK_STORE_KEY_DEFAULT).
-
HazelcastLockProvider
public HazelcastLockProvider(com.hazelcast.core.HazelcastInstance hazelcastInstance, String lockStoreKey, Duration lockLeaseTime)Instantiate the provider.- Parameters:
hazelcastInstance- The Hazelcast engine used by the applicationlockStoreKey- The key where the locks store is associatehazelcastInstance(by defaultLOCK_STORE_KEY_DEFAULT).lockLeaseTime- When lock is being obtained there is a Hazelcast lock used to make it thread-safe. This lock should be released quite fast but if the process dies while holding the lock, it is held forever. lockLeaseTime is used as a safety-net for such situations.
-
-
Method Details
-
lock
- Specified by:
lockin interfaceLockProvider
-