Top Description Inners Fields Constructors Methods
io.undertow.util

public Class PortableConcurrentDirectDeque<E>

extends ConcurrentDirectDeque<E>
implements Deque<E>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Deque, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable, java.util.Queue
Type Parameters
<E>
the type of elements held in this collection
Static Imports
org.wildfly.common.Assert.checkNotNullParamWithNullPointerException

A modified version of ConcurrentLinkedDequeue which includes direct removal and is portable accorss all JVMs. This is only a fallback if the JVM does not offer access to Unsafe. More specifically, an unbounded concurrent deque based on linked nodes. Concurrent insertion, removal, and access operations execute safely across multiple threads. A ConcurrentLinkedDeque is an appropriate choice when many threads will share access to a common collection. Like most other concurrent collection implementations, this class does not permit the use of null elements.

Iterators are weakly consistent, returning elements reflecting the state of the deque at some point at or since the creation of the iterator. They do not throw ConcurrentModificationException, and may proceed concurrently with other operations.

Beware that, unlike in most collections, the size method is NOT a constant-time operation. Because of the asynchronous nature of these deques, determining the current number of elements requires a traversal of the elements, and so may report inaccurate results if this collection is modified during traversal. Additionally, the bulk operations addAll, removeAll, retainAll, containsAll, equals, and toArray are not guaranteed to be performed atomically. For example, an iterator operating concurrently with an addAll operation might view only some of the added elements.

This class and its iterator implement all of the optional methods of the java.util.Deque and java.util.Iterator interfaces.

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a ConcurrentLinkedDeque happen-before actions subsequent to the access or removal of that element from the ConcurrentLinkedDeque in another thread.

This class is a member of the Java Collections Framework.

Authors
Doug Lea, Martin Buchholz, Jason T. Grene
Since
1.7

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract class
private class
private class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private transient volatile PortableConcurrentDirectDeque.Node<E>
head

A node from which the first node on list (that is, the unique node p with p.prev == null && p.next != p) can be reached in O(1) time.

private static final AtomicReferenceFieldUpdater<PortableConcurrentDirectDeque<E>, PortableConcurrentDirectDeque.Node<E>>
private static final int
private static final PortableConcurrentDirectDeque.Node<Object>
private static final PortableConcurrentDirectDeque.Node<Object>
private static final long
private transient volatile PortableConcurrentDirectDeque.Node<E>
tail

A node from which the last node on list (that is, the unique node p with p.next == null && p.prev != p) can be reached in O(1) time.

private static final AtomicReferenceFieldUpdater<PortableConcurrentDirectDeque<E>, PortableConcurrentDirectDeque.Node<E>>

Constructor Summary

AccessConstructor and Description
public
PortableConcurrentDirectDeque()

Constructs an empty deque.

public
PortableConcurrentDirectDeque(Collection<? extends E>
the collection of elements to initially contain
c
)

Constructs a deque initially containing the elements of the given collection, added in traversal order of the collection's iterator.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true (as specified by java.util.Collection#add)
add
(E
the element to add
e
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Deque.add, java.util.Collection.add.

Inserts the specified element at the tail of this deque.

public boolean

Returns:

true if this deque changed as a result of the call
addAll
(Collection<? extends E>
the elements to be inserted into this deque
c
)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.Deque.addAll, java.util.Collection.addAll.

Appends all of the elements in the specified collection to the end of this deque, in the order that they are returned by the specified collection's iterator.

public void
addFirst(E
the element to add
e
)

Implements java.util.Deque.addFirst.

Inserts the specified element at the front of this deque.

public void
addLast(E
the element to add
e
)

Implements java.util.Deque.addLast.

Inserts the specified element at the end of this deque.

private boolean
private boolean
public void
clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Collection.clear.

Removes all of the elements from this deque.

public boolean

Returns:

true if this deque contains the specified element
contains
(Object
element whose presence in this deque is to be tested
o
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Deque.contains, java.util.Collection.contains.

Returns true if this deque contains at least one element e such that o.equals(e).

public Iterator<E>

Returns:

an iterator over the elements in this deque in reverse order
descendingIterator
()

Implements java.util.Deque.descendingIterator.

Returns an iterator over the elements in this deque in reverse sequential order.

public E
element()

Implements java.util.Deque.element.

Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque).

pack-priv PortableConcurrentDirectDeque.Node<E>
first()

Returns the first node, the unique node p for which: p.prev == null && p.next != p The returned node may or may not be logically deleted.

public E
getFirst()

Implements java.util.Deque.getFirst.

Retrieves, but does not remove, the first element of this deque.

public E
getLast()

Implements java.util.Deque.getLast.

Retrieves, but does not remove, the last element of this deque.

private void
initHeadTail(PortableConcurrentDirectDeque.Node<E> h, PortableConcurrentDirectDeque.Node<E> t)

Initializes head and tail, ensuring invariants hold.

public boolean

Returns:

true if this collection contains no elements
isEmpty
()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty.

Returns true if this collection contains no elements.

public Iterator<E>

Returns:

an iterator over the elements in this deque in proper sequence
iterator
()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Deque.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this deque in proper sequence.

pack-priv PortableConcurrentDirectDeque.Node<E>
last()

Returns the last node, the unique node p for which: p.next == null && p.prev != p The returned node may or may not be logically deleted.

private PortableConcurrentDirectDeque.Node<E>
linkFirst(E e)

Links e as first element.

private PortableConcurrentDirectDeque.Node<E>
linkLast(E e)

Links e as last element.

pack-priv PortableConcurrentDirectDeque.Node<E>
public boolean

Returns:

true (as specified by java.util.Queue#offer)
offer
(E
the element to add
e
)

Implements java.util.Deque.offer.

Inserts the specified element at the tail of this deque.

public boolean

Returns:

true (as specified by java.util.Deque#offerFirst)
offerFirst
(E
the element to add
e
)

Implements java.util.Deque.offerFirst.

Inserts the specified element at the front of this deque.

public Object
public boolean

Returns:

true (as specified by java.util.Deque#offerLast)
offerLast
(E
the element to add
e
)

Implements java.util.Deque.offerLast.

Inserts the specified element at the end of this deque.

public Object
public E
peek()

Implements java.util.Deque.peek.

Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

public E
peekFirst()

Implements java.util.Deque.peekFirst.

Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty.

public E
peekLast()

Implements java.util.Deque.peekLast.

Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty.

public E
poll()

Implements java.util.Deque.poll.

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

public E
pollFirst()

Implements java.util.Deque.pollFirst.

Retrieves and removes the first element of this deque, or returns null if this deque is empty.

public E
pollLast()

Implements java.util.Deque.pollLast.

Retrieves and removes the last element of this deque, or returns null if this deque is empty.

public E
pop()

Implements java.util.Deque.pop.

Pops an element from the stack represented by this deque.

pack-priv final PortableConcurrentDirectDeque.Node<E>
pred(PortableConcurrentDirectDeque.Node<E> p)

Returns the predecessor of p, or the last node if p.prev has been linked to self, which will only be true if traversing with a stale pointer that is now off the list.

pack-priv PortableConcurrentDirectDeque.Node<E>
public void
push(E
the element to push
e
)

Implements java.util.Deque.push.

Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.

private void
readObject(ObjectInputStream s)

Reconstitutes this deque from a stream (that is, deserializes it).

public E
remove()

Implements java.util.Deque.remove.

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).

public boolean

Returns:

true if the deque contained the specified element
remove
(Object
element to be removed from this deque, if present
o
)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Deque.remove, java.util.Collection.remove.

Removes the first element e such that o.equals(e), if such an element exists in this deque.

public E
removeFirst()

Implements java.util.Deque.removeFirst.

Retrieves and removes the first element of this deque.

public boolean

Returns:

true if the deque contained the specified element
removeFirstOccurrence
(Object
element to be removed from this deque, if present
o
)

Implements java.util.Deque.removeFirstOccurrence.

Removes the first element e such that o.equals(e), if such an element exists in this deque.

public E
removeLast()

Implements java.util.Deque.removeLast.

Retrieves and removes the last element of this deque.

public boolean

Returns:

true if the deque contained the specified element
removeLastOccurrence
(Object
element to be removed from this deque, if present
o
)

Implements java.util.Deque.removeLastOccurrence.

Removes the last element e such that o.equals(e), if such an element exists in this deque.

public void
private E

Returns:

the element
screenNullResult
(E
the element
v
)

Returns element unless it is null, in which case throws NoSuchElementException.

public int

Returns:

the number of elements in this deque
size
()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Deque.size, java.util.Collection.size.

Returns the number of elements in this deque.

private void
private void
pack-priv final PortableConcurrentDirectDeque.Node<E>
succ(PortableConcurrentDirectDeque.Node<E> p)

Returns the successor of p, or the first node if p.next has been linked to self, which will only be true if traversing with a stale pointer that is now off the list.

public Object[]

Returns:

an array containing all of the elements in this deque
toArray
()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Collection.toArray.

Returns an array containing all of the elements in this deque, in proper sequence (from first to last element).

public <T> T[]

Returns:

an array containing all of the elements in this deque
toArray
(T[]
the array into which the elements of the deque are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
a
)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Collection.toArray.

Returns an array containing all of the elements in this deque, in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

private ArrayList<E>

Returns:

the arrayList
toArrayList
()

Creates an array list and fills it with elements of this list.

private void
unlinkFirst(PortableConcurrentDirectDeque.Node<E> first, PortableConcurrentDirectDeque.Node<E> next)

Unlinks non-null first node.

private void
private void
updateHead()

Guarantees that any node which was unlinked before a call to this method will be unreachable from head after it returns.

private void
updateTail()

Guarantees that any node which was unlinked before a call to this method will be unreachable from tail after it returns.

private void
writeObject(ObjectOutputStream s)

Saves this deque to a stream (that is, serializes it).

Inherited from io.undertow.util.ConcurrentDirectDeque:
newInstance