Interface PaymentLockService<P extends Payment>
- All Known Implementing Classes:
DefaultPaymentLockService
public interface PaymentLockService<P extends Payment>
Service used to lock, unlock, & validate locks on
Payment
objects. This is meant to be
used for processes that should simultaneously modify a Payment
or its
PaymentTransactions
.- Author:
- Chris Kittrell (ckittrell)
-
Method Summary
Modifier and TypeMethodDescriptiondefault <V> V
doWithLock
(Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.default <V> V
doWithLock
(Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Supplier<V> operation) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.default <V> V
doWithLock
(Payment payment, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.<V> V
doWithLock
(Payment payment, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Supplier<V> operation) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.<V> V
doWithLock
(Payment payment, Duration lockTTL, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.default <V> V
doWithLock
(P payment, Duration lockTTL, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.<V> V
doWithLockAndTenantId
(Payment payment, String tenantId, Duration lockTTL, String lockToken, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment.lockPayment
(P payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayment
, if a lock is not already established.lockPayment
(P payment, Duration lockTTL, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayment
, if a lock is not already established.lockPayments
(List<P> payments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayments
, if a lock is not already established.void
unlockPayment
(@NonNull String lockToken) Releases the lock against the payment.void
unlockPayments
(Collection<String> lockTokens) Releases the lock against the list of payments.
-
Method Details
-
lockPayment
String lockPayment(P payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayment
, if a lock is not already established.- Parameters:
payment
- ThePayment
that is being locked.contextInfo
- Context information related to multitenancy.- Returns:
- The locked
Payment
. - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException
- if the payment is already locked.StalePaymentVersionException
- if the provided payment's version is out of date.com.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if thePayment
cannot be found within the provided context.org.springframework.dao.OptimisticLockingFailureException
- if the payment version is out of date
-
lockPayment
String lockPayment(P payment, Duration lockTTL, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayment
, if a lock is not already established.- Parameters:
payment
- ThePayment
that is being locked.lockTTL
- How long the lock should be held.contextInfo
- Context information related to multitenancy.- Returns:
- The locked
Payment
. - Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException
- if the payment is already locked.StalePaymentVersionException
- if the provided payment's version is out of date.com.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if thePayment
cannot be found within the provided context.org.springframework.dao.OptimisticLockingFailureException
- if the payment version is out of date
-
lockPayments
Map<String,String> lockPayments(List<P> payments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayments
, if a lock is not already established. If a lock attempt fails for any of the payments, then none of them will be locked.Note that each lock's time-to-live will be multiplied by the total number of payments to lock
- Parameters:
payments
- ThePayments
that are being locked.contextInfo
- Context information related to multitenancy.- Returns:
- A map of payment id to lock token.
- Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException
- if the payment is already locked.com.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if thePayment
cannot be found within the provided context.org.springframework.dao.OptimisticLockingFailureException
- if the payment version is out of dateStalePaymentVersionException
- if the provided payment's version is out of date.
-
doWithLock
default <V> V doWithLock(Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Supplier<V> operation) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedcontextInfo
- Context information related to multitenancy.operation
- 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
<V> V doWithLock(Payment payment, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Supplier<V> operation) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedlockToken
- Token granted to resource that owns the payment lock.contextInfo
- Context information related to multitenancy.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
default <V> V doWithLock(Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedcontextInfo
- Context information related to multitenancy.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
default <V> V doWithLock(P payment, Duration lockTTL, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedlockTTL
- How long the lock should be held.contextInfo
- Context information related to multitenancy.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
default <V> V doWithLock(Payment payment, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedlockToken
- Token granted to resource that owns the payment lock.contextInfo
- Context information related to multitenancy.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(Payment payment, @Nullable Duration lockTTL, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedlockTTL
- How long the lock should be held.lockToken
- Token granted to resource that owns the payment lock.contextInfo
- Context information related to multitenancy.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.
-
doWithLockAndTenantId
<V> V doWithLockAndTenantId(Payment payment, String tenantId, @Nullable Duration lockTTL, @Nullable String lockToken, Function<String, V> function) A convenience method forlockPayment(Payment, ContextInfo)
andunlockPayment(String)
to obtain a lock for aPayment
, perform an operation, and then unlock the payment. 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 aResourceLockException
is thrown. If the token is known, but correlates to an expired or unlocked payment lock, then we'll attempt to re-establish a lock for the operation. Note: This lock ignores the context filtering logic and finds the payment based on its ID and tenant ID. This means that archived payments will be found when using this lock.- Type Parameters:
V
- type returned fromoperation
- Parameters:
payment
- thePayment
that is to be lockedtenantId
- the tenant context of this paymentlockTTL
- How long the lock should be held.lockToken
- Token granted to resource that owns the payment 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.
-
unlockPayment
Releases the lock against the payment.- Parameters:
lockToken
- Token granted to resource that owns the payment lock.- Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException
- if thePaymentLockInfo
does not match thePayment's
lock.
-
unlockPayments
Releases the lock against the list of payments.- Parameters:
lockTokens
- Tokens granted to resource that owns the payment locks.- Throws:
com.broadleafcommerce.common.messaging.exception.ResourceLockException
- if thePaymentLockInfo
does not match aPayment's
lock
-