/** * @return the {@link ReadWriteLock#readLock()}, locked */ public AutoLock autoReadLock() { return readLock.autoLock(); }
/** * Unlocks the underlying {@link Lock}. */ @Override public void close() { unlock(); }
@Test public void testDefault() throws Exception { AutoLock al = new AutoLock(); assertNotNull(al.autoLock()); assertNotNull(al.toString()); assertNotNull(al.newCondition()); al.lockInterruptibly(); al.unlock(); assertTrue(al.tryLock()); al.unlock(); assertTrue(al.tryLock(1, TimeUnit.SECONDS)); al.unlock(); }
@Test public void testClose() { ReentrantLock lock = new ReentrantLock(); assertFalse(lock.isHeldByCurrentThread()); AutoLock al = new AutoLock(lock); assertFalse(lock.isHeldByCurrentThread()); al.autoLock(); assertTrue(lock.isHeldByCurrentThread()); al.close(); assertFalse(lock.isHeldByCurrentThread()); }
/** * @return this, after calling {@link #lock()} */ public AutoLock autoLock() { lock(); return this; }
/** * @return this, after calling {@link #lock()} */ public AutoLock autoLock() { lock(); return this; }
/** * @return the {@link ReadWriteLock#writeLock()} ()}, locked */ public AutoLock autoWriteLock() { return writeLock.autoLock(); }
/** * Unlocks the underlying {@link Lock}. */ @Override public void close() { unlock(); }
/** * @return the {@link ReadWriteLock#readLock()}, locked */ public AutoLock autoReadLock() { return readLock.autoLock(); }
/** * @return the {@link ReadWriteLock#writeLock()} ()}, locked */ public AutoLock autoWriteLock() { return writeLock.autoLock(); }