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
DefaultAttributeMap
implementation 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 class
DefaultAttributeMap.DefaultAttribute<T>
-
Field Summary
Fields Modifier and Type Field Description private DefaultAttributeMap.DefaultAttribute[]
attributes
private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<DefaultAttributeMap,DefaultAttributeMap.DefaultAttribute[]>
ATTRIBUTES_UPDATER
private 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 theAttribute
for the givenAttributeKey
.<T> boolean
hasAttr(AttributeKey<T> key)
private static void
orderedCopyOnInsert(DefaultAttributeMap.DefaultAttribute[] sortedSrc, int srcLength, DefaultAttributeMap.DefaultAttribute[] copy, DefaultAttributeMap.DefaultAttribute toInsert)
private <T> void
removeAttributeIfMatch(AttributeKey<T> key, DefaultAttributeMap.DefaultAttribute<T> value)
private static int
searchAttributeByKey(DefaultAttributeMap.DefaultAttribute[] sortedAttributes, AttributeKey<?> key)
Similarly toArrays::binarySearch
it 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::binarySearch
it 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:AttributeMap
Get theAttribute
for the givenAttributeKey
. This method will never return null, but may return anAttribute
which does not have a value set yet.- Specified by:
attr
in interfaceAttributeMap
-
hasAttr
public <T> boolean hasAttr(AttributeKey<T> key)
Description copied from interface:AttributeMap
- Specified by:
hasAttr
in interfaceAttributeMap
-
removeAttributeIfMatch
private <T> void removeAttributeIfMatch(AttributeKey<T> key, DefaultAttributeMap.DefaultAttribute<T> value)
-
-