Class DefaultPaymentLockService<P extends Payment>
java.lang.Object
com.broadleafcommerce.paymenttransaction.service.DefaultPaymentLockService<P>
- All Implemented Interfaces:
PaymentLockService<P>
public class DefaultPaymentLockService<P extends Payment>
extends Object
implements PaymentLockService<P>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultPaymentLockService(PaymentRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, PaymentVersionValidationService paymentVersionValidationService, com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository, PaymentTransactionServiceProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected <V> V_doWithTemporaryLock(@NonNull Payment payment, @NonNull String lockToken, @NonNull 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.protected <V> V_doWithTemporaryLock(@NonNull Payment payment, @NonNull String lockToken, @NonNull 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.protected <V> V_doWithTemporaryLock(@NonNull Payment payment, @NonNull 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.protected <V> V_doWithTemporaryLock(@NonNull Payment payment, @NonNull 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.protected <V> V_doWithTemporaryLock(@NonNull Payment payment, Duration lockTTL, @NonNull String lockToken, @NonNull 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.protected <V> V_doWithTemporaryLock(@NonNull Payment payment, Duration lockTTL, @NonNull 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> VdoWithLock(@NonNull Payment payment, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull Supplier<V> operation) A convenience method forPaymentLockService.lockPayment(Payment, ContextInfo)andPaymentLockService.unlockPayment(String)to obtain a lock for aPayment, perform an operation, and then unlock the payment.<V> VdoWithLock(@NonNull Payment payment, Duration lockTTL, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull Function<String, V> function) A convenience method forPaymentLockService.lockPayment(Payment, ContextInfo)andPaymentLockService.unlockPayment(String)to obtain a lock for aPayment, perform an operation, and then unlock the payment.protected com.broadleafcommerce.data.tracking.core.service.CrudEntityHelperprotected PaymentVersionValidationServiceprotected PaymentTransactionServicePropertiesprotected PaymentRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> lockPayment(P payment, @NonNull Duration lockTTL, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayment, if a lock is not already established.lockPayment(P payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayment, if a lock is not already established.lockPayments(@NonNull List<P> payments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to lock thePayments, if a lock is not already established.protected PreadByContextId(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidunlockPayment(@NonNull String lockToken) Releases the lock against the payment.voidunlockPayments(@NonNull Collection<String> lockTokens) Releases the lock against the list of payments.protected voidvalidatePaymentVersion(P payment, Integer requestVersion) Validate that the providedPaymentis not out-of-date.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.paymenttransaction.service.PaymentLockService
doWithLock, doWithLock, doWithLock, doWithLock
-
Field Details
-
PAYMENT_LOCK_CONCEPT
- See Also:
-
-
Constructor Details
-
DefaultPaymentLockService
public DefaultPaymentLockService(PaymentRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, PaymentVersionValidationService paymentVersionValidationService, com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository, PaymentTransactionServiceProperties properties)
-
-
Method Details
-
lockPayment
public String lockPayment(@NonNull P payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentLockServiceAttempts to lock thePayment, if a lock is not already established.- Specified by:
lockPaymentin interfacePaymentLockService<P extends Payment>- Parameters:
payment- ThePaymentthat is being locked.contextInfo- Context information related to multitenancy.- Returns:
- The locked
Payment.
-
lockPayment
public String lockPayment(@NonNull P payment, @NonNull @NonNull Duration lockTTL, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentLockServiceAttempts to lock thePayment, if a lock is not already established.- Specified by:
lockPaymentin interfacePaymentLockService<P extends Payment>- Parameters:
payment- ThePaymentthat is being locked.lockTTL- How long the lock should be held.contextInfo- Context information related to multitenancy.- Returns:
- The locked
Payment.
-
lockPayments
public Map<String,String> lockPayments(@NonNull @NonNull List<P> payments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentLockServiceAttempts 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
- Specified by:
lockPaymentsin interfacePaymentLockService<P extends Payment>- Parameters:
payments- ThePaymentsthat are being locked.contextInfo- Context information related to multitenancy.- Returns:
- A map of payment id to lock token.
-
doWithLock
public <V> V doWithLock(@NonNull @NonNull Payment payment, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull @NonNull Supplier<V> operation) Description copied from interface:PaymentLockServiceA convenience method forPaymentLockService.lockPayment(Payment, ContextInfo)andPaymentLockService.unlockPayment(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 aResourceLockExceptionis 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.- Specified by:
doWithLockin interfacePaymentLockService<P extends Payment>- Type Parameters:
V- type returned fromoperation- Parameters:
payment- thePaymentthat 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
-
doWithLock
public <V> V doWithLock(@NonNull @NonNull Payment payment, @Nullable Duration lockTTL, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull @NonNull Function<String, V> function) Description copied from interface:PaymentLockServiceA convenience method forPaymentLockService.lockPayment(Payment, ContextInfo)andPaymentLockService.unlockPayment(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 aResourceLockExceptionis 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.- Specified by:
doWithLockin interfacePaymentLockService<P extends Payment>- Type Parameters:
V- type returned fromoperation- Parameters:
payment- thePaymentthat 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
-
unlockPayment
Description copied from interface:PaymentLockServiceReleases the lock against the payment.- Specified by:
unlockPaymentin interfacePaymentLockService<P extends Payment>- Parameters:
lockToken- Token granted to resource that owns the payment lock.
-
unlockPayments
Description copied from interface:PaymentLockServiceReleases the lock against the list of payments.- Specified by:
unlockPaymentsin interfacePaymentLockService<P extends Payment>- Parameters:
lockTokens- Tokens granted to resource that owns the payment locks.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull Payment payment, @NonNull @NonNull String lockToken, @NonNull @NonNull 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 aResourceLockExceptionis 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- thePaymentthat is to be lockedlockToken- Token granted to resource that owns the payment 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 Payment payment, @NonNull @NonNull 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.- Type Parameters:
V- type returned fromoperation- Parameters:
payment- thePaymentthat 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 Payment payment, @NonNull @NonNull String lockToken, @NonNull @NonNull 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 aResourceLockExceptionis 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- thePaymentthat is to be lockedlockToken- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull Payment payment, @Nullable Duration lockTTL, @NonNull @NonNull String lockToken, @NonNull @NonNull 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 aResourceLockExceptionis 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- thePaymentthat is to be lockedlockTTL- 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.
-
_doWithTemporaryLock
protected <V> V _doWithTemporaryLock(@NonNull @NonNull Payment payment, @NonNull @NonNull 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.- Type Parameters:
V- type returned fromoperation- Parameters:
payment- thePaymentthat 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 Payment payment, @Nullable Duration lockTTL, @NonNull @NonNull 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.- Type Parameters:
V- type returned fromoperation- Parameters:
payment- thePaymentthat 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.
-
validatePaymentVersion
Validate that the providedPaymentis not out-of-date.- Parameters:
payment- the up-to-datePaymentrequestVersion- the version that was provided as part of the request- Throws:
StalePaymentVersionException- if the requestVersion is out of date.
-
readByContextId
-
getRepository
-
getHelper
protected com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper getHelper() -
getPaymentVersionValidationService
-
getResourceLockRepository
protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> getResourceLockRepository() -
getProperties
-