Top Description Inners Fields Constructors Methods
io.vertx.core.impl.utils

public Class ConcurrentCyclicSequence<T>

extends Object
implements Iterable<T>, Iterator<T>
Class Inheritance
All Implemented Interfaces
java.util.Iterator, java.lang.Iterable
Imports
java.util.*, java.util.concurrent.atomic.AtomicInteger

A concurrent cyclic sequence of elements that can be used for round robin.

The sequence is immutable and modifications are done with copy-on-write using add(Object) and remove(Object) to return a modified copy of the current instance.

The internal counter uses a volatile index, so it can be incremented concurrently by several threads without locking.

Authors
Tim Fox, Julien Viet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final Object[]
private static final Object[]
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
ConcurrentCyclicSequence()

Create a new empty sequence.

public
ConcurrentCyclicSequence(T... elements)

Create a new empty sequence.

private
ConcurrentCyclicSequence(int pos, Object[] elements)

Method Summary

Modifier and TypeMethod and Description
public ConcurrentCyclicSequence<T>

Returns:

the resulting sequence
add
(T
the element to add
element
)

Copy the current sequence, add element at the tail of this sequence and returns it.

private int
computeIndex(int p)

public T

Returns:

the first element or null when the sequence is empty
first
()

public boolean

Returns:

always true
hasNext
()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public int

Returns:

the current index
index
()

public Iterator<T>

Returns:

an iterator starting at the first element of the sequence, the iterator will not throw ConcurrentModificationException
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public Iterator<T>

Returns:

an iterator starting at the next element of the sequence, the iterator will not throw ConcurrentModificationException
iterator
(boolean startAtBeginning)

public T

Returns:

the next element in the sequence
next
()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public ConcurrentCyclicSequence<T>

Returns:

the resulting sequence
remove
(T
the element to remove
element
)

Remove the first occurrence of element in this sequence and returns it.

public int

Returns:

the size of this sequence
size
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

elementsback to summary
private final Object[] elements
EMPTY_ARRAYback to summary
private static final Object[] EMPTY_ARRAY
posback to summary
private final AtomicInteger pos

Constructor Detail

ConcurrentCyclicSequenceback to summary
public ConcurrentCyclicSequence()

Create a new empty sequence.

ConcurrentCyclicSequenceback to summary
public ConcurrentCyclicSequence(T... elements)

Create a new empty sequence.

Annotations
@SafeVarargs
ConcurrentCyclicSequenceback to summary
private ConcurrentCyclicSequence(int pos, Object[] elements)

Method Detail

addback to summary
public ConcurrentCyclicSequence<T> add(T element)

Copy the current sequence, add element at the tail of this sequence and returns it.

Parameters
element:T

the element to add

Returns:ConcurrentCyclicSequence<T>

the resulting sequence

computeIndexback to summary
private int computeIndex(int p)
firstback to summary
public T first()
Returns:T

the first element or null when the sequence is empty

Annotations
@SuppressWarnings:unchecked
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

always true

Annotations
@Override
indexback to summary
public int index()
Returns:int

the current index

iteratorback to summary
public Iterator<T> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<T>

an iterator starting at the first element of the sequence, the iterator will not throw ConcurrentModificationException

Annotations
@Override
iteratorback to summary
public Iterator<T> iterator(boolean startAtBeginning)
Returns:Iterator<T>

an iterator starting at the next element of the sequence, the iterator will not throw ConcurrentModificationException

nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the sequence

Annotations
@SuppressWarnings:unchecked
@Override
removeback to summary
public ConcurrentCyclicSequence<T> remove(T element)

Remove the first occurrence of element in this sequence and returns it.

If the sequence does not contains element, this instance is returned instead.

Parameters
element:T

the element to remove

Returns:ConcurrentCyclicSequence<T>

the resulting sequence

sizeback to summary
public int size()
Returns:int

the size of this sequence

io.vertx.core.impl.utils back to summary

private Class ConcurrentCyclicSequence.Iter

extends Object
implements Iterator<T>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Annotations
@SuppressWarnings:unchecked

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv final int

Constructor Summary

AccessConstructor and Description
public
Iter(int start)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cursorback to summary
pack-priv int cursor
startback to summary
pack-priv final int start

Constructor Detail

Iterback to summary
public Iter(int start)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the iteration

Annotations
@Override
io.vertx.core.impl.utils back to summary

private Class ConcurrentCyclicSequence.SingletonIter

extends Object
implements Iterator<T>
Class Inheritance
  • java.lang.Object
  • io.vertx.core.impl.utils.ConcurrentCyclicSequence.SingletonIter
All Implemented Interfaces
java.util.Iterator
Annotations
@SuppressWarnings:unchecked

Field Summary

Modifier and TypeField and Description
pack-priv boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextback to summary
pack-priv boolean next

Constructor Detail

SingletonIterback to summary
private SingletonIter()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the iteration

Annotations
@Override