Class DefaultUserResourceLockService<U extends User>
- All Implemented Interfaces:
UserResourceLockService<U>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultUserResourceLockService(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository, AuthenticationResourceLockProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected <V> V_doWithTemporaryLock(@NonNull User user, @NonNull String lockToken, @NonNull Function<String, V> function) A convenience method for locking the user with the configured time-to-live fromAuthenticationResourceLockProperties.getUserLockTtl(), perform an operation, and then unlock the user.protected <V> V_doWithTemporaryLock(@NonNull User user, @NonNull String lockToken, @NonNull Supplier<V> operation) A convenience method for perform an operation with an existing lock token.protected <V> V_doWithTemporaryLock(@NonNull User user, @NonNull Function<String, V> function) A convenience method for locking theUser, perform an operation, and then unlock the user.protected <V> V_doWithTemporaryLock(@NonNull User user, @NonNull Supplier<V> operation) A convenience method for locking the user with the configured time-to-live fromAuthenticationResourceLockProperties.getUserLockTtl(), perform an operation, and then unlock the user.protected <V> V_doWithTemporaryLock(@NonNull User user, Duration lockTTL, @NonNull String lockToken, @NonNull Function<String, V> function) A convenience method for perform an operation with an existing lock token.protected <V> V_doWithTemporaryLock(@NonNull User user, Duration lockTTL, @NonNull Function<String, V> function) A convenience method for locking theUser, perform an operation, and then unlock the user.<V> VdoWithLock(@NonNull User user, String lockToken, @NonNull Supplier<V> operation) A convenience method forUserResourceLockService.lockUser(User)andUserResourceLockService.unlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.<V> VdoWithLock(@NonNull User user, Duration lockTTL, String lockToken, @NonNull Function<String, V> function) A convenience method forUserResourceLockService.lockUser(User)andUserResourceLockService.unlockUser(String)to obtain a lock for aUser, perform an operation, and then unlock the user.protected AuthenticationResourceLockPropertiesprotected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> 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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.auth.user.service.UserResourceLockService
doWithLock, doWithLock, doWithLock, doWithLock
-
Field Details
-
USER_LOCK_CONCEPT
- See Also:
-
-
Constructor Details
-
DefaultUserResourceLockService
public DefaultUserResourceLockService(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository, AuthenticationResourceLockProperties properties)
-
-
Method Details
-
lockUser
Description copied from interface:UserResourceLockServiceAttempts to lock theUser, if a lock is not already established. -
lockUser
Description copied from interface:UserResourceLockServiceAttempts to lock theUser, if a lock is not already established. -
doWithLock
public <V> V doWithLock(@NonNull @NonNull User user, @Nullable String lockToken, @NonNull @NonNull Supplier<V> operation) Description copied from interface:UserResourceLockServiceA convenience method forUserResourceLockService.lockUser(User)andUserResourceLockService.unlockUser(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.- Specified by:
doWithLockin interfaceUserResourceLockService<U extends User>- 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
-
doWithLock
public <V> V doWithLock(@NonNull @NonNull User user, @Nullable Duration lockTTL, @Nullable String lockToken, @NonNull @NonNull Function<String, V> function) Description copied from interface:UserResourceLockServiceA convenience method forUserResourceLockService.lockUser(User)andUserResourceLockService.unlockUser(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.- Specified by:
doWithLockin interfaceUserResourceLockService<U extends User>- 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
-
unlockUser
Description copied from interface:UserResourceLockServiceReleases the lock against the user.- Specified by:
unlockUserin interfaceUserResourceLockService<U extends User>- Parameters:
lockToken- Token granted to resource that owns the user lock.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull User user, @NonNull @NonNull String lockToken, @NonNull @NonNull Supplier<V> operation) A convenience method for perform an operation with an existing lock token. If the given lock token isLockStatus.ACTIVE, then the operation is performed, otherwise a new lock is obtained via_doWithTemporaryLock(User, Supplier).- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull User user, @NonNull @NonNull Supplier<V> operation) A convenience method for locking the user with the configured time-to-live fromAuthenticationResourceLockProperties.getUserLockTtl(), perform an operation, and then unlock the user.- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull User user, @NonNull @NonNull String lockToken, @NonNull @NonNull Function<String, V> function) A convenience method for locking the user with the configured time-to-live fromAuthenticationResourceLockProperties.getUserLockTtl(), perform an operation, and then unlock the user.- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull User user, @Nullable Duration lockTTL, @NonNull @NonNull String lockToken, @NonNull @NonNull Function<String, V> function) A convenience method for perform an operation with an existing lock token. If the given lock token isLockStatus.ACTIVE, then the operation is performed, otherwise a new lock is obtained via_doWithTemporaryLock(User, Function).- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull User user, @NonNull @NonNull Function<String, V> function) A convenience method for locking theUser, perform an operation, and then unlock the user.- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull User user, @Nullable Duration lockTTL, @NonNull @NonNull Function<String, V> function) A convenience method for locking theUser, perform an operation, and then unlock the user.- 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.
-
getResourceLockRepository
protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> getResourceLockRepository() -
getProperties
-