Class NoOpResourceLockRepository
java.lang.Object
com.broadleafcommerce.common.messaging.repository.NoOpResourceLockRepository
- All Implemented Interfaces:
ResourceLockRepository<String,
,String> org.springframework.data.repository.Repository<String,
String>
public class NoOpResourceLockRepository
extends Object
implements ResourceLockRepository<String,String>
Simple
ResourceLockRepository
implementation that DOES NOTHING. This implementation is
meant to serve as a placeholder in the case that a specific data provider is not registered - ie
for integration tests that depend on this module.- Author:
- Chris Kittrell (ckittrell)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<V> V
doWithLock
(String contextId, Class<?> type, String optional, String conceptKey, Supplier<V> operation) A convenience method forResourceLockRepository.lockResource(String, Class, String, String)
andResourceLockRepository.unlockResource(String)
to obtainin a lock, perform an operation and then unlock<V> V
doWithTemporaryLock
(String contextId, Class<?> type, String optional, String conceptKey, Duration stagnationThreshold, Supplier<V> operation) A convenience method forResourceLockRepository.lockResource(String, Class, String, String)
andResourceLockRepository.unlockResource(String)
to obtainin a lock, perform an operation and then unlock<V> V
doWithTemporaryLock
(String contextId, Class<?> type, String optional, String conceptKey, Supplier<V> operation) A convenience method forResourceLockRepository.lockResource(String, Class, String, String)
andResourceLockRepository.unlockResource(String)
to obtain a temporary lock, perform an operation and then unlocklockResource
(String contextId, Class<?> type, String optional, String conceptKey) Lock a resource indefinitely based on identifying information.lockResourceTemporarily
(String contextId, Class<?> type, String optional, String conceptKey) Lock a resource temporarily based on identifying information.lockResourceTemporarily
(String contextId, Class<?> type, String optional, String conceptKey, Duration stagnationThreshold) Lock a resource temporarily based on identifying information.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.common.messaging.repository.ResourceLockRepository
attemptTakeover, purgeLocks, updateState
-
Constructor Details
-
NoOpResourceLockRepository
public NoOpResourceLockRepository()
-
-
Method Details
-
lockResource
Description copied from interface:ResourceLockRepository
Lock a resource indefinitely based on identifying information. Will return a token representing the lock that is suitable to be passed toResourceLockRepository.unlockResource(String)
when the work requiring the lock is complete. If unable to acquire the lock, aResourceLockException
is thrown.- Specified by:
lockResource
in interfaceResourceLockRepository<String,
String> - Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdoptional
- Optional information associated with the lock. Common values are sandboxId and status.conceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking place- Returns:
- The token that identifies the lock
-
lockResourceTemporarily
public String lockResourceTemporarily(String contextId, Class<?> type, String optional, String conceptKey) Description copied from interface:ResourceLockRepository
Lock a resource temporarily based on identifying information. Will return a token representing the lock that is suitable to be passed toResourceLockRepository.unlockResource(String)
when the work requiring the lock is complete. If unable to acquire the lock, aResourceLockException
is thrown.- Specified by:
lockResourceTemporarily
in interfaceResourceLockRepository<String,
String> - Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdoptional
- Optional information associated with the lock. Common values are sandboxId and status.conceptKey
- a generally descriptive key that identifies the overall concept for which the lock is taking place- Returns:
- The token that identifies the lock
- See Also:
-
lockResourceTemporarily
public String lockResourceTemporarily(String contextId, Class<?> type, String optional, String conceptKey, Duration stagnationThreshold) Description copied from interface:ResourceLockRepository
Lock a resource temporarily based on identifying information. Will return a token representing the lock that is suitable to be passed toResourceLockRepository.unlockResource(String)
when the work requiring the lock is complete. If unable to acquire the lock, aResourceLockException
is thrown.- Specified by:
lockResourceTemporarily
in interfaceResourceLockRepository<String,
String> - Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdoptional
- Optional information associated with the lock. Common values are sandboxId and status.conceptKey
- 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
-
unlockResource
Description copied from interface:ResourceLockRepository
Unlock the resource so that other requesters can acquire the lock on the resource.- Specified by:
unlockResource
in interfaceResourceLockRepository<String,
String> - Parameters:
token
- The identifying token for the lock
-
status
Description copied from interface:ResourceLockRepository
Report on the status of the lock. Especially useful if the token is distributed outside of a discrete flow.- Specified by:
status
in interfaceResourceLockRepository<String,
String> - Parameters:
token
- The identifying token for the lock- Returns:
- The status of the lock
-
doWithLock
public <V> V doWithLock(String contextId, Class<?> type, String optional, String conceptKey, Supplier<V> operation) Description copied from interface:ResourceLockRepository
A convenience method forResourceLockRepository.lockResource(String, Class, String, String)
andResourceLockRepository.unlockResource(String)
to obtainin a lock, perform an operation and then unlock- Specified by:
doWithLock
in interfaceResourceLockRepository<String,
String> - Type Parameters:
V
- type returned fromoperation
- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdoptional
- Optional information associated with the lock. Common values are sandboxId and status.conceptKey
- 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
public <V> V doWithTemporaryLock(String contextId, Class<?> type, String optional, String conceptKey, Supplier<V> operation) Description copied from interface:ResourceLockRepository
A convenience method forResourceLockRepository.lockResource(String, Class, String, String)
andResourceLockRepository.unlockResource(String)
to obtain a temporary lock, perform an operation and then unlock- Specified by:
doWithTemporaryLock
in interfaceResourceLockRepository<String,
String> - Type Parameters:
V
- type returned fromoperation
- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdoptional
- Optional information associated with the lock. Common values are sandboxId and status.conceptKey
- 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
public <V> V doWithTemporaryLock(String contextId, Class<?> type, String optional, String conceptKey, Duration stagnationThreshold, Supplier<V> operation) Description copied from interface:ResourceLockRepository
A convenience method forResourceLockRepository.lockResource(String, Class, String, String)
andResourceLockRepository.unlockResource(String)
to obtainin a lock, perform an operation and then unlock- Specified by:
doWithTemporaryLock
in interfaceResourceLockRepository<String,
String> - Type Parameters:
V
- type returned fromoperation
- Parameters:
contextId
- a unique id of the obtain a lock fortype
- grouping for the contextIdoptional
- Optional information associated with the lock. Common values are sandboxId and status.conceptKey
- 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
Description copied from interface:ResourceLockRepository
Deletes all non-expiring locks that are out of date according to thelockTtl
and haveJpaResourceLock.getTypeAlias()
equal to the providedlockTypes
.- Specified by:
purgeLocks
in interfaceResourceLockRepository<String,
String> - 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.
-