Interface OrderLockManager
public interface OrderLockManager
It is recommended to only allow one write operation on orders at a time. For example, if two add to cart operations
for the same order came through at the same time, we would want to execute them serially and not in parallel.
Implementations of this interface are responsible for maintaining the lock status for the given order.
- Author:
- Andre Azzolini (apazzolini)
-
Method Summary
Modifier and TypeMethodDescriptionacquireLock(Order order) Blocks the requesting thread until able to acquire a lock for the given order.acquireLockIfAvailable(Order order) This method differs fromacquireLock(Order)in that it will not block if the lock is currently held by a different caller.booleanisActive()This method indicates if the lock manager is active.voidreleaseLock(Object lockObject) Releases the given lockObject and notifies any threads that are waiting on that object that they are able to attempt to acquire the lock.
-
Method Details
-
acquireLock
Blocks the requesting thread until able to acquire a lock for the given order. NOTE: Callers of this method MUST callreleaseLock(Object), passing in the Object returned from this call once their critical section has executed. The suggested idiom for this operation is:Object lockObject = null; try { lockObject = orderLockManager.acquireLock(order); // Do something } finally { orderLockManager.releaseLock(lockObject); }
- Parameters:
order-- Returns:
- the lock object, which should be passed in as the parameter to
releaseLock(Object)once the operation that required a lock has completed.
-
acquireLockIfAvailable
This method differs fromacquireLock(Order)in that it will not block if the lock is currently held by a different caller. In the case that the lock was not able to be immediately acquired, this method will return null.- Parameters:
order-- Returns:
- the lock if it was immediately acquireable, null otherwise
- See Also:
-
releaseLock
Releases the given lockObject and notifies any threads that are waiting on that object that they are able to attempt to acquire the lock.- Parameters:
lockObject-
-
isActive
boolean isActive()This method indicates if the lock manager is active. It can return a static value or a dynamic one based on values in the BroadleafRequestContext or other stateful mechanism. A good example of when this might be dynamic is when there is a session-based lock and the request indicates that it is not OK to use sessions.- Returns:
-