/** * When the calling thread returns this index merger will be idle, that is * there will be no merge tasks pending anymore. The method returns immediately * if there are currently no tasks pending at all. */ void waitUntilIdle() throws InterruptedException { mergerIdle.acquire(); // and immediately release again mergerIdle.release(); }
/** * Returns <code>true</code> if this workspace info is initialized, * otherwise returns <code>false</code>. * * @return <code>true</code> if this workspace info is initialized. */ protected final boolean isInitialized() { try { if (!initLock.readLock().attempt(0)) { return false; } } catch (InterruptedException e) { return false; } // can't use 'finally' pattern here boolean ret = initialized; initLock.readLock().release(); return ret; }
/** * Called when events are delivered. * * @param events the events. */ public void onEvent(EventIterator events) { this.events = events; sync.release(); }
private ReadLock(Sync readLock) throws InterruptedException { this.readLock = readLock; this.readLock.acquire(); }
/** * Gets the events from the EventListener. Waits at most <code>wait</code> * milliseconds for the events. * <p> * If the events are not delivered within <code>wait</code> time * <code>null</code> is returned and a log message is written. * @param wait time in milliseconds to wait at most for * <code>EventIterator</code>. * @return <code>EventIterator</code>. */ public EventIterator getEventIterator(long wait) { try { if (sync.attempt(wait)) { // result ready return events; } } catch (InterruptedException e) { log.println("Interrupted while waiting for EventIterator"); } return null; }
public void release() { readLock.release(); }
private ReadLock(Sync readLock) throws InterruptedException { this.readLock = readLock; this.readLock.acquire(); }
public void release() { Sync exclusive = writerStateRWLock.writeLock(); for (;;) { try { exclusive.acquire(); break; } catch (InterruptedException e) { // try again Thread.interrupted(); } } try { activeWriter = null; activeWriterId = null; notifyWaitingReaders(); notifyWaitingWriters(); } finally { exclusive.release(); } }
public void release() { readLock.release(); }
/** * Creates a new <code>EventResult</code>. * * @param log log messages are written to this <code>Logger</code>. */ public EventResult(PrintWriter log) { this.log = log; try { sync.acquire(); } catch (InterruptedException e) { log.println("Could not aquire sync."); throw new RuntimeException("EventResult: Interrupted while aquiring sync."); } }
/** * Returns <code>true</code> if this workspace info is initialized, * otherwise returns <code>false</code>. * * @return <code>true</code> if this workspace info is initialized. */ protected final boolean isInitialized() { try { if (!initLock.readLock().attempt(0)) { return false; } } catch (InterruptedException e) { return false; } // can't use 'finally' pattern here boolean ret = initialized; initLock.readLock().release(); return ret; }
public void release() { Sync exclusive = writerStateRWLock.writeLock(); for (;;) { try { exclusive.acquire(); break; } catch (InterruptedException e) { // try again Thread.interrupted(); } } try { activeWriter = null; activeWriterId = null; notifyWaitingReaders(); notifyWaitingWriters(); } finally { exclusive.release(); } }
/** * This method is not thread-safe and calling threads must ensure that * only one thread calls this method at a time. */ private void notifyWaitingReaders() { Iterator<Sync> it = waitingReaders.iterator(); while (it.hasNext()) { it.next().release(); it.remove(); } }
private WriteLock(ReadWriteLock readWriteLock) throws InterruptedException { this.readWriteLock = readWriteLock; this.readWriteLock.writeLock().acquire(); }
/** * This method is not thread-safe and calling threads must ensure that * only one thread calls this method at a time. */ private void notifyWaitingReaders() { Iterator<Sync> it = waitingReaders.iterator(); while (it.hasNext()) { it.next().release(); it.remove(); } }
private WriteLock(ReadWriteLock readWriteLock) throws InterruptedException { this.readWriteLock = readWriteLock; this.readWriteLock.writeLock().acquire(); }
public ReadLock downgrade() { readerCount.incrementAndGet(); readLockMap.addLock(null); Sync exclusive = writerStateRWLock.writeLock(); for (;;) { try { exclusive.acquire(); break; } catch (InterruptedException e) { // try again Thread.interrupted(); } } try { activeWriter = null; // only notify waiting readers since we still hold a down // graded lock, which is kind of exclusiv with respect to // other writers notifyWaitingReaders(); } finally { exclusive.release(); } return anonymousReadLock; }
/** * This method may be called concurrently by multiple threads. */ private void notifyWaitingWriters() { synchronized (waitingWriters) { if (waitingWriters.isEmpty()) { return; } Iterator<Sync> it = waitingWriters.iterator(); while (it.hasNext()) { it.next().release(); it.remove(); } } }