Package org.axonframework.common.lock
Class PessimisticLockFactory
java.lang.Object
org.axonframework.common.lock.PessimisticLockFactory
- All Implemented Interfaces:
LockFactory
Implementation of a
LockFactory that uses a pessimistic locking strategy. Calls to
obtainLock(java.lang.String) will block until a lock could be obtained or back off limit is reached, based on the
settings provided, by throwing an exception. The latter will cause the command to fail, but will allow
the calling thread to be freed. If a lock is obtained by a thread, that thread has guaranteed unique access.
Each thread can hold the same lock multiple times. The lock will only be released for other threads when the lock
has been released as many times as it was obtained.
This lock can be used to ensure thread safe access to a number of objects, such as Aggregates and Sagas.- Since:
- 1.3
- Author:
- Allard Buijze, Michael Bischoff, Henrique Sena
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an instance of the lock factory using the givenbuildercontaining the configuration properties to use. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a builder to construct an instance of this LockFactory.obtainLock(String identifier) Obtain a lock for a resource identified by the givenidentifier.static PessimisticLockFactoryCreates an instance using default values, as defined in the properties of thePessimisticLockFactory.Builder.
-
Constructor Details
-
PessimisticLockFactory
Creates an instance of the lock factory using the givenbuildercontaining the configuration properties to use.- Parameters:
builder- The building containing the configuration properties to use
-
-
Method Details
-
builder
Creates a builder to construct an instance of this LockFactory.- Returns:
- a builder allowing the definition of properties for this Lock Factory.
-
usingDefaults
Creates an instance using default values, as defined in the properties of thePessimisticLockFactory.Builder.- Returns:
- a PessimisticLockFactory instance using sensible default values
-
obtainLock
Obtain a lock for a resource identified by the givenidentifier. This method will block until a lock was successfully obtained. Note: when an exception occurs during the locking process, the lock may or may not have been allocated.- Specified by:
obtainLockin interfaceLockFactory- Parameters:
identifier- the identifier of the lock to obtain.- Returns:
- A handle to release the lock. If the thread that releases the lock does not hold the lock a
IllegalMonitorStateExceptionis thrown. - Throws:
IllegalArgumentException- Thrown when the givenidentifierisnull.
-