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>
SimpleResourceLockRepository
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 Constructor Description NoOpResourceLockRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> V
doWithLock(String contextId, Class<?> type, String sandboxId, 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 sandboxId, 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 sandboxId, 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 unlockString
lockResource(String contextId, Class<?> type, String sandboxId, String conceptKey)
Lock a resource indefinitely based on identifying information.String
lockResourceTemporarily(String contextId, Class<?> type, String sandboxId, String conceptKey)
Lock a resource temporarily based on identifying information.String
lockResourceTemporarily(String contextId, Class<?> type, String sandboxId, String conceptKey, Duration stagnationThreshold)
Lock a resource temporarily based on identifying information.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
.LockStatus
status(String token)
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 Detail
-
lockResource
public String lockResource(String contextId, Class<?> type, String sandboxId, String conceptKey)
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 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
-
lockResourceTemporarily
public String lockResourceTemporarily(String contextId, Class<?> type, String sandboxId, 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 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
- See Also:
ResourceLockProperties.getDefaultStagnationThreshold()
-
lockResourceTemporarily
public String lockResourceTemporarily(String contextId, Class<?> type, String sandboxId, 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 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
-
unlockResource
public void unlockResource(String token)
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
public LockStatus status(String token)
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 sandboxId, 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 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
public <V> V doWithTemporaryLock(String contextId, Class<?> type, String sandboxId, 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 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:
ResourceLockProperties.getDefaultStagnationThreshold()
-
doWithTemporaryLock
public <V> V doWithTemporaryLock(String contextId, Class<?> type, String sandboxId, 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 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
public void purgeLocks(Class<?> type, Duration lockTtl)
Description copied from interface:ResourceLockRepository
Deletes all non-expiring locks that are out of date according to thelockTtl
and haveJpaResourceLock.getTypeAlias()
equal to the providedtype
.- Specified by:
purgeLocks
in interfaceResourceLockRepository<String,String>
- 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.
-
-