org.multiverse.transactional.collections
Class TransactionalLinkedList<E>

java.lang.Object
  extended by org.multiverse.transactional.collections.AbstractTransactionalDeque<E>
      extended by org.multiverse.transactional.collections.TransactionalLinkedList<E>
Type Parameters:
E -
All Implemented Interfaces:
Iterable<E>, Collection<E>, BlockingDeque<E>, BlockingQueue<E>, Deque<E>, List<E>, Queue<E>, TransactionalCollection<E>, TransactionalDeque<E>, TransactionalList<E>, TransactionalQueue<E>

public final class TransactionalLinkedList<E>
extends AbstractTransactionalDeque<E>
implements TransactionalList<E>

A general purposes collection structure that could be considered a work horse because it implements a lot of interfaces:

  • Iterable
  • Collection
  • List
  • Queue
  • BlockingQueue
  • Deque
  • BlockingDeque
  • Each operation on this TransactionalLinkedList is transactional by default, and of course can participate in already running transactions.

    There is a scalability issue with this structure and it has to do with unwanted writeconflicts. Although a take and put can be executed concurrently because there is a seperate tail and head to place items on, one of the transactions is going to fail because of a write conflict on the size field, or on the head/tail because of the object granularity of the stm. This is an issue that is going to be solved in the future, but for the moment this structure will not be very concurrent. This even gets worse with longer transactions that are typical for stm's, compared to classic concurrency (the synchronized block could be seen as a transaction).

    Author:
    Peter Veentjer.
    See Also:
    TransactionalCollection, TransactionalQueue, TransactionalDeque, TransactionalList, BlockingDeque, BlockingQueue, Queue, Deque, List

    Nested Class Summary
     class TransactionalLinkedList.DescendingIteratorImpl
               
     class TransactionalLinkedList.IteratorImpl
               
     class TransactionalLinkedList.ListIteratorImpl
               
    static class TransactionalLinkedList.Node<E>
               
     
    Constructor Summary
    TransactionalLinkedList()
              Creates a new TransactionalLinkedList with unbound capacity.
    TransactionalLinkedList(Collection<E> items)
              Creates a new TransactionalLinkedList with unbound capacity and the provided items.
    TransactionalLinkedList(E... items)
              Creates a new TransactionalLinkedList with unbound capacity and the provided items.
    TransactionalLinkedList(int maxCapacity)
              Creates a new TransactionalLinkedList with the provided max capacity.
    TransactionalLinkedList(int maxCapacity, boolean relaxedMaximumCapacity)
              Creates a new TransactionalLinkedList.
     
    Method Summary
     void add(int index, E element)
               
     boolean addAll(Collection<? extends E> c)
               
     boolean addAll(int index, Collection<? extends E> c)
               
     int atomicSize()
              Returns the current size of the TransactionalCollection.
     void clear()
               
     Iterator<E> descendingIterator()
               
    protected  void doAddFirst(E e)
               
    protected  void doAddLast(E e)
               
    protected  E doRemoveFirst()
               
    protected  E doRemoveLast()
               
     boolean equals(Object thatObj)
               
     E get(int index)
               
     TransactionalLinkedList.Node<E> getHead()
               
     int getMaxCapacity()
               
     int hashCode()
               
     boolean hasRelaxedMaxCapacity()
              Checks if this TransactionalLinkedList uses a relaxed maximum capacity.
     int indexOf(Object o)
               
     boolean isEmpty()
               
     Iterator<E> iterator()
              Returns an iterator over the elements contained in this collection.
     int lastIndexOf(Object o)
               
     ListIterator<E> listIterator()
               
     ListIterator<E> listIterator(int index)
               
     E peekFirst()
               
     E peekLast()
               
     void putFirst(E e)
               
     int remainingCapacity()
               
     E remove(int index)
               
     boolean remove(Object item)
               
     E removeFirst()
               
     E set(int index, E element)
               
     int size()
               
     List<E> subList(int fromIndex, int toIndex)
               
     E takeLast()
               
     
    Methods inherited from class org.multiverse.transactional.collections.AbstractTransactionalDeque
    add, addFirst, addLast, contains, containsAll, drainTo, drainTo, element, getFirst, getLast, hasNoStorageCapacity, offer, offer, offerFirst, offerFirst, offerLast, offerLast, peek, poll, poll, pollFirst, pollFirst, pollLast, pollLast, pop, push, put, putLast, remove, removeAll, removeFirstOccurrence, removeLast, removeLastOccurrence, retainAll, take, takeFirst, takeUninterruptible, toArray, toArray, toString
     
    Methods inherited from class java.lang.Object
    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
     
    Methods inherited from interface java.util.List
    add, contains, containsAll, removeAll, retainAll, toArray, toArray
     
    Methods inherited from interface org.multiverse.transactional.collections.TransactionalCollection
    add, contains, containsAll, removeAll, retainAll, toArray, toArray, toString
     

    Constructor Detail

    TransactionalLinkedList

    public TransactionalLinkedList()
    Creates a new TransactionalLinkedList with unbound capacity.

    It is strict on the maximum capacity, so it could cause contention problems. See the TransactionalLinkedList(int, boolean) as alternative.


    TransactionalLinkedList

    public TransactionalLinkedList(E... items)
    Creates a new TransactionalLinkedList with unbound capacity and the provided items.

    It is strict on the maximum capacity, so it could cause contention problems. See the TransactionalLinkedList(int, boolean) as alternative.

    Parameters:
    items - the items to store in this TransactionalLinkedList.
    Throws:
    NullPointerException - if items is null.

    TransactionalLinkedList

    public TransactionalLinkedList(Collection<E> items)
    Creates a new TransactionalLinkedList with unbound capacity and the provided items.

    It is strict on the maximum capacity, so it could cause contention problems. See the TransactionalLinkedList(int, boolean) as alternative.

    Parameters:
    items - the items to store in this TransactionalLinkedList.
    Throws:
    NullPointerException - if items is null.

    TransactionalLinkedList

    public TransactionalLinkedList(int maxCapacity)
    Creates a new TransactionalLinkedList with the provided max capacity.

    It is strict on the maximum capacity, so it could cause contention problems. See the TransactionalLinkedList(int, boolean) as alternative.

    Parameters:
    maxCapacity - the maximum capacity of the queue.
    Throws:
    IllegalArgumentException - if maxCapacity smaller than 0.

    TransactionalLinkedList

    public TransactionalLinkedList(int maxCapacity,
                                   boolean relaxedMaximumCapacity)
    Creates a new TransactionalLinkedList.

    Parameters:
    maxCapacity - the maximum number of items stores in this TransactionalLinkedList.
    relaxedMaximumCapacity - if the TransactionalLinkedList should be relaxed with it maxCapacity. If it is strict, it leads to reduced concurrency. If it is relaxed, then the number of items stored could exceed the maxCapacity. In most cases this is not an issue.
    Throws:
    IllegalArgumentException - if maxCapacity is smaller than 0.
    Method Detail

    hasRelaxedMaxCapacity

    public boolean hasRelaxedMaxCapacity()
    Checks if this TransactionalLinkedList uses a relaxed maximum capacity. Meaning that the number of items in the TransactionLinkedList could exceed the maximum capacity.

    Returns:
    true if a relaxed maximum capacity is used.

    isEmpty

    public boolean isEmpty()
    Specified by:
    isEmpty in interface Collection<E>
    Specified by:
    isEmpty in interface List<E>
    Specified by:
    isEmpty in interface TransactionalCollection<E>
    Overrides:
    isEmpty in class AbstractTransactionalDeque<E>

    atomicSize

    public int atomicSize()
    Description copied from interface: TransactionalCollection
    Returns the current size of the TransactionalCollection. The big difference between the normal TransactionalCollection.size() method is that this one returns the actual size of this map and doesn't look at the current transaction. So you could see changes made by other threads.

    Specified by:
    atomicSize in interface TransactionalCollection<E>
    Returns:
    the current size of the TransactionalMap.

    size

    public int size()
    Specified by:
    size in interface Collection<E>
    Specified by:
    size in interface BlockingDeque<E>
    Specified by:
    size in interface Deque<E>
    Specified by:
    size in interface List<E>
    Specified by:
    size in interface TransactionalCollection<E>
    Specified by:
    size in class AbstractTransactionalDeque<E>

    remainingCapacity

    public int remainingCapacity()
    Specified by:
    remainingCapacity in interface BlockingQueue<E>
    Specified by:
    remainingCapacity in interface TransactionalQueue<E>

    clear

    public void clear()
    Specified by:
    clear in interface Collection<E>
    Specified by:
    clear in interface List<E>
    Specified by:
    clear in interface TransactionalCollection<E>

    getMaxCapacity

    public int getMaxCapacity()

    doAddLast

    protected void doAddLast(E e)
    Specified by:
    doAddLast in class AbstractTransactionalDeque<E>

    doAddFirst

    protected void doAddFirst(E e)
    Specified by:
    doAddFirst in class AbstractTransactionalDeque<E>

    getHead

    public TransactionalLinkedList.Node<E> getHead()

    removeFirst

    public E removeFirst()
    Specified by:
    removeFirst in interface Deque<E>
    Overrides:
    removeFirst in class AbstractTransactionalDeque<E>

    doRemoveFirst

    protected E doRemoveFirst()
    Specified by:
    doRemoveFirst in class AbstractTransactionalDeque<E>

    takeLast

    public E takeLast()
               throws InterruptedException
    Specified by:
    takeLast in interface BlockingDeque<E>
    Specified by:
    takeLast in interface TransactionalDeque<E>
    Overrides:
    takeLast in class AbstractTransactionalDeque<E>
    Throws:
    InterruptedException

    putFirst

    public void putFirst(E e)
                  throws InterruptedException
    Specified by:
    putFirst in interface BlockingDeque<E>
    Specified by:
    putFirst in interface TransactionalDeque<E>
    Overrides:
    putFirst in class AbstractTransactionalDeque<E>
    Throws:
    InterruptedException

    doRemoveLast

    protected E doRemoveLast()
    Specified by:
    doRemoveLast in class AbstractTransactionalDeque<E>

    iterator

    public Iterator<E> iterator()
    Description copied from class: AbstractTransactionalDeque
    Returns an iterator over the elements contained in this collection.

    Specified by:
    iterator in interface Iterable<E>
    Specified by:
    iterator in interface Collection<E>
    Specified by:
    iterator in interface BlockingDeque<E>
    Specified by:
    iterator in interface Deque<E>
    Specified by:
    iterator in interface List<E>
    Specified by:
    iterator in interface TransactionalCollection<E>
    Specified by:
    iterator in class AbstractTransactionalDeque<E>
    Returns:
    an iterator over the elements contained in this collection

    peekFirst

    public E peekFirst()
    Specified by:
    peekFirst in interface Deque<E>

    peekLast

    public E peekLast()
    Specified by:
    peekLast in interface Deque<E>

    descendingIterator

    public Iterator<E> descendingIterator()
    Specified by:
    descendingIterator in interface Deque<E>

    addAll

    public boolean addAll(int index,
                          Collection<? extends E> c)
    Specified by:
    addAll in interface List<E>
    Specified by:
    addAll in interface TransactionalList<E>

    get

    public E get(int index)
    Specified by:
    get in interface List<E>
    Specified by:
    get in interface TransactionalList<E>

    set

    public E set(int index,
                 E element)
    Specified by:
    set in interface List<E>
    Specified by:
    set in interface TransactionalList<E>

    add

    public void add(int index,
                    E element)
    Specified by:
    add in interface List<E>
    Specified by:
    add in interface TransactionalList<E>

    addAll

    public boolean addAll(Collection<? extends E> c)
    Specified by:
    addAll in interface Collection<E>
    Specified by:
    addAll in interface List<E>
    Specified by:
    addAll in interface TransactionalCollection<E>

    remove

    public E remove(int index)
    Specified by:
    remove in interface List<E>
    Specified by:
    remove in interface TransactionalList<E>

    indexOf

    public int indexOf(Object o)
    Specified by:
    indexOf in interface List<E>
    Specified by:
    indexOf in interface TransactionalList<E>

    lastIndexOf

    public int lastIndexOf(Object o)
    Specified by:
    lastIndexOf in interface List<E>
    Specified by:
    lastIndexOf in interface TransactionalList<E>

    listIterator

    public ListIterator<E> listIterator()
    Specified by:
    listIterator in interface List<E>
    Specified by:
    listIterator in interface TransactionalList<E>

    listIterator

    public ListIterator<E> listIterator(int index)
    Specified by:
    listIterator in interface List<E>
    Specified by:
    listIterator in interface TransactionalList<E>

    subList

    public List<E> subList(int fromIndex,
                           int toIndex)
    Specified by:
    subList in interface List<E>
    Specified by:
    subList in interface TransactionalList<E>

    remove

    public boolean remove(Object item)
    Specified by:
    remove in interface Collection<E>
    Specified by:
    remove in interface BlockingDeque<E>
    Specified by:
    remove in interface BlockingQueue<E>
    Specified by:
    remove in interface Deque<E>
    Specified by:
    remove in interface List<E>
    Specified by:
    remove in interface TransactionalCollection<E>
    Overrides:
    remove in class AbstractTransactionalDeque<E>

    hashCode

    public int hashCode()
    Specified by:
    hashCode in interface Collection<E>
    Specified by:
    hashCode in interface List<E>
    Specified by:
    hashCode in interface TransactionalCollection<E>
    Overrides:
    hashCode in class Object

    equals

    public boolean equals(Object thatObj)
    Specified by:
    equals in interface Collection<E>
    Specified by:
    equals in interface List<E>
    Specified by:
    equals in interface TransactionalCollection<E>
    Overrides:
    equals in class Object


    Copyright © 2008-2010 Multiverse. All Rights Reserved.