Class TransientLockManager
- java.lang.Object
-
- org.copperengine.core.lockmgr.tranzient.TransientLockManager
-
- All Implemented Interfaces:
LockManager
public class TransientLockManager extends java.lang.Object implements LockManager
Implementation for theLockManager
interface for transient engines. Note: This will not work on a cluster with transient engines! Synchronization on a lock id only works for one engine. Note: You might use this for persistent engines as well, but keep in mind, the synchronization only works for workflows on one engine and won't survive system crashes! Might still be useful sometimes..
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TransientLockManager.Locker
-
Field Summary
Fields Modifier and Type Field Description protected ProcessingEngine
engine
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,TransientLockManager.Locker>
lockMap
-
Constructor Summary
Constructors Constructor Description TransientLockManager(ProcessingEngine engine)
-
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.long
curNumberOfLocks()
void
releaseLock(java.lang.String key, java.lang.String workflowInstanceId)
Releases the specified lock.
-
-
-
Field Detail
-
lockMap
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,TransientLockManager.Locker> lockMap
-
engine
protected ProcessingEngine engine
-
-
Constructor Detail
-
TransientLockManager
public TransientLockManager(ProcessingEngine engine)
-
-
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 key, 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:
key
- symbolic lock idworkflowInstanceId
- requestor/owner of this lock
-
curNumberOfLocks
public long curNumberOfLocks()
-
-