public class DatabaseOrderLockManager extends Object implements OrderLockManager
OrderLockManager that relies on the database to provide synchronization
for locks on Orders. This class leverages the OrderLock domain object to provide this
functionality.| Modifier and Type | Field and Description |
|---|---|
protected static org.apache.commons.logging.Log |
LOG |
protected OrderService |
orderService |
| Constructor and Description |
|---|
DatabaseOrderLockManager() |
| Modifier and Type | Method and Description |
|---|---|
Object |
acquireLock(Order order)
Blocks the requesting thread until able to acquire a lock for the given order.
|
Object |
acquireLockIfAvailable(Order order)
This method differs from
OrderLockManager.acquireLock(Order) in that it will not block if the lock is currently
held by a different caller. |
protected int |
getDatabaseLockAcquisitionNumRetries() |
protected long |
getDatabaseLockPollingIntervalMs() |
boolean |
isActive()
This method indicates if the lock manager is active.
|
void |
releaseLock(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.
|
protected static final org.apache.commons.logging.Log LOG
protected OrderService orderService
public Object acquireLock(Order order)
OrderLockManagerOrderLockManager.releaseLock(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);
}acquireLock in interface OrderLockManagerOrderLockManager.releaseLock(Object) once
the operation that required a lock has completed.public Object acquireLockIfAvailable(Order order)
OrderLockManagerOrderLockManager.acquireLock(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.acquireLockIfAvailable in interface OrderLockManagerOrderLockManager.acquireLock(Order)public void releaseLock(Object lockObject)
OrderLockManagerreleaseLock in interface OrderLockManagerprotected long getDatabaseLockPollingIntervalMs()
protected int getDatabaseLockAcquisitionNumRetries()
public boolean isActive()
OrderLockManagerisActive in interface OrderLockManagerCopyright © 2015. All rights reserved.