-
- Type Parameters:
T
- the type of the value it holds.
public interface Attribute<T>
An attribute which allows to store a value reference. It may be updated atomically and so is thread-safe.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description boolean
compareAndSet(T oldValue, T newValue)
Atomically sets the value to the given updated value if the current value == the expected value.T
get()
Returns the current value, which may benull
T
getAndRemove()
Deprecated.please consider usinggetAndSet(Object)
(with value ofnull
).T
getAndSet(T value)
Atomically sets to the given value and returns the old value which may benull
if non was set before.AttributeKey<T>
key()
Returns the key of this attribute.void
remove()
Deprecated.please consider usingset(Object)
(with value ofnull
).void
set(T value)
Sets the valueT
setIfAbsent(T value)
Atomically sets to the given value if thisAttribute
's value isnull
.
-
-
-
Method Detail
-
key
AttributeKey<T> key()
Returns the key of this attribute.
-
get
T get()
Returns the current value, which may benull
-
set
void set(T value)
Sets the value
-
getAndSet
T getAndSet(T value)
Atomically sets to the given value and returns the old value which may benull
if non was set before.
-
setIfAbsent
T setIfAbsent(T value)
Atomically sets to the given value if thisAttribute
's value isnull
. If it was not possible to set the value as it contains a value it will just return the current value.
-
getAndRemove
@Deprecated T getAndRemove()
Deprecated.please consider usinggetAndSet(Object)
(with value ofnull
).Removes this attribute from theAttributeMap
and returns the old value. Subsequentget()
calls will returnnull
. If you only want to return the old value and clear theAttribute
while still keep it in theAttributeMap
usegetAndSet(Object)
with a value ofnull
.Be aware that even if you call this method another thread that has obtained a reference to this
Attribute
viaAttributeMap.attr(AttributeKey)
will still operate on the same instance. That said if now another thread or even the same thread later will callAttributeMap.attr(AttributeKey)
again, a newAttribute
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 callremove()
orgetAndRemove()
.
-
compareAndSet
boolean compareAndSet(T oldValue, T newValue)
Atomically sets the value to the given updated value if the current value == the expected value. If it the set was successful it returnstrue
otherwisefalse
.
-
remove
@Deprecated void remove()
Deprecated.please consider usingset(Object)
(with value ofnull
).Removes this attribute from theAttributeMap
. Subsequentget()
calls will return @{code null}. If you only want to remove the value and clear theAttribute
while still keep it inAttributeMap
useset(Object)
with a value ofnull
.Be aware that even if you call this method another thread that has obtained a reference to this
Attribute
viaAttributeMap.attr(AttributeKey)
will still operate on the same instance. That said if now another thread or even the same thread later will callAttributeMap.attr(AttributeKey)
again, a newAttribute
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 callremove()
orgetAndRemove()
.
-
-