public void join() { awaitUninterruptibly(); }
private void notifyListeners() { // There won't be any visibility problem or concurrent modification // because 'ready' flag will be checked against both addListener and // removeListener calls. if (firstListener != null) { notifyListener(firstListener); firstListener = null; if (otherListeners != null) { for (IoFutureListener l : otherListeners) { notifyListener(l); } otherListeners = null; } } }
private boolean awaitUninterruptibly(long timeoutMillis) { try { return await0(timeoutMillis, false); } catch (InterruptedException e) { throw new InternalError(); } }
/** * Sets the result of the asynchronous operation, and mark it as finished. */ protected void setValue(Object newValue) { synchronized (lock) { // Allow only once. if (ready) { return; } result = newValue; ready = true; if (waiters > 0) { lock.notifyAll(); } } notifyListeners(); }
public void addListener(IoFutureListener listener) { if (listener == null) { throw new NullPointerException("listener"); } boolean notifyNow = false; synchronized (lock) { if (ready) { notifyNow = true; } else { if (firstListener == null) { firstListener = listener; } else { if (otherListeners == null) { otherListeners = new ArrayList<IoFutureListener>(1); } otherListeners.add(listener); } } } if (notifyNow) { notifyListener(listener); } }
public boolean join(long timeoutMillis) { return awaitUninterruptibly(timeoutMillis); }