Class InfinispanLock
java.lang.Object
org.infinispan.util.concurrent.locks.impl.InfinispanLock
A special lock for Infinispan cache.
The main different with the traditional
Lock is allowing to use any object as lock
owner. It is possible to use a Thread as lock owner that makes similar to Lock.
In addition, it has an asynchronous interface. acquire(Object, long, TimeUnit) will not acquire the lock
immediately (except if it is free) but will return a ExtendedLockPromise. This promise allow to test if the
lock is acquired asynchronously and cancel the lock acquisition, without any blocking.- Since:
- 8.0
- Author:
- Pedro Ruivo
-
Constructor Summary
ConstructorsConstructorDescriptionInfinispanLock(Executor nonBlockingExecutor, TimeService timeService) Creates a new instance.InfinispanLock(Executor nonBlockingExecutor, TimeService timeService, Runnable releaseRunnable) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionIt tries to acquire this lock.booleancontainsLockOwner(Object lockOwner) It tests if the lock has the lock owner.voiddeadlockCheck(DeadlockChecker deadlockChecker) It forces a deadlock checking.booleanisLocked()It checks if the lock is acquired.voidIt tries to release the lock held bylockOwner.voidsetTimeService(TimeService timeService) Tests purpose only!
-
Constructor Details
-
InfinispanLock
Creates a new instance.- Parameters:
nonBlockingExecutor- executor that is resumed upon after a lock has been acquired or times out if waitingtimeService- theTimeServiceto check for timeouts.
-
InfinispanLock
public InfinispanLock(Executor nonBlockingExecutor, TimeService timeService, Runnable releaseRunnable) Creates a new instance.- Parameters:
nonBlockingExecutor- executor that is resumed upon after a lock has been acquired or times out if waitingtimeService- theTimeServiceto check for timeouts.releaseRunnable- aRunnablethat is invoked every time this lock is released.
-
-
Method Details
-
setTimeService
Tests purpose only! -
acquire
It tries to acquire this lock. If it is invoked multiple times with the same owner, the sameExtendedLockPromiseis returned until it has timed-out orrelease(Object)is invoked. If the lock is free, it is immediately acquired, otherwise the lock owner is queued.- Parameters:
lockOwner- the lock owner who needs to acquire the lock.time- the timeout value.timeUnit- the timeout unit.- Returns:
- an
ExtendedLockPromise. - Throws:
NullPointerException- iflockOwnerortimeUnitisnull.
-
release
It tries to release the lock held bylockOwner. If the lock is not acquired (is waiting or timed out/deadlocked) bylockOwner, itsExtendedLockPromiseis canceled. IflockOwneris the current lock owner, the lock is released and the next lock owner available will acquire the lock. If thelockOwnernever tried to acquire the lock, this method does nothing.- Parameters:
lockOwner- the lock owner who wants to release the lock.- Throws:
NullPointerException- iflockOwnerisnull.
-
getLockOwner
- Returns:
- the current lock owner or
nullif it is not acquired.
-
isLocked
public boolean isLocked()It checks if the lock is acquired. Afalsereturn value does not mean the lock is free since it may have queued lock owners.- Returns:
trueif the lock is acquired.
-
deadlockCheck
It forces a deadlock checking. -
containsLockOwner
It tests if the lock has the lock owner. It returntrueif the lock owner is the current lock owner or it in the queue.- Parameters:
lockOwner- the lock owner to test.- Returns:
trueif it contains the lock owner.
-