Class PersistentLockManagerImpl
- java.lang.Object
-
- org.copperengine.core.persistent.lock.PersistentLockManagerImpl
-
- All Implemented Interfaces:
LockManager
,PersistentLockManager
public class PersistentLockManagerImpl extends java.lang.Object implements PersistentLockManager
Implementation for thePersistentLockManager
interface. It needs aPersistentLockManagerDialect
and aTransactionController
to work.
-
-
Constructor Summary
Constructors Constructor Description PersistentLockManagerImpl(PersistentProcessingEngine engine, PersistentLockManagerDialect dialect, TransactionController transactionController)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
acquireLock(java.lang.String lockId, java.lang.String workflowInstanceId)
Acquires a lock with the specified id.void
releaseLock(java.lang.String lockId, java.lang.String workflowInstanceId)
Releases the specified lock.
-
-
-
Constructor Detail
-
PersistentLockManagerImpl
public PersistentLockManagerImpl(PersistentProcessingEngine engine, PersistentLockManagerDialect dialect, TransactionController transactionController)
-
-
Method Detail
-
acquireLock
public java.lang.String acquireLock(java.lang.String lockId, java.lang.String workflowInstanceId)
Description copied from interface:LockManager
Acquires a lock with the specified id. If the lock is free, then the lock is assigned to the caller and the methods returnnull
.Otherwise, if the lock is currently held by another entity, then the method returns a correlationId that the caller has to use to wait for. As soon as this lock is assigned to the caller, the lock manager creates a
Response
for this specified correlationId, containing theLockResult
.Example:
private void acquireLock(final String lockId) throws Interrupt { for (;;) { logger.info("Going to acquire lock '{}'", lockId); final String cid = lockManager.acquireLock(lockId, this.getId()); if (cid == null) { logger.info("Successfully acquired lock '{}'", lockId); return; } else { logger.info("Lock '{}' is currently not free - calling wait...", lockId); wait(WaitMode.ALL, 10000, cid); final Response<LockResult> result = getAndRemoveResponse(cid); logger.info("lock result={}", result); if (result.isTimeout()) { logger.info("Failed to acquire lock: Timeout - trying again..."); } else if (result.getResponse() != LockResult.OK) { logger.error("Failed to acquire lock: {} - trying again...", result.getResponse()); } else { logger.info("Successfully acquired lock '{}'", lockId); return; } } } }
- Specified by:
acquireLock
in interfaceLockManager
- Parameters:
lockId
- symbolic lock idworkflowInstanceId
- requestor/owner of this lock- Returns:
null
if the lock was free and was assigned to the caller (workflowInstanceId) otherwise a correlationId to wait for.
-
releaseLock
public void releaseLock(java.lang.String lockId, java.lang.String workflowInstanceId)
Description copied from interface:LockManager
Releases the specified lock. If the workflow with the specified workflowId is not yet the owner of the lock (i.e. it is still waiting to retrieve the lock), the acquireLock request is removed from the queue.- Specified by:
releaseLock
in interfaceLockManager
- Parameters:
lockId
- symbolic lock idworkflowInstanceId
- requestor/owner of this lock
-
-