public class DefaultThreadContext extends Object implements ThreadContext
ThreadContext
.Constructor and Description |
---|
DefaultThreadContext() |
Modifier and Type | Method and Description |
---|---|
ConcurrentMap<String,io.vavr.control.Try<Property<?>>> |
getProperties() |
<T> io.vavr.control.Try<Property<T>> |
getProperty(String name)
Retrieves a
Try of the property for the given name. |
Thread |
getThread()
Returns the original thread.
|
<T> io.vavr.control.Try<Property<T>> |
removeProperty(String name)
Removes the property with the given name.
|
void |
setPropertyIfAbsent(String name,
io.vavr.control.Try<Property<?>> value)
Sets a value for the property for the given name, if it has not been set before.
|
String |
toString() |
@Nonnull public <T> io.vavr.control.Try<Property<T>> getProperty(@Nonnull String name) throws ClassCastException
Try
of the property for the given name. The Try
is considered to fail in case of
exceptions or if the property does not exist. Implementations have to ensure that this method is thread-safe.getProperty
in interface ThreadContext
name
- The name of the property.Try
of the property.ClassCastException
- If the property cannot be cast to the desired type.public void setPropertyIfAbsent(@Nonnull String name, @Nonnull io.vavr.control.Try<Property<?>> value) throws ThreadContextPropertyException
setPropertyIfAbsent
in interface ThreadContext
name
- The name of the property.value
- A Try
of the property.ThreadContextPropertyException
- If there is an issue while setting the property.@Nonnull public <T> io.vavr.control.Try<Property<T>> removeProperty(@Nonnull String name) throws ClassCastException
Caution: Implementations may not be thread-safe!
removeProperty
in interface ThreadContext
name
- The name of the property.Try
holding the removed value, or a failure if there was an exception or the property does not
exist.ClassCastException
- If the property cannot be cast to the desired type.public Thread getThread()
ThreadContext
getThread
in interface ThreadContext
public ConcurrentMap<String,io.vavr.control.Try<Property<?>>> getProperties()
Copyright © 2019 SAP SE. All rights reserved.