Package io.netty.util
Class DefaultAttributeMap
- java.lang.Object
-
- io.netty.util.DefaultAttributeMap
-
- All Implemented Interfaces:
AttributeMap
- Direct Known Subclasses:
AbstractChannel,AbstractHttp2StreamChannel
public class DefaultAttributeMap extends java.lang.Object implements AttributeMap
DefaultAttributeMapimplementation which not exibit any blocking behaviour on attribute lookup while using a copy-on-write approach on the modify path.
Attributes lookup and remove exibitO(logn)time worst-case complexity, henceattribute::set(null)is to be preferred toremove.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDefaultAttributeMap.DefaultAttribute<T>
-
Field Summary
Fields Modifier and Type Field Description private DefaultAttributeMap.DefaultAttribute[]attributesprivate static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<DefaultAttributeMap,DefaultAttributeMap.DefaultAttribute[]>ATTRIBUTES_UPDATERprivate static DefaultAttributeMap.DefaultAttribute[]EMPTY_ATTRIBUTES
-
Constructor Summary
Constructors Constructor Description DefaultAttributeMap()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Attribute<T>attr(AttributeKey<T> key)Get theAttributefor the givenAttributeKey.<T> booleanhasAttr(AttributeKey<T> key)private static voidorderedCopyOnInsert(DefaultAttributeMap.DefaultAttribute[] sortedSrc, int srcLength, DefaultAttributeMap.DefaultAttribute[] copy, DefaultAttributeMap.DefaultAttribute toInsert)private <T> voidremoveAttributeIfMatch(AttributeKey<T> key, DefaultAttributeMap.DefaultAttribute<T> value)private static intsearchAttributeByKey(DefaultAttributeMap.DefaultAttribute[] sortedAttributes, AttributeKey<?> key)Similarly toArrays::binarySearchit perform a binary search optimized for this use case, in order to save polymorphic calls (on comparator side) and unnecessary class checks.
-
-
-
Field Detail
-
ATTRIBUTES_UPDATER
private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<DefaultAttributeMap,DefaultAttributeMap.DefaultAttribute[]> ATTRIBUTES_UPDATER
-
EMPTY_ATTRIBUTES
private static final DefaultAttributeMap.DefaultAttribute[] EMPTY_ATTRIBUTES
-
attributes
private volatile DefaultAttributeMap.DefaultAttribute[] attributes
-
-
Method Detail
-
searchAttributeByKey
private static int searchAttributeByKey(DefaultAttributeMap.DefaultAttribute[] sortedAttributes, AttributeKey<?> key)
Similarly toArrays::binarySearchit perform a binary search optimized for this use case, in order to save polymorphic calls (on comparator side) and unnecessary class checks.
-
orderedCopyOnInsert
private static void orderedCopyOnInsert(DefaultAttributeMap.DefaultAttribute[] sortedSrc, int srcLength, DefaultAttributeMap.DefaultAttribute[] copy, DefaultAttributeMap.DefaultAttribute toInsert)
-
attr
public <T> Attribute<T> attr(AttributeKey<T> key)
Description copied from interface:AttributeMapGet theAttributefor the givenAttributeKey. This method will never return null, but may return anAttributewhich does not have a value set yet.- Specified by:
attrin interfaceAttributeMap
-
hasAttr
public <T> boolean hasAttr(AttributeKey<T> key)
Description copied from interface:AttributeMap- Specified by:
hasAttrin interfaceAttributeMap
-
removeAttributeIfMatch
private <T> void removeAttributeIfMatch(AttributeKey<T> key, DefaultAttributeMap.DefaultAttribute<T> value)
-
-