Class PersistentLockManagerImpl

    • 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 return null.

        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 the LockResult.

        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 interface LockManager
        Parameters:
        lockId - symbolic lock id
        workflowInstanceId - 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 interface LockManager
        Parameters:
        lockId - symbolic lock id
        workflowInstanceId - requestor/owner of this lock