Interface ResourceLockRepository<D,ID>
- All Superinterfaces:
org.springframework.data.repository.Repository<D,
ID>
- All Known Subinterfaces:
JpaResourceLockRepository
- All Known Implementing Classes:
JpaCustomizedResourceLockRepository
,NoOpResourceLockRepository
@NoRepositoryBean
public interface ResourceLockRepository<D,ID>
extends org.springframework.data.repository.Repository<D,ID>
Repository responsible for allowing requesters to lock and unlock a resource. This prevents
concurrent mutation of a resource, particularly during sandbox workflow operations. For example,
a reject operation would lock a resource and prevent a promotion operation for that same resource
from occurring until the completion of the reject.
- Author:
- Jeff Fischer
-
Method Summary
Modifier and TypeMethodDescription<V> V
doWithLock
(String contextId, Class<?> type, String sandboxId, String conceptKey, Supplier<V> operation) A convenience method forlockResource(String, Class, String, String)
andunlockResource(String)
to obtainin a lock, perform an operation and then unlock<V> V
doWithTemporaryLock
(String contextId, Class<?> type, String sandboxId, String conceptKey, Duration stagnationThreshold, Supplier<V> operation) A convenience method forlockResource(String, Class, String, String)
andunlockResource(String)
to obtainin a lock, perform an operation and then unlock<V> V
doWithTemporaryLock
(String contextId, Class<?> type, String sandboxId, String conceptKey, Supplier<V> operation) A convenience method forlockResource(String, Class, String, String)
andunlockResource(String)
to obtain a temporary lock, perform an operation and then unlocklockResource
(String contextId, Class<?> type, String sandboxId, String conceptKey) Lock a resource indefinitely based on identifying information.lockResourceTemporarily
(String contextId, Class<?> type, String sandboxId, String conceptKey) Lock a resource temporarily based on identifying information.lockResourceTemporarily
(String contextId, Class<?> type, String sandboxId, String conceptKey, Duration stagnationThreshold) Lock a resource temporarily based on identifying information.default void
purgeLocks
(Class<?> type, Duration lockTtl) Deletes all non-expiring locks that are out of date according to thelockTtl
and haveJpaResourceLock.getTypeAlias()
equal to the providedtype
.void
purgeLocks
(Set<String> lockTypes, Duration lockTtl) Deletes all non-expiring locks that are out of date according to thelockTtl
and haveJpaResourceLock.getTypeAlias()
equal to the providedlockTypes
.Report on the status of the lock.void
unlockResource
(String token) Unlock the resource so that other requesters can acquire the lock on the resource.
-
Method Details
-
lockResource
String lockResource(String contextId, Class<?> type, @Nullable String sandboxId, @Nullable String conceptKey) Lock a resource indefinitely based on identifying information. Will return a token representing the lock that is suitable to be passed tounlockResource(String)
when the work requiring the lock is complete. If unable to acquire the lock, aResourceLockException
is thrown.- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdsandboxId
- sandbox associated with the entityconceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking place- Returns:
- The token that identifies the lock
- Throws:
ResourceLockException
- if the lock could not be acquired
-
lockResourceTemporarily
String lockResourceTemporarily(String contextId, Class<?> type, @Nullable String sandboxId, @Nullable String conceptKey) Lock a resource temporarily based on identifying information. Will return a token representing the lock that is suitable to be passed tounlockResource(String)
when the work requiring the lock is complete. If unable to acquire the lock, aResourceLockException
is thrown.- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdsandboxId
- sandbox associated with the entityconceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking place- Returns:
- The token that identifies the lock
- Throws:
ResourceLockException
- if the lock could not be acquired- See Also:
-
lockResourceTemporarily
String lockResourceTemporarily(String contextId, Class<?> type, @Nullable String sandboxId, @Nullable String conceptKey, Duration stagnationThreshold) Lock a resource temporarily based on identifying information. Will return a token representing the lock that is suitable to be passed tounlockResource(String)
when the work requiring the lock is complete. If unable to acquire the lock, aResourceLockException
is thrown.- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdsandboxId
- sandbox associated with the entityconceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking placestagnationThreshold
- how long the lock should be held- Returns:
- The token that identifies the lock
- Throws:
ResourceLockException
- if the lock could not be acquired
-
unlockResource
Unlock the resource so that other requesters can acquire the lock on the resource.- Parameters:
token
- The identifying token for the lock
-
status
Report on the status of the lock. Especially useful if the token is distributed outside of a discrete flow.- Parameters:
token
- The identifying token for the lock- Returns:
- The status of the lock
- Throws:
ResourceLockException
- if the lock status cannot be determined
-
doWithLock
<V> V doWithLock(String contextId, Class<?> type, @Nullable String sandboxId, @Nullable String conceptKey, Supplier<V> operation) A convenience method forlockResource(String, Class, String, String)
andunlockResource(String)
to obtainin a lock, perform an operation and then unlock- Type Parameters:
V
- type returned fromoperation
- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdsandboxId
- sandbox associated with the entityconceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking placeoperation
- the operation to perform within the lock- Returns:
- the result of invoking
operation
-
doWithTemporaryLock
<V> V doWithTemporaryLock(String contextId, Class<?> type, @Nullable String sandboxId, @Nullable String conceptKey, Supplier<V> operation) A convenience method forlockResource(String, Class, String, String)
andunlockResource(String)
to obtain a temporary lock, perform an operation and then unlock- Type Parameters:
V
- type returned fromoperation
- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdsandboxId
- sandbox associated with the entityconceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking placeoperation
- the operation to perform within the lock- Returns:
- the result of invoking
operation
- See Also:
-
doWithTemporaryLock
<V> V doWithTemporaryLock(String contextId, Class<?> type, @Nullable String sandboxId, @Nullable String conceptKey, Duration stagnationThreshold, Supplier<V> operation) A convenience method forlockResource(String, Class, String, String)
andunlockResource(String)
to obtainin a lock, perform an operation and then unlock- Type Parameters:
V
- type returned fromoperation
- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdsandboxId
- sandbox associated with the entityconceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking placestagnationThreshold
- how long the lock should be heldoperation
- the operation to perform within the lock- Returns:
- the result of invoking
operation
-
purgeLocks
Deletes all non-expiring locks that are out of date according to thelockTtl
and haveJpaResourceLock.getTypeAlias()
equal to the providedtype
.- Parameters:
type
- The type of lock that is to be removedlockTtl
- How long the lock should be held. If the lock is too old, then it should be removed.
-
purgeLocks
Deletes all non-expiring locks that are out of date according to thelockTtl
and haveJpaResourceLock.getTypeAlias()
equal to the providedlockTypes
.- Parameters:
lockTypes
- The types of locks that are to be removedlockTtl
- How long the lock should be held. If the lock is too old, then it should be removed.
-