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 Details

    • lockPayment

      String lockPayment(P payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Attempts to lock the Payment, if a lock is not already established.
      Parameters:
      payment - The Payment 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 the Payment 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 the Payment, if a lock is not already established.
      Parameters:
      payment - The Payment 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 the Payment 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 the Payments, 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 - The Payments 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 the Payment cannot be found within the provided context.
      org.springframework.dao.OptimisticLockingFailureException - if the payment version is out of date
      StalePaymentVersionException - 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 for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      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 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 for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      lockToken - 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 for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      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(P payment, Duration lockTTL, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, Function<String,V> function)
      A convenience method for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      lockTTL - 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 for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      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.
    • 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 for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      lockTTL - 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 for lockPayment(Payment, ContextInfo) and unlockPayment(String) to obtain a lock for a Payment, 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 a ResourceLockException 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 from operation
      Parameters:
      payment - the Payment that is to be locked
      tenantId - the tenant context of this payment
      lockTTL - 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

      void unlockPayment(@NonNull @NonNull String lockToken)
      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 the PaymentLockInfo does not match the Payment's lock.
    • unlockPayments

      void unlockPayments(Collection<String> lockTokens)
      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 the PaymentLockInfo does not match a Payment's lock