ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/LinkedTransferQueue.java
(Generate patch)

Comparing jsr166/src/jsr166y/LinkedTransferQueue.java (file contents):
Revision 1.34 by jsr166, Thu Jul 30 17:30:26 2009 UTC vs.
Revision 1.35 by jsr166, Thu Jul 30 22:45:39 2009 UTC

# Line 10 | Line 10 | import java.util.concurrent.*;
10  
11   import java.util.AbstractQueue;
12   import java.util.Collection;
13 + import java.util.ConcurrentModificationException;
14   import java.util.Iterator;
15   import java.util.NoSuchElementException;
16 + import java.util.Queue;
17   import java.util.concurrent.locks.LockSupport;
18   import java.util.concurrent.atomic.AtomicReference;
19  
# Line 471 | Line 473 | public class LinkedTransferQueue<E> exte
473      }
474  
475      /**
476 <     * @throws InterruptedException {@inheritDoc}
477 <     * @throws NullPointerException {@inheritDoc}
476 >     * Inserts the specified element at the tail of this queue.
477 >     * As the queue is unbounded, this method will never block.
478 >     *
479 >     * @throws NullPointerException if the specified element is null
480       */
481 <    public void put(E e) throws InterruptedException {
482 <        if (e == null) throw new NullPointerException();
479 <        if (Thread.interrupted()) throw new InterruptedException();
480 <        xfer(e, NOWAIT, 0);
481 >    public void put(E e) {
482 >        offer(e);
483      }
484  
485      /**
486 <     * @throws InterruptedException {@inheritDoc}
487 <     * @throws NullPointerException {@inheritDoc}
486 >     * Inserts the specified element at the tail of this queue.
487 >     * As the queue is unbounded, this method will never block or
488 >     * return {@code false}.
489 >     *
490 >     * @return {@code true} (as specified by
491 >     *  {@link BlockingQueue#offer(Object,long,TimeUnit) BlockingQueue.offer})
492 >     * @throws NullPointerException if the specified element is null
493       */
494 <    public boolean offer(E e, long timeout, TimeUnit unit)
495 <        throws InterruptedException {
489 <        if (e == null) throw new NullPointerException();
490 <        if (Thread.interrupted()) throw new InterruptedException();
491 <        xfer(e, NOWAIT, 0);
492 <        return true;
494 >    public boolean offer(E e, long timeout, TimeUnit unit) {
495 >        return offer(e);
496      }
497  
498      /**
499 <     * @throws NullPointerException {@inheritDoc}
499 >     * Inserts the specified element at the tail of this queue.
500 >     * As the queue is unbounded, this method will never return {@code false}.
501 >     *
502 >     * @return {@code true} (as specified by
503 >     *         {@link BlockingQueue#offer(Object) BlockingQueue.offer})
504 >     * @throws NullPointerException if the specified element is null
505       */
506      public boolean offer(E e) {
507          if (e == null) throw new NullPointerException();
# Line 502 | Line 510 | public class LinkedTransferQueue<E> exte
510      }
511  
512      /**
513 <     * @throws NullPointerException {@inheritDoc}
513 >     * Inserts the specified element at the tail of this queue.
514 >     * As the queue is unbounded this method will never throw
515 >     * {@link IllegalStateException} or return {@code false}.
516 >     *
517 >     * @return {@code true} (as specified by {@link Collection#add})
518 >     * @throws NullPointerException if the specified element is null
519       */
520      public boolean add(E e) {
521 +        return offer(e);
522 +    }
523 +
524 +    /**
525 +     * Transfers the specified element immediately if there exists a
526 +     * consumer already waiting to receive it (in {@link #take} or
527 +     * timed {@link #poll(Object,long,TimeUnit) poll}), otherwise
528 +     * returning {@code false} without enqueuing the element.
529 +     *
530 +     * @throws NullPointerException if the specified element is null
531 +     */
532 +    public boolean tryTransfer(E e) {
533          if (e == null) throw new NullPointerException();
534 <        xfer(e, NOWAIT, 0);
510 <        return true;
534 >        return fulfill(e) != null;
535      }
536  
537      /**
538 +     * Inserts the specified element at the tail of this queue,
539 +     * waiting if necessary for the element to be received by a
540 +     * consumer invoking {@code take} or {@code poll}.
541 +     *
542       * @throws InterruptedException {@inheritDoc}
543 <     * @throws NullPointerException {@inheritDoc}
543 >     * @throws NullPointerException if the specified element is null
544       */
545      public void transfer(E e) throws InterruptedException {
546          if (e == null) throw new NullPointerException();
# Line 523 | Line 551 | public class LinkedTransferQueue<E> exte
551      }
552  
553      /**
554 +     * Inserts the specified element at the tail of this queue,
555 +     * waiting up to the specified wait time for the element to be
556 +     * received by a consumer invoking {@code take} or {@code poll}.
557 +     *
558       * @throws InterruptedException {@inheritDoc}
559 <     * @throws NullPointerException {@inheritDoc}
559 >     * @throws NullPointerException if the specified element is null
560       */
561      public boolean tryTransfer(E e, long timeout, TimeUnit unit)
562          throws InterruptedException {
# Line 536 | Line 568 | public class LinkedTransferQueue<E> exte
568          throw new InterruptedException();
569      }
570  
539    /**
540     * @throws NullPointerException {@inheritDoc}
541     */
542    public boolean tryTransfer(E e) {
543        if (e == null) throw new NullPointerException();
544        return fulfill(e) != null;
545    }
546
547    /**
548     * @throws InterruptedException {@inheritDoc}
549     */
571      public E take() throws InterruptedException {
572          E e = xfer(null, WAIT, 0);
573          if (e != null)
# Line 635 | Line 656 | public class LinkedTransferQueue<E> exte
656          }
657      }
658  
659 +    /**
660 +     * Returns an iterator over the elements in this queue in proper
661 +     * sequence, from head to tail.
662 +     *
663 +     * <p>The returned iterator is a "weakly consistent" iterator that
664 +     * will never throw
665 +     * {@link ConcurrentModificationException ConcurrentModificationException},
666 +     * and guarantees to traverse elements as they existed upon
667 +     * construction of the iterator, and may (but is not guaranteed
668 +     * to) reflect any modifications subsequent to construction.
669 +     *
670 +     * @return an iterator over the elements in this queue in proper sequence
671 +     */
672      public Iterator<E> iterator() {
673          return new Itr();
674      }
# Line 689 | Line 723 | public class LinkedTransferQueue<E> exte
723          }
724  
725          public E next() {
726 <            if (next == null)
726 >            if (next == null)
727                  throw new NoSuchElementException();
728              return advance();
729          }
# Line 823 | Line 857 | public class LinkedTransferQueue<E> exte
857          }
858      }
859  
860 +    /**
861 +     * Always returns {@code Integer.MAX_VALUE} because a
862 +     * {@code LinkedTransferQueue} is not capacity constrained.
863 +     *
864 +     * @return {@code Integer.MAX_VALUE} (as specified by
865 +     *         {@link BlockingQueue#remainingCapacity()})
866 +     */
867      public int remainingCapacity() {
868          return Integer.MAX_VALUE;
869      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines