Package com.linecorp.armeria.common
Interface ConcurrentAttributes
- All Superinterfaces:
AttributesGetters
,AttributesSetters
An
Attributes
supporting concurrency of retrievals and updates.-
Method Summary
Modifier and TypeMethodDescriptionstatic ConcurrentAttributes
fromParent
(AttributesGetters parent) Returns a newConcurrentAttributes
with the specified parentAttributesGetters
.static ConcurrentAttributes
of()
Returns a new emptyConcurrentAttributes
.default <T> ConcurrentAttributes
removeAndThen
(AttributeKey<T> key) Removes the value associated with the specifiedAttributeKey
in theAttributesGetters.ownAttrs()
.set
(AttributeKey<T> key, T value) Sets the specified value with the givenAttributeKey
.Methods inherited from interface com.linecorp.armeria.common.AttributesGetters
attr, attrs, hasAttr, hasOwnAttr, isEmpty, ownAttr, ownAttrs, parent, size
Methods inherited from interface com.linecorp.armeria.common.AttributesSetters
getAndSet, remove
-
Method Details
-
of
Returns a new emptyConcurrentAttributes
. -
fromParent
Returns a newConcurrentAttributes
with the specified parentAttributesGetters
. The parentAttributesGetters
can be accessed viaAttributesGetters.attr(AttributeKey)
orAttributesGetters.attrs()
.Note that any mutations in
ConcurrentAttributes
won't modify the attributes in the parent. -
set
Description copied from interface:AttributesSetters
Sets the specified value with the givenAttributeKey
. The old value associated with theAttributeKey
is replaced by the specified value. If anull
value is specified, the value in theAttributesGetters.parent()
is hidden as well.static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID"); static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN"); static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID"); Attributes attributes = Attributes.of(USER_ID, "Meri Kim", SECRET_TOKEN, "secret-1", TRACE_ID, "trace-1"); Attributes child = Attributes.builder(attributes) .set(SECRET_TOKEN, null) .set(TRACE_ID, "trace-2") .build(); // Any mutations in the child do not modify the value in the parent. assert attributes.attr(USER_ID).equals("Meri Kim"); assert attributes.attr(SECRET_TOKEN).equals("secret-1"); assert attributes.attr(TRACE_ID).equals("trace-1"); // Inherits the value of USER_ID from the parent. assert child.attr(USER_ID).equals("Meri Kim"); // Hides the value of SECRET_TOKEN that the parent has. assert child.attr(SECRET_TOKEN) == null; // Overrides the parent's TRACE_ID. assert child.attr(TRACE_ID).equals("trace-2");
- Specified by:
set
in interfaceAttributesSetters
-
removeAndThen
Description copied from interface:AttributesSetters
Removes the value associated with the specifiedAttributeKey
in theAttributesGetters.ownAttrs()
. UnlikeAttributesSetters.remove(AttributeKey)
this method returns itself so that the caller can chain the invocations.Note that this method won't remove the value in
AttributesGetters.parent()
.- Specified by:
removeAndThen
in interfaceAttributesSetters
-