@Test(expected = AcmObjectLockException.class) public void acquireUnknownLockThrowsException() throws AcmObjectLockException { Long objectId = 1L; String objectType = "FILE"; String lockType = "UNKNOWN"; String userId = "userId"; fileObjectLockingProvider.acquireObjectLock(objectId, objectType, lockType, null, false, userId); fail("AcmObjectLockException should have been thrown for unknown lock type!"); }
@Override public synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry, boolean lockChildObjects, String userId) throws AcmObjectLockException { log.trace("Acquiring object lock[objectId={}, objectType={}, lockType={}] for user: [{}]", objectId, objectType, lockType, userId); FileLockType objectLockType = FileLockType.fromName(lockType); if (expiry == null || expiry == 0) { expiry = getExpiryTimeInMilliseconds(); } checkIfObjectLockCanBeAcquired(objectId, objectType, lockType, lockChildObjects, userId); AcmObjectLock existingLock = objectLockService.findLock(objectId, objectType); String lockedByUserId = userId; if (existingLock != null) { if (objectLockType == FileLockType.READ && !existingLock.getLockType().equals(FileLockType.READ.name())) { return getLock(objectId, objectType, lockType, expiry, userId); } if ((objectLockType == FileLockType.SHARED_WRITE) && existingLock.getLockType().equals(FileLockType.SHARED_WRITE.name())) { lockedByUserId = existingLock.getCreator(); } } return objectLockService.createLock(objectId, objectType, lockType, expiry, lockedByUserId); }
FileLockingProvider implements ObjectLockingProvider { @Override public synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry, boolean lockChildObjects, String userId) throws AcmObjectLockException { log.trace("Acquiring object lock[objectId={}, objectType={}, lockType={}] for user: [{}]", objectId, objectType, lockType, userId); FileLockType objectLockType = FileLockType.fromName(lockType); if (expiry == null || expiry == 0) { expiry = getExpiryTimeInMilliseconds(); } checkIfObjectLockCanBeAcquired(objectId, objectType, lockType, lockChildObjects, userId); AcmObjectLock existingLock = objectLockService.findLock(objectId, objectType); String lockedByUserId = userId; if (existingLock != null) { if (objectLockType == FileLockType.READ && !existingLock.getLockType().equals(FileLockType.READ.name())) { return getLock(objectId, objectType, lockType, expiry, userId); } if ((objectLockType == FileLockType.SHARED_WRITE) && existingLock.getLockType().equals(FileLockType.SHARED_WRITE.name())) { lockedByUserId = existingLock.getCreator(); } } return objectLockService.createLock(objectId, objectType, lockType, expiry, lockedByUserId); } }
FileLockingProvider implements ObjectLockingProvider { @Override public synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry, boolean lockChildObjects, String userId) throws AcmObjectLockException { log.trace("Acquiring object lock[objectId={}, objectType={}, lockType={}] for user: [{}]", objectId, objectType, lockType, userId); FileLockType objectLockType = FileLockType.fromName(lockType); if (expiry == null || expiry == 0) { expiry = getExpiryTimeInMilliseconds(); } checkIfObjectLockCanBeAcquired(objectId, objectType, lockType, lockChildObjects, userId); AcmObjectLock existingLock = objectLockService.findLock(objectId, objectType); String lockedByUserId = userId; if (existingLock != null) { if (objectLockType == FileLockType.READ && !existingLock.getLockType().equals(FileLockType.READ.name())) { return getLock(objectId, objectType, lockType, expiry, userId); } if ((objectLockType == FileLockType.SHARED_WRITE) && existingLock.getLockType().equals(FileLockType.SHARED_WRITE.name())) { lockedByUserId = existingLock.getCreator(); } } return objectLockService.createLock(objectId, objectType, lockType, expiry, lockedByUserId); }  }
FileLockingProvider implements ObjectLockingProvider { @Override public synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry, boolean lockChildObjects, String userId) throws AcmObjectLockException { log.trace("Acquiring object lock[objectId={}, objectType={}, lockType={}] for user: [{}]", objectId, objectType, lockType, userId); FileLockType objectLockType = FileLockType.fromName(lockType); if (expiry == null || expiry == 0) { expiry = getExpiryTimeInMilliseconds(); } checkIfObjectLockCanBeAcquired(objectId, objectType, lockType, lockChildObjects, userId); AcmObjectLock existingLock = objectLockService.findLock(objectId, objectType); String lockedByUserId = userId; if (existingLock != null) { if (objectLockType == FileLockType.READ && !existingLock.getLockType().equals(FileLockType.READ.name())) { return getLock(objectId, objectType, lockType, expiry, userId); } if ((objectLockType == FileLockType.SHARED_WRITE) && existingLock.getLockType().equals(FileLockType.SHARED_WRITE.name())) { lockedByUserId = existingLock.getCreator(); } } return objectLockService.createLock(objectId, objectType, lockType, expiry, lockedByUserId); }  @Override void checkIfObjectLockCanBeAcquired(Long objectId, String objectType, String lockType, boolean checkChildObjects, String userId); @Override synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry,
            boolean lockChildObjects, String userId); @Override synchronized void releaseObjectLock(Long objectId, String objectType, String lockType, boolean unlockChildObjects, String userId,
            Long lockId); @Override Long getExpiryTimeInMilliseconds(); void setExpiryTimeInMilliseconds(Long expiryTimeInMilliseconds); AcmObjectLockService getObjectLockService(); void setObjectLockService(AcmObjectLockService objectLockService); }
FileLockingProvider implements ObjectLockingProvider { @Override public synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry, boolean lockChildObjects, String userId) throws AcmObjectLockException { log.trace("Acquiring object lock[objectId={}, objectType={}, lockType={}] for user: [{}]", objectId, objectType, lockType, userId); FileLockType objectLockType = FileLockType.fromName(lockType); if (expiry == null || expiry == 0) { expiry = getExpiryTimeInMilliseconds(); } checkIfObjectLockCanBeAcquired(objectId, objectType, lockType, lockChildObjects, userId); AcmObjectLock existingLock = objectLockService.findLock(objectId, objectType); String lockedByUserId = userId; if (existingLock != null) { if (objectLockType == FileLockType.READ && !existingLock.getLockType().equals(FileLockType.READ.name())) { return getLock(objectId, objectType, lockType, expiry, userId); } if ((objectLockType == FileLockType.SHARED_WRITE) && existingLock.getLockType().equals(FileLockType.SHARED_WRITE.name())) { lockedByUserId = existingLock.getCreator(); } } return objectLockService.createLock(objectId, objectType, lockType, expiry, lockedByUserId); }  @Override void checkIfObjectLockCanBeAcquired(Long objectId, String objectType, String lockType, boolean checkChildObjects, String userId); @Override synchronized AcmObjectLock acquireObjectLock(Long objectId, String objectType, String lockType, Long expiry,
            boolean lockChildObjects, String userId); @Override synchronized void releaseObjectLock(Long objectId, String objectType, String lockType, boolean unlockChildObjects, String userId,
            Long lockId); @Override Long getExpiryTimeInMilliseconds(); void setExpiryTimeInMilliseconds(Long expiryTimeInMilliseconds); AcmObjectLockService getObjectLockService(); void setObjectLockService(AcmObjectLockService objectLockService);  }