public boolean lock(@NotEmpty final String lockKey, final String lockInfo) throws JobRuntimeException { if (!this.isEnabled) { log.info("The LockManager is not enabled. Consider the key {} locked.", lockKey); return true; } if (this.lockMap.containsKey(lockKey)) { log.info("The existing lock {} has info {}", lockKey, new String(this.lockMap.get(lockKey).getLockNodeBytes())); return this.lockMap.get(lockKey).isAcquiredInThisProcess(); } else { log.info("Acquiring a new lock for {}", lockKey); final CustomizedInterProcessMutex newLockValue = new CustomizedInterProcessMutex( client.get(), lockKey, lockInfo); try { if (acquireLock(newLockValue)) { log.info("Acquired a new lock for {}", lockKey); lockMap.put(lockKey, newLockValue); return true; } else { log.info("Unable to acquire a new lock for {}", lockKey); return false; } } catch (Exception e) { throw new JobRuntimeException(String.format("Failed to acquire a new lock for %s", lockKey), e); } } }