Package io.ocfl.core.lock
Class InMemoryObjectLock
- java.lang.Object
-
- io.ocfl.core.lock.InMemoryObjectLock
-
- All Implemented Interfaces:
ObjectLock
public class InMemoryObjectLock extends Object implements ObjectLock
In-memory implementation of ObjectLock that uses Java's ReentrantReadWriteLock.
-
-
Constructor Summary
Constructors Constructor Description InMemoryObjectLock(long waitTime, TimeUnit timeUnit)
How long to wait when attempting to acquire a lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doInWriteLock(String objectId, Runnable doInLock)
Executes the code block after securing a write lock on the objectId.<T> T
doInWriteLock(String objectId, Callable<T> doInLock)
Executes the code block after securing a write lock on the objectId.
-
-
-
Constructor Detail
-
InMemoryObjectLock
public InMemoryObjectLock(long waitTime, TimeUnit timeUnit)
How long to wait when attempting to acquire a lock.- Parameters:
waitTime
- how long to wait for the locktimeUnit
- unit of wait time
-
-
Method Detail
-
doInWriteLock
public void doInWriteLock(String objectId, Runnable doInLock)
Executes the code block after securing a write lock on the objectId. The lock is released after the block completes.- Specified by:
doInWriteLock
in interfaceObjectLock
- Parameters:
objectId
- id of the objectdoInLock
- block to execute within the lock
-
doInWriteLock
public <T> T doInWriteLock(String objectId, Callable<T> doInLock)
Executes the code block after securing a write lock on the objectId. The lock is released after the block completes.- Specified by:
doInWriteLock
in interfaceObjectLock
- Type Parameters:
T
- return type- Parameters:
objectId
- id of the objectdoInLock
- block to execute within the lock- Returns:
- object
-
-