Interface UserResourceLockService<U extends User>
- All Known Implementing Classes:
DefaultUserResourceLockService
User objects. This is meant to be used
for processes that should simultaneously modify a User.
Note that this is different from DefaultUserLockoutService.
DefaultUserLockoutService is to facilitate the user account
lockouts based on login attempts, while this service is to lock the user entity itself,
preventing multiple processes from simultaneously modifying a User.
- Author:
- Sunny Yu
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault <V> VdoWithLock(User user, String lockToken, Function<String, V> function) A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.<V> VdoWithLock(User user, String lockToken, Supplier<V> operation) A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.<V> VA convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.default <V> VdoWithLock(User user, Function<String, V> function) A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.default <V> VdoWithLock(User user, Supplier<V> operation) A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.default <V> VdoWithLock(U user, Duration lockTTL, Function<String, V> function) A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.Attempts to lock theUser, if a lock is not already established.Attempts to lock theUser, if a lock is not already established.voidunlockUser(@NonNull String lockToken) Releases the lock against the user.
-
Method Details
-
lockUser
Attempts to lock theUser, if a lock is not already established. -
lockUser
Attempts to lock theUser, if a lock is not already established. -
doWithLock
A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.If the lock pre-existed before this action, then the lockToken is expected to be non-null. In that case, if the token correlates to an active lock, then the operation will be allowed to proceed. If the token does not match a known lock, then a
ResourceLockExceptionis thrown. If the token is known, but correlates to an expired or unlocked user lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V- type returned fromoperation- Parameters:
user- theUserthat is to be lockedoperation- the operation to perform within the lock- Returns:
- the result of invoking
operation - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if a lock cannot be obtained.
-
doWithLock
A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.If the lock pre-existed before this action, then the lockToken is expected to be non-null. In that case, if the token correlates to an active lock, then the operation will be allowed to proceed. If the token does not match a known lock, then a
ResourceLockExceptionis thrown. If the token is known, but correlates to an expired or unlocked user lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V- type returned fromoperation- Parameters:
user- theUserthat is to be lockedlockToken- Token granted to resource that owns the user lock.operation- the operation to perform within the lock- Returns:
- the result of invoking
operation - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if the token does not match a known lock.
-
doWithLock
A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.If the lock pre-existed before this action, then the lockToken is expected to be non-null. In that case, if the token correlates to an active lock, then the operation will be allowed to proceed. If the token does not match a known lock, then a
ResourceLockExceptionis thrown. If the token is known, but correlates to an expired or unlocked user lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V- type returned fromoperation- Parameters:
user- theUserthat is to be lockedfunction- the function to perform within the lock- Returns:
- the result of invoking
operation - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if a lock cannot be obtained.
-
doWithLock
A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.If the lock pre-existed before this action, then the lockToken is expected to be non-null. In that case, if the token correlates to an active lock, then the operation will be allowed to proceed. If the token does not match a known lock, then a
ResourceLockExceptionis thrown. If the token is known, but correlates to an expired or unlocked user lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V- type returned fromoperation- Parameters:
user- theUserthat is to be lockedlockTTL- How long the lock should be held.function- the function to perform within the lock- Returns:
- the result of invoking
operation - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if a lock cannot be obtained.
-
doWithLock
A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.If the lock pre-existed before this action, then the lockToken is expected to be non-null. In that case, if the token correlates to an active lock, then the operation will be allowed to proceed. If the token does not match a known lock, then a
ResourceLockExceptionis thrown. If the token is known, but correlates to an expired or unlocked user lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V- type returned fromoperation- Parameters:
user- theUserthat is to be lockedlockToken- Token granted to resource that owns the user lock.function- the function to perform within the lock- Returns:
- the result of invoking
operation - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if the token does not match a known lock.
-
doWithLock
<V> V doWithLock(User user, @Nullable Duration lockTTL, @Nullable String lockToken, Function<String, V> function) A convenience method forlockUser(User)andunlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.If the lock pre-existed before this action, then the lockToken is expected to be non-null. In that case, if the token correlates to an active lock, then the operation will be allowed to proceed. If the token does not match a known lock, then a
ResourceLockExceptionis thrown. If the token is known, but correlates to an expired or unlocked user lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V- type returned fromoperation- Parameters:
user- theUserthat is to be lockedlockTTL- How long the lock should be held.lockToken- Token granted to resource that owns the user lock.function- the function to perform within the lock- Returns:
- the result of invoking
operation - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if the token does not match a known lock.
-
unlockUser
Releases the lock against the user.- Parameters:
lockToken- Token granted to resource that owns the user lock.- Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException- if the lock token does not match theUser'slock.
-