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
-
Constructor Summary
ConstructorDescriptionDefaultPaymentLockService
(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> V
doWithLock
(@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> V
doWithLock
(@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.<V> V
doWithLockAndTenantId
(@NonNull Payment payment, @NonNull String tenantId, Duration lockTTL, String lockToken, @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.CrudEntityHelper
protected PaymentVersionValidationService
protected PaymentTransactionServiceProperties
protected 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 P
readByContextId
(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected P
readByContextIdAndTenantId
(@NonNull String id, @NonNull String tenantId) void
unlockPayment
(@NonNull String lockToken) Releases the lock against the payment.void
unlockPayments
(@NonNull Collection<String> lockTokens) Releases the lock against the list of payments.protected void
validatePaymentVersion
(P payment, Integer requestVersion) Validate that the providedPayment
is not out-of-date.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:PaymentLockService
Attempts to lock thePayment
, if a lock is not already established.- Specified by:
lockPayment
in interfacePaymentLockService<P extends Payment>
- Parameters:
payment
- ThePayment
that 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:PaymentLockService
Attempts to lock thePayment
, if a lock is not already established.- Specified by:
lockPayment
in interfacePaymentLockService<P extends Payment>
- 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
.
-
lockPayments
public Map<String,String> lockPayments(@NonNull @NonNull List<P> payments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentLockService
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
- Specified by:
lockPayments
in interfacePaymentLockService<P extends Payment>
- Parameters:
payments
- ThePayments
that 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:PaymentLockService
A 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 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.- Specified by:
doWithLock
in interfacePaymentLockService<P extends Payment>
- 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
-
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:PaymentLockService
A 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 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.- Specified by:
doWithLock
in interfacePaymentLockService<P extends Payment>
- 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
-
doWithLockAndTenantId
public <V> V doWithLockAndTenantId(@NonNull @NonNull Payment payment, @NonNull @NonNull String tenantId, @Nullable Duration lockTTL, @Nullable String lockToken, @NonNull @NonNull Function<String, V> function) Description copied from interface:PaymentLockService
A 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 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.- Specified by:
doWithLockAndTenantId
in interfacePaymentLockService<P extends Payment>
- 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
-
unlockPayment
Description copied from interface:PaymentLockService
Releases the lock against the payment.- Specified by:
unlockPayment
in interfacePaymentLockService<P extends Payment>
- Parameters:
lockToken
- Token granted to resource that owns the payment lock.
-
unlockPayments
Description copied from interface:PaymentLockService
Releases the lock against the list of payments.- Specified by:
unlockPayments
in 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 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.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
- thePayment
that 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 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.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 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.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
- thePayment
that 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
- thePayment
that 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 providedPayment
is not out-of-date.- Parameters:
payment
- the up-to-datePayment
requestVersion
- the version that was provided as part of the request- Throws:
StalePaymentVersionException
- if the requestVersion is out of date.
-
readByContextId
-
readByContextIdAndTenantId
-
getRepository
-
getHelper
protected com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper getHelper() -
getPaymentVersionValidationService
-
getResourceLockRepository
protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> getResourceLockRepository() -
getProperties
-