/** {@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 void put(T item) throws IgniteException { A.notNull(item, "item"); if (!bounded()) { boolean offer = offer(item); assert offer; return; } while (true) { try { writeSem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue put interrupted.", e); } checkStopping(); if (offer(item)) return; } }
/** {@inheritDoc} */ @Override public boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException { A.notNull(item, "item"); A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout); if (!bounded()) { boolean offer = offer(item); assert offer; return true; } long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit); while (U.currentTimeMillis() < end) { boolean retVal = false; try { if (writeSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) { checkStopping(); retVal = offer(item); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue put interrupted.", e); } if (retVal) return true; } return false; }
/** {@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 void put(T item) throws IgniteException { A.notNull(item, "item"); if (!bounded()) { boolean offer = offer(item); assert offer; return; } while (true) { try { writeSem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue put interrupted.", e); } checkStopping(); if (offer(item)) return; } }
/** {@inheritDoc} */ @Override public boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException { A.notNull(item, "item"); A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout); if (!bounded()) { boolean offer = offer(item); assert offer; return true; } long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit); while (U.currentTimeMillis() < end) { boolean retVal = false; try { if (writeSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) { checkStopping(); retVal = offer(item); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue put interrupted.", e); } if (retVal) return true; } return false; }