Package org.infinispan.lock.impl.lock
Class ClusteredLockImpl
- java.lang.Object
-
- org.infinispan.lock.impl.lock.ClusteredLockImpl
-
- All Implemented Interfaces:
ClusteredLock
public class ClusteredLockImpl extends Object implements ClusteredLock
ImplementsClusteredLockinterface.This lock implements a non reentrant where the ownership is
OwnershipLevel.NODE.Non reentrant lock, Owner Node
- Originator of the requests is the
Addressof theEmbeddedCacheManager- 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
Partition handling
- Since:
- 9.2
- Author:
- Katia Aresti, karesti@redhat.com
- See Also:
- Infinispan documentation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classClusteredLockImpl.LockRequestHolderclassClusteredLockImpl.RequestHolder<E>classClusteredLockImpl.TryLockRequestHolder
-
Constructor Summary
Constructors Constructor Description ClusteredLockImpl(String name, ClusteredLockKey lockKey, org.infinispan.AdvancedCache<ClusteredLockKey,ClusteredLockValue> clusteredLockCache, EmbeddedClusteredLockManager clusteredLockManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetName()ObjectgetOriginator()CompletableFuture<Boolean>isLocked()Returns aCompletableFutureholdingtruewhen the lock is locked andfalsewhen the lock is released.CompletableFuture<Boolean>isLockedByMe()Returns aCompletableFutureholdingtruewhen the lock is owned by the caller andfalsewhen the lock is owned by someone else or it's released.CompletableFuture<Void>lock()Acquires the lock.voidstop()StringtoString()CompletableFuture<Boolean>tryLock()Acquires the lock only if it is free at the time of invocation.CompletableFuture<Boolean>tryLock(long time, TimeUnit unit)If the lock is available this method returns immediately with theCompletableFutureholding the valuetrue.CompletableFuture<Void>unlock()Releases the lock.
-
-
-
Constructor Detail
-
ClusteredLockImpl
public ClusteredLockImpl(String name, ClusteredLockKey lockKey, org.infinispan.AdvancedCache<ClusteredLockKey,ClusteredLockValue> clusteredLockCache, EmbeddedClusteredLockManager clusteredLockManager)
-
-
Method Detail
-
stop
public void stop()
-
lock
public CompletableFuture<Void> 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
public CompletableFuture<Boolean> 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
public CompletableFuture<Boolean> tryLock(long time, TimeUnit unit)
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
public CompletableFuture<Void> 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
public CompletableFuture<Boolean> isLocked()
Description copied from interface:ClusteredLockReturns aCompletableFutureholdingtruewhen the lock is locked andfalsewhen the lock is released.- Specified by:
isLockedin interfaceClusteredLock- Returns:
- a
CompletableFutureholding aBoolean
-
isLockedByMe
public CompletableFuture<Boolean> isLockedByMe()
Description copied from interface:ClusteredLockReturns aCompletableFutureholdingtruewhen 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
public String getName()
-
getOriginator
public Object getOriginator()
-
-