Package org.infinispan.lock.impl.lock
Class ClusteredLockImpl
java.lang.Object
org.infinispan.lock.impl.lock.ClusteredLockImpl
- All Implemented Interfaces:
ClusteredLock
Implements Originator of the requests is the When a lock is acquired by a Node, it cannot be re-acquired,
even by the actual node til the lock is released. The lock can be unlocked only by the lock owner, in this
case the node lock method does not expire til the lock is acquired, so this can cause thread starvation in
the actual implementation
ClusteredLock interface.
This lock implements a non reentrant where the ownership is OwnershipLevel.NODE.
Non reentrant lock, Owner Node
Address of the EmbeddedCacheManager
Partition handling
- Since:
- 9.2
- Author:
- Katia Aresti, karesti@redhat.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassclass -
Constructor Summary
ConstructorsConstructorDescriptionClusteredLockImpl(String name, ClusteredLockKey lockKey, org.infinispan.AdvancedCache<ClusteredLockKey, ClusteredLockValue> clusteredLockCache, EmbeddedClusteredLockManager clusteredLockManager) -
Method Summary
Modifier and TypeMethodDescriptiongetName()isLocked()Returns aCompletableFuture<Boolean>holdingtruewhen the lock is locked andfalsewhen the lock is released.Returns aCompletableFuture<Boolean>holdingtruewhen the lock is owned by the caller andfalsewhen the lock is owned by someone else or it's released.lock()Acquires the lock.voidstop()toString()tryLock()Acquires the lock only if it is free at the time of invocation.If the lock is available this method returns immediately with theCompletableFutureholding the valuetrue.unlock()Releases the lock.
-
Constructor Details
-
ClusteredLockImpl
public ClusteredLockImpl(String name, ClusteredLockKey lockKey, org.infinispan.AdvancedCache<ClusteredLockKey, ClusteredLockValue> clusteredLockCache, EmbeddedClusteredLockManager clusteredLockManager)
-
-
Method Details
-
stop
public void stop() -
lock
Description copied from interface:ClusteredLockAcquires the lock. If the lock is not available then theCompletableFuturewaits until the lock has been acquired. Currently, there is no maximum time specified for a lock request to fail, so this could cause thread starvation.- Specified by:
lockin interfaceClusteredLock- Returns:
- a completed
CompletableFuturewhen the lock is acquired
-
tryLock
Description copied from interface:ClusteredLockAcquires the lock only if it is free at the time of invocation. Acquires the lock if it is available and returns immediately with with theCompletableFutureholding the valuetrue. If the lock is not available then this method will return immediately with theCompletableFutureholding the valuefalse.- Specified by:
tryLockin interfaceClusteredLock- Returns:
CompletableFuture(true)if the lock was acquired andCompletableFuture(false)otherwise
-
tryLock
Description copied from interface:ClusteredLockIf the lock is available this method returns immediately with theCompletableFutureholding the valuetrue. If the lock is not available then theCompletableFuturewaits until :- The lock is acquired
- The specified waiting time elapses
CompletableFuturewill complete with the valuetrue. If the specified waiting time elapses then theCompletableFuturewill complete with the valuefalse. If the time is less than or equal to zero, the method will not wait at all.- Specified by:
tryLockin interfaceClusteredLock- Parameters:
time- , the maximum time to wait for the lockunit- , the time unit of thetimeargument- Returns:
CompletableFuture(true)if the lock was acquired andCompletableFuture(false)if the waiting time elapsed before the lock was acquired
-
unlock
Description copied from interface:ClusteredLockReleases the lock. Only the holder of the lock may release the lock.- Specified by:
unlockin interfaceClusteredLock- Returns:
- a completed
CompletableFuturewhen the lock is released
-
isLocked
Description copied from interface:ClusteredLockReturns aCompletableFuture<Boolean>holdingtruewhen the lock is locked andfalsewhen the lock is released.- Specified by:
isLockedin interfaceClusteredLock- Returns:
- a
CompletableFutureholding aBoolean
-
isLockedByMe
Description copied from interface:ClusteredLockReturns aCompletableFuture<Boolean>holdingtruewhen the lock is owned by the caller andfalsewhen the lock is owned by someone else or it's released.- Specified by:
isLockedByMein interfaceClusteredLock- Returns:
- a
CompletableFutureholding aBoolean
-
getName
-
getOriginator
-
toString
-