Esempio n. 1
0
 /**
  * Adds the specified element to this queue, waiting if necessary for another thread to receive
  * it.
  *
  * @throws InterruptedException {@inheritDoc}
  * @throws NullPointerException {@inheritDoc}
  */
 public void put(E o) throws InterruptedException {
   if (o == null) throw new NullPointerException();
   if (transferer.transfer(o, false, 0) == null) {
     Thread.interrupted();
     throw new InterruptedException();
   }
 }
Esempio n. 2
0
 /**
  * Retrieves and removes the head of this queue, if another thread is currently making an element
  * available.
  *
  * @return the head of this queue, or <tt>null</tt> if no element is available.
  */
 public E poll() {
   return (E) transferer.transfer(null, true, 0);
 }
Esempio n. 3
0
 /**
  * Retrieves and removes the head of this queue, waiting if necessary up to the specified wait
  * time, for another thread to insert it.
  *
  * @return the head of this queue, or <tt>null</tt> if the specified waiting time elapses before
  *     an element is present.
  * @throws InterruptedException {@inheritDoc}
  */
 public E poll(long timeout, TimeUnit unit) throws InterruptedException {
   Object e = transferer.transfer(null, true, unit.toNanos(timeout));
   if (e != null || !Thread.interrupted()) return (E) e;
   throw new InterruptedException();
 }
Esempio n. 4
0
 /**
  * Retrieves and removes the head of this queue, waiting if necessary for another thread to insert
  * it.
  *
  * @return the head of this queue
  * @throws InterruptedException {@inheritDoc}
  */
 public E take() throws InterruptedException {
   Object e = transferer.transfer(null, false, 0);
   if (e != null) return (E) e;
   Thread.interrupted();
   throw new InterruptedException();
 }
Esempio n. 5
0
 /**
  * Inserts the specified element into this queue, if another thread is waiting to receive it.
  *
  * @param e the element to add
  * @return <tt>true</tt> if the element was added to this queue, else <tt>false</tt>
  * @throws NullPointerException if the specified element is null
  */
 public boolean offer(E e) {
   if (e == null) throw new NullPointerException();
   return transferer.transfer(e, true, 0) != null;
 }
Esempio n. 6
0
 /**
  * Inserts the specified element into this queue, waiting if necessary up to the specified wait
  * time for another thread to receive it.
  *
  * @return <tt>true</tt> if successful, or <tt>false</tt> if the specified waiting time elapses
  *     before a consumer appears.
  * @throws InterruptedException {@inheritDoc}
  * @throws NullPointerException {@inheritDoc}
  */
 public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException {
   if (o == null) throw new NullPointerException();
   if (transferer.transfer(o, true, unit.toNanos(timeout)) != null) return true;
   if (!Thread.interrupted()) return false;
   throw new InterruptedException();
 }