@Test public void unlockNonExistingLock() throws Exception { long badLockId = 1; assertFalse(mLockManager.unlockBlockNoException(badLockId)); }
public boolean unlockBlockNoException(long lockId) { Lock lock; LockRecord record; try (LockResource r = new LockResource(mSharedMapsLock.writeLock())) { record = mLockIdToRecordMap.get(lockId); if (record == null) { return false; } long sessionId = record.getSessionId(); lock = record.getLock(); mLockIdToRecordMap.remove(lockId); Set<Long> sessionLockIds = mSessionIdToLockIdsMap.get(sessionId); sessionLockIds.remove(lockId); if (sessionLockIds.isEmpty()) { mSessionIdToLockIdsMap.remove(sessionId); } } unlock(lock, record.getBlockId()); return true; }
BlockLockManager { public boolean unlockBlockNoException(long lockId) { Lock lock; LockRecord record; try (LockResource r = new LockResource(mSharedMapsLock.writeLock())) { record = mLockIdToRecordMap.get(lockId); if (record == null) { return false; } long sessionId = record.getSessionId(); lock = record.getLock(); mLockIdToRecordMap.remove(lockId); Set<Long> sessionLockIds = mSessionIdToLockIdsMap.get(sessionId); sessionLockIds.remove(lockId); if (sessionLockIds.isEmpty()) { mSessionIdToLockIdsMap.remove(sessionId); } } unlock(lock, record.getBlockId()); return true; } }
BlockLockManager { public boolean unlockBlockNoException(long lockId) { Lock lock; LockRecord record; try (LockResource r = new LockResource(mSharedMapsLock.writeLock())) { record = mLockIdToRecordMap.get(lockId); if (record == null) { return false; } long sessionId = record.getSessionId(); lock = record.getLock(); mLockIdToRecordMap.remove(lockId); Set<Long> sessionLockIds = mSessionIdToLockIdsMap.get(sessionId); sessionLockIds.remove(lockId); if (sessionLockIds.isEmpty()) { mSessionIdToLockIdsMap.remove(sessionId); } } unlock(lock, record.getBlockId()); return true; } BlockLockManager(); }
BlockLockManager { public boolean unlockBlockNoException(long lockId) { Lock lock; LockRecord record; try (LockResource r = new LockResource(mSharedMapsLock.writeLock())) { record = mLockIdToRecordMap.get(lockId); if (record == null) { return false; } long sessionId = record.getSessionId(); lock = record.getLock(); mLockIdToRecordMap.remove(lockId); Set<Long> sessionLockIds = mSessionIdToLockIdsMap.get(sessionId); sessionLockIds.remove(lockId); if (sessionLockIds.isEmpty()) { mSessionIdToLockIdsMap.remove(sessionId); } } unlock(lock, record.getBlockId()); return true; } BlockLockManager(); long lockBlock(long sessionId, long blockId, BlockLockType blockLockType); boolean unlockBlockNoException(long lockId); void unlockBlock(long lockId); boolean unlockBlock(long sessionId, long blockId); void validateLock(long sessionId, long blockId, long lockId); void cleanupSession(long sessionId); Set<Long> getLockedBlocks(); void validate(); }
BlockLockManager { public boolean unlockBlockNoException(long lockId) { Lock lock; LockRecord record; try (LockResource r = new LockResource(mSharedMapsLock.writeLock())) { record = mLockIdToRecordMap.get(lockId); if (record == null) { return false; } long sessionId = record.getSessionId(); lock = record.getLock(); mLockIdToRecordMap.remove(lockId); Set<Long> sessionLockIds = mSessionIdToLockIdsMap.get(sessionId); sessionLockIds.remove(lockId); if (sessionLockIds.isEmpty()) { mSessionIdToLockIdsMap.remove(sessionId); } } unlock(lock, record.getBlockId()); return true; } BlockLockManager(); long lockBlock(long sessionId, long blockId, BlockLockType blockLockType); boolean unlockBlockNoException(long lockId); void unlockBlock(long lockId); boolean unlockBlock(long sessionId, long blockId); void validateLock(long sessionId, long blockId, long lockId); void cleanupSession(long sessionId); Set<Long> getLockedBlocks(); void validate(); static final long INVALID_LOCK_ID; }