Package io.netty.util
Class DefaultAttributeMap
java.lang.Object
io.netty.util.DefaultAttributeMap
- All Implemented Interfaces:
AttributeMap
- Direct Known Subclasses:
AbstractChannel
,AbstractHttp2StreamChannel
Default
Attributes lookup and remove exibit
AttributeMap
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 exibit
O(logn)
time worst-case
complexity, hence attribute::set(null)
is to be preferred to remove
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DefaultAttributeMap.DefaultAttribute[]
private static final AtomicReferenceFieldUpdater
<DefaultAttributeMap, DefaultAttributeMap.DefaultAttribute[]> private static final DefaultAttributeMap.DefaultAttribute[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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 Details
-
ATTRIBUTES_UPDATER
private static final AtomicReferenceFieldUpdater<DefaultAttributeMap,DefaultAttributeMap.DefaultAttribute[]> ATTRIBUTES_UPDATER -
EMPTY_ATTRIBUTES
-
attributes
-
-
Constructor Details
-
DefaultAttributeMap
public DefaultAttributeMap()
-
-
Method Details
-
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
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
Description copied from interface:AttributeMap
- Specified by:
hasAttr
in interfaceAttributeMap
-
removeAttributeIfMatch
private <T> void removeAttributeIfMatch(AttributeKey<T> key, DefaultAttributeMap.DefaultAttribute<T> value)
-