/** {@inheritDoc} */ @Override public T remove() { T res = poll(); if (res == null) throw new NoSuchElementException(); return res; }
/** {@inheritDoc} */ @Override public int drainTo(Collection<? super T> c, int maxElements) { int max = Math.min(maxElements, size()); for (int i = 0; i < max; i++) { T el = poll(); if (el == null) return i; c.add(el); } return max; }
/** {@inheritDoc} */ @Nullable @Override public T poll(final long timeout, final TimeUnit unit) { gate.enter(); try { return delegate.poll(timeout, unit); } finally { gate.leave(); } }
/** {@inheritDoc} */ @Nullable @Override public T poll() { gate.enter(); try { return delegate.poll(); } finally { gate.leave(); } }
/** {@inheritDoc} */ @Nullable @Override public T take() throws IgniteException { while (true) { try { readSem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue take interrupted.", e); } checkStopping(); T e = poll(); if (e != null) return e; } }
/** {@inheritDoc} */ @Nullable @Override public T poll(long timeout, TimeUnit unit) throws IgniteException { A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout); long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit); while (U.currentTimeMillis() < end) { T retVal = null; try { if (readSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) { checkStopping(); retVal = poll(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue poll interrupted.", e); } if (retVal != null) return retVal; } return null; }
/** {@inheritDoc} */ @Override public T remove() { T res = poll(); if (res == null) throw new NoSuchElementException(); return res; }
/** {@inheritDoc} */ @Override public int drainTo(Collection<? super T> c, int maxElements) { int max = Math.min(maxElements, size()); for (int i = 0; i < max; i++) { T el = poll(); if (el == null) return i; c.add(el); } return max; }
/** {@inheritDoc} */ @Nullable @Override public T poll(final long timeout, final TimeUnit unit) { gate.enter(); try { return delegate.poll(timeout, unit); } finally { gate.leave(); } }
/** {@inheritDoc} */ @Nullable @Override public T poll() { gate.enter(); try { return delegate.poll(); } finally { gate.leave(); } }
/** {@inheritDoc} */ @Nullable @Override public T take() throws IgniteException { while (true) { try { readSem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue take interrupted.", e); } checkStopping(); T e = poll(); if (e != null) return e; } }
/** {@inheritDoc} */ @Nullable @Override public T poll(long timeout, TimeUnit unit) throws IgniteException { A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout); long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit); while (U.currentTimeMillis() < end) { T retVal = null; try { if (readSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) { checkStopping(); retVal = poll(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue poll interrupted.", e); } if (retVal != null) return retVal; } return null; }