Package net.engio.mbassy.common
Class AbstractConcurrentSet<T>
- java.lang.Object
-
- net.engio.mbassy.common.AbstractConcurrentSet<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>,java.util.Collection<T>,java.util.Set<T>
- Direct Known Subclasses:
StrongConcurrentSet,WeakConcurrentSet
public abstract class AbstractConcurrentSet<T> extends java.lang.Object implements java.util.Set<T>This data structure is optimized for non-blocking reads even when write operations occur. Running read iterators will not be affected by add operations since writes always insert at the head of the structure. Remove operations can affect any running iterator such that a removed element that has not yet been reached by the iterator will not appear in that iterator anymore.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractConcurrentSet.Entry<T>
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConcurrentSet(java.util.Map<T,ISetEntry<T>> entries)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(T element)booleanaddAll(java.util.Collection<? extends T> elements)voidclear()booleancontains(java.lang.Object element)booleancontainsAll(java.util.Collection<?> c)protected abstract AbstractConcurrentSet.Entry<T>createEntry(T value, AbstractConcurrentSet.Entry<T> next)booleanequals(java.lang.Object obj)inthashCode()private booleaninsert(T element)Inserts a new element at the head of the set.booleanisEmpty()booleanremove(java.lang.Object element)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)
-
-
-
Field Detail
-
id
private static final java.util.concurrent.atomic.AtomicLong id
-
ID
private final long ID
-
lock
protected final java.util.concurrent.locks.ReentrantReadWriteLock lock
-
head
protected AbstractConcurrentSet.Entry<T> head
-
-
Method Detail
-
createEntry
protected abstract AbstractConcurrentSet.Entry<T> createEntry(T value, AbstractConcurrentSet.Entry<T> next)
-
add
public boolean add(T element)
-
contains
public boolean contains(java.lang.Object element)
-
insert
private boolean insert(T element)
Inserts a new element at the head of the set. Note: This method is expected to be synchronized by the calling code
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
addAll
public boolean addAll(java.util.Collection<? extends T> elements)
-
remove
public boolean remove(java.lang.Object element)
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
clear
public void clear()
-
hashCode
public int hashCode()
-
-