public void acquireReadLock() throws InterruptedException { this.lock.attemptLock(LockMode.READ_ONLY, -1, null); }
public final void releaseLock(final LockMode mode, final boolean releaseAll, Object owner) { releaseLock(mode, releaseAll, owner, null); }
public void run() { try { if (this.l.attemptLock(LockMode.SH, waitMillisForTakingLock, null)) { Thread.sleep(this.sleepMillisAfterTakingLock); } else { failed = true; } } catch (InterruptedException e) { fail("did not expect exception in taking read locks"); } this.l.releaseLock(LockMode.SH, false, null); } }
public void _testLockBehaviourQueue() throws Exception { final Object id = new String("id"); final ReentrantReadWriteWriteShareLock lock = new ReentrantReadWriteWriteShareLock(); assertTrue(lock.attemptLock(LockMode.EX_SH, 0, id)); assertTrue(lock.attemptLock(LockMode.SH, 0, null)); for (int i = 0; i < MAX_READ_SHARED_COUNT * 5; i++) { if (i % MAX_WRITE_COUNT == 0) { lock.releaseLock(LockMode.EX_SH, true, id); try { lock.releaseLock(LockMode.EX_SH, false, id); fail("write share release clears the write bits, so second attempt " + "should fail");
public void testLockBehaviourWithDIfferentThread() throws Exception { final Object id = new String("id"); final ReentrantReadWriteWriteShareLock lock = new ReentrantReadWriteWriteShareLock(); assertTrue(lock.attemptLock(LockMode.EX_SH, 0, id)); Locker locker = new Locker(lock, id, true, true, "R:S:E", "P:P:P"); Thread t = new Thread(locker); t.start(); t.join(); // lock again as it would have been released assertTrue(lock.attemptLock(LockMode.EX_SH, 0, id)); locker = new Locker(lock, id, false, true, "R:S:E", "P:F:F"); Thread t1 = new Thread(locker); t1.start(); t1.join(); }
public void releaseSnapshotGIIWriteLock() { if (writeLockEnabled()) { if (this.getPartitionedRegion().isInternalColumnTable()) { BucketRegion bufferRegion = getBufferRegion(); bufferRegion.releaseSnapshotGIIWriteLock(); } else { final LogWriterI18n logger = getCache().getLoggerI18n(); if (logger.fineEnabled()) { logger.fine("Releasing exclusive snapshotGIILock on bucket " + this.getName()); } if (this.snapshotGIILock.hasExclusiveLock(giiWriteLockForSIOwner, null)) { if (snapshotGIILocked) { snapshotGIILock.releaseLock(LockMode.EX, false, giiWriteLockForSIOwner); getBucketAdvisor().removeMembershipListener(giiListener); this.giiListener = null; snapshotGIILocked = false; } } if (logger.fineEnabled()) { logger.fine("Released exclusive snapshotGIILock on bucket " + this.getName()); } } } }
/** * @see ExclusiveSharedLockObject#attemptLock */ public final boolean attemptLock(final LockMode mode, final int flags, final LockingPolicy lockPolicy, final long msecs, Object owner, final Object context) { if (owner == null) { owner = Thread.currentThread(); } if (mode == LockMode.EX) { return attemptExclusiveLock(flags, lockPolicy, msecs, owner, context); } return attemptSharedLock(mode.getLockModeArg() | flags, lockPolicy, msecs, owner, context); }
final Object id2 = new String("id2"); final ReentrantReadWriteWriteShareLock lock = new ReentrantReadWriteWriteShareLock(); assertTrue(lock.attemptLock(LockMode.SH, 0, null)); lock.attemptLock(LockMode.SH, 0, null); fail("attempt to acquire read lock after max possible read: " + MAX_READ_SHARED_COUNT + " should have failed"); lock.releaseLock(LockMode.SH, false, null); lock.releaseLock(LockMode.SH, true, null); fail("attempt to release read lock when read count is 0 " + "should have failed"); assertTrue(lock.attemptLock(LockMode.EX_SH, 0, id)); lock.attemptLock(LockMode.EX_SH, 0, id); fail("attempt to acquire write share lock after max possible write share: " + MAX_WRITE_COUNT + " should have failed"); lock.releaseLock(LockMode.EX_SH, true, id2); fail("attempt to release write share lock when " + "owner is different should fail"); lock.releaseLock(LockMode.EX_SH, true, id); lock.releaseLock(LockMode.EX_SH, false, id);
case 'R': if (shouldPass) { assertTrue(this.l.attemptLock(LockMode.SH, 0, null)); assertFalse(this.l.attemptLock(LockMode.SH, 0, null)); this.l.releaseLock(LockMode.SH, false, null); assertTrue(this.l.attemptLock(LockMode.EX_SH, 0, this.id)); assertTrue(this.l.attemptLock(LockMode.EX_SH, 0, "someId")); assertFalse(this.l.attemptLock(LockMode.EX_SH, 0, "someId")); this.l.releaseLock(LockMode.EX_SH, true, id); assertTrue(this.l.attemptLock(LockMode.EX, 0, this.id)); assertTrue(this.l.attemptLock(LockMode.EX, 0, "someid")); assertFalse(this.l.attemptLock(LockMode.EX, 0, "someid")); this.l.releaseLock(LockMode.EX, true, id);
public void testLockBehaviourWithSameThread() throws Exception { final Object id = new String("id"); final ReentrantReadWriteWriteShareLock lock = new ReentrantReadWriteWriteShareLock(); assertTrue(lock.attemptLock(LockMode.SH, 0, null)); assertTrue(lock.attemptLock(LockMode.EX_SH, 0, id)); assertFalse(lock.attemptLock(LockMode.EX, 0, id)); lock.releaseLock(LockMode.SH, true, null); assertTrue(lock.attemptLock(LockMode.SH, 0, null)); assertTrue(lock.attemptLock(LockMode.EX_SH, 0, id)); assertFalse(lock.attemptLock(LockMode.EX, 0, id)); lock.releaseLock(LockMode.SH, false, null); lock.releaseLock(LockMode.EX_SH, false, id); assertTrue(lock.attemptLock(LockMode.SH, 0, id)); assertFalse(lock.attemptLock(LockMode.EX, 0, id)); lock.releaseLock(LockMode.SH, true, null); assertTrue(lock.attemptLock(LockMode.SH, 0, null)); assertFalse(lock.attemptLock(LockMode.EX, 0, id)); lock.releaseLock(LockMode.SH, false, id); assertTrue(lock.attemptLock(LockMode.SH, 0, id)); assertFalse(lock.attemptLock(LockMode.EX, 0, id)); lock.releaseLock(LockMode.SH, true, id); assertTrue(lock.attemptLock(LockMode.EX, 0, id));
public final boolean attemptLock(final LockMode mode, final long msecs, final Object owner) { return attemptLock(mode, 0, LockingPolicy.NONE, msecs, owner, null); }
public void releaseReadLock() { this.lock.releaseLock(LockMode.READ_ONLY, false, null); }
public void acquireWriteLock() throws InterruptedException { this.lock.attemptLock(LockMode.EX, -1, null); }
public void releaseWriteLock() { this.lock.releaseLock(LockMode.EX, false, null); }
public void acquireWriteLock() throws InterruptedException { this.lock.attemptLock(LockMode.EX, -1, null); }
public void releaseWriteLock() { this.lock.releaseLock(LockMode.EX_SH, false, null); }
public void acquireWriteLock() throws InterruptedException { this.lock.attemptLock(LockMode.EX_SH, -1, null); }
public void releaseReadLock() { this.lock.releaseLock(LockMode.SH, false, null); }
public void acquireReadLock() throws InterruptedException { this.lock.attemptLock(LockMode.SH, -1, null); }
public void releaseWriteLock() { this.lock.releaseLock(LockMode.EX, false, null); }