Top Description Inners Fields Constructors Methods
io.netty.util

public Class DefaultAttributeMap

extends Object
implements AttributeMap
Class Inheritance
All Implemented Interfaces
io.netty.util.AttributeMap
Imports
io.netty.util.internal.ObjectUtil, java.util.Arrays, java.util.concurrent.atomic.AtomicReference, .AtomicReferenceFieldUpdater

Default 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 and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private volatile DefaultAttributeMap.DefaultAttribute<T>[]
private static final AtomicReferenceFieldUpdater<DefaultAttributeMap, DefaultAttributeMap.DefaultAttribute<T>[]>
private static final DefaultAttributeMap.DefaultAttribute<T>[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public <T> Attribute<T>
attr(AttributeKey<T> key)

Implements io.netty.util.AttributeMap.attr.

Get the Attribute for the given AttributeKey.
public <T> boolean
hasAttr(AttributeKey<T> key)

Implements io.netty.util.AttributeMap.hasAttr.

Returns true if and only if the given Attribute exists in this AttributeMap.
private static void
private <T> void
private static int
searchAttributeByKey(DefaultAttributeMap.DefaultAttribute<T>[] sortedAttributes, AttributeKey<?> key)

Similarly to Arrays::binarySearch it perform a binary search optimized for this use case, in order to save polymorphic calls (on comparator side) and unnecessary class checks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
private volatile DefaultAttributeMap.DefaultAttribute<T>[] attributes
ATTRIBUTES_UPDATERback to summary
private static final AtomicReferenceFieldUpdater<DefaultAttributeMap, DefaultAttributeMap.DefaultAttribute<T>[]> ATTRIBUTES_UPDATER
EMPTY_ATTRIBUTESback to summary
private static final DefaultAttributeMap.DefaultAttribute<T>[] EMPTY_ATTRIBUTES

Constructor Detail

DefaultAttributeMapback to summary
public DefaultAttributeMap()

Method Detail

attrback to summary
public <T> Attribute<T> attr(AttributeKey<T> key)

Implements io.netty.util.AttributeMap.attr.

Doc from io.netty.util.AttributeMap.attr.

Get the Attribute for the given AttributeKey. This method will never return null, but may return an Attribute which does not have a value set yet.

Annotations
@SuppressWarnings:unchecked
@Override
hasAttrback to summary
public <T> boolean hasAttr(AttributeKey<T> key)

Implements io.netty.util.AttributeMap.hasAttr.

Doc from io.netty.util.AttributeMap.hasAttr.

Returns true if and only if the given Attribute exists in this AttributeMap.

Annotations
@Override
orderedCopyOnInsertback to summary
private static void orderedCopyOnInsert(DefaultAttributeMap.DefaultAttribute<T>[] sortedSrc, int srcLength, DefaultAttributeMap.DefaultAttribute<T>[] copy, DefaultAttributeMap.DefaultAttribute<T> toInsert)
removeAttributeIfMatchback to summary
private <T> void removeAttributeIfMatch(AttributeKey<T> key, DefaultAttributeMap.DefaultAttribute<T> value)
searchAttributeByKeyback to summary
private static int searchAttributeByKey(DefaultAttributeMap.DefaultAttribute<T>[] sortedAttributes, AttributeKey<?> key)

Similarly to Arrays::binarySearch it perform a binary search optimized for this use case, in order to save polymorphic calls (on comparator side) and unnecessary class checks.

io.netty.util back to summary

private final Class DefaultAttributeMap.DefaultAttribute<T>

extends AtomicReference<T>
implements Attribute<T>
Class Inheritance
All Implemented Interfaces
io.netty.util.Attribute
Annotations
@SuppressWarnings:serial

Field Summary

Modifier and TypeField and Description
private volatile DefaultAttributeMap
private final AttributeKey<T>
private static final AtomicReferenceFieldUpdater<DefaultAttributeMap.DefaultAttribute<T>, DefaultAttributeMap>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public T
getAndRemove()

Implements io.netty.util.Attribute.getAndRemove.

Removes this attribute from the AttributeMap and returns the old value.
private boolean
public AttributeKey<T>
key()

Implements io.netty.util.Attribute.key.

Returns the key of this attribute.
public void
remove()

Implements io.netty.util.Attribute.remove.

Removes this attribute from the AttributeMap.
public T
setIfAbsent(T value)

Implements io.netty.util.Attribute.setIfAbsent.

Atomically sets to the given value if this Attribute's value is null.
Inherited from java.util.concurrent.atomic.AtomicReference:
accumulateAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndAccumulategetAndSetgetAndUpdategetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

attributeMapback to summary
private volatile DefaultAttributeMap attributeMap
keyback to summary
private final AttributeKey<T> key
MAP_UPDATERback to summary
private static final AtomicReferenceFieldUpdater<DefaultAttributeMap.DefaultAttribute<T>, DefaultAttributeMap> MAP_UPDATER
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicReference.serialVersionUID.

Constructor Detail

DefaultAttributeback to summary
pack-priv DefaultAttribute(DefaultAttributeMap attributeMap, AttributeKey<T> key)

Method Detail

getAndRemoveback to summary
public T getAndRemove()

Implements io.netty.util.Attribute.getAndRemove.

Doc from io.netty.util.Attribute.getAndRemove.

Removes this attribute from the AttributeMap and returns the old value. Subsequent get() calls will return null. If you only want to return the old value and clear the Attribute while still keep it in the AttributeMap use getAndSet(Object) with a value of null.

Be aware that even if you call this method another thread that has obtained a reference to this Attribute via AttributeMap#attr(AttributeKey) will still operate on the same instance. That said if now another thread or even the same thread later will call AttributeMap#attr(AttributeKey) again, a new Attribute instance is created and so is not the same as the previous one that was removed. Because of this special caution should be taken when you call remove() or getAndRemove().

Annotations
@Override
isRemovedback to summary
private boolean isRemoved()
keyback to summary
public AttributeKey<T> key()

Implements io.netty.util.Attribute.key.

Doc from io.netty.util.Attribute.key.

Returns the key of this attribute.

Annotations
@Override
removeback to summary
public void remove()

Implements io.netty.util.Attribute.remove.

Doc from io.netty.util.Attribute.remove.

Removes this attribute from the AttributeMap. Subsequent get() calls will return @{code null}. If you only want to remove the value and clear the Attribute while still keep it in AttributeMap use set(Object) with a value of null.

Be aware that even if you call this method another thread that has obtained a reference to this Attribute via AttributeMap#attr(AttributeKey) will still operate on the same instance. That said if now another thread or even the same thread later will call AttributeMap#attr(AttributeKey) again, a new Attribute instance is created and so is not the same as the previous one that was removed. Because of this special caution should be taken when you call remove() or getAndRemove().

Annotations
@Override
setIfAbsentback to summary
public T setIfAbsent(T value)

Implements io.netty.util.Attribute.setIfAbsent.

Doc from io.netty.util.Attribute.setIfAbsent.

Atomically sets to the given value if this Attribute's value is null. If it was not possible to set the value as it contains a value it will just return the current value.

Annotations
@Override