Package net.javacrumbs.shedlock.support
Class StorageBasedLockProvider
- java.lang.Object
-
- net.javacrumbs.shedlock.support.StorageBasedLockProvider
-
- All Implemented Interfaces:
LockProvider
public class StorageBasedLockProvider extends Object implements LockProvider
Distributed lock using abstract storageIt uses a table/collection that contains ID = lock name and a field locked_until.
- Attempts to insert a new lock record. As an optimization, we keep in-memory track of created lock records. If the record has been inserted, returns lock.
- We will try to update lock record using filter ID == name AND lock_until <= now
- If the update succeeded (1 updated row/document), we have the lock. If the update failed (0 updated documents) somebody else holds the lock
- When unlocking, lock_until is set to now.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedStorageBasedLockProvider(@NotNull StorageAccessor storageAccessor)
-
Method Summary
Modifier and Type Method Description voidclearCache()Clears cache of existing lock records.protected booleandoLock(LockConfiguration lockConfiguration)Sets lockUntil according to LockConfiguration if current lockUntil <= now@NotNull Optional<SimpleLock>lock(@NotNull LockConfiguration lockConfiguration)
-
-
-
Constructor Detail
-
StorageBasedLockProvider
protected StorageBasedLockProvider(@NotNull @NotNull StorageAccessor storageAccessor)
-
-
Method Detail
-
clearCache
public void clearCache()
Clears cache of existing lock records.
-
lock
@NotNull public @NotNull Optional<SimpleLock> lock(@NotNull @NotNull LockConfiguration lockConfiguration)
- Specified by:
lockin interfaceLockProvider- Returns:
- If empty optional has been returned, lock could not be acquired. The lock has to be released by the callee.
-
doLock
protected boolean doLock(LockConfiguration lockConfiguration)
Sets lockUntil according to LockConfiguration if current lockUntil <= now
-
-