Package io.ocfl.core.lock
Class DbObjectLock
- java.lang.Object
-
- io.ocfl.core.lock.DbObjectLock
-
- All Implemented Interfaces:
ObjectLock
public class DbObjectLock extends Object implements ObjectLock
Lock implementation that writes to a DB table to lock a resource. The row is deleted when the lock is released. The lock expires if the row has not been deleted within a configurable period of time.
-
-
Constructor Summary
Constructors Constructor Description DbObjectLock(DbType dbType, String tableName, DataSource dataSource, Duration maxLockDuration)
-
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
-
DbObjectLock
public DbObjectLock(DbType dbType, String tableName, DataSource dataSource, Duration maxLockDuration)
-
-
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
-
-