Class DefaultThreadContext

java.lang.Object
com.sap.cloud.sdk.cloudplatform.thread.DefaultThreadContext
All Implemented Interfaces:
ThreadContext

public class DefaultThreadContext extends Object implements ThreadContext
This class represents the default implementation of ThreadContext.
  • Constructor Details

    • DefaultThreadContext

      public DefaultThreadContext()
  • Method Details

    • getPropertyValue

      @Nonnull public <T> io.vavr.control.Try<T> getPropertyValue(@Nonnull String name)
      Description copied from interface: ThreadContext
      Retrieves a Try of the property's value 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.
      Specified by:
      getPropertyValue in interface ThreadContext
      Type Parameters:
      T - The generic value type.
      Parameters:
      name - The name of the property.
      Returns:
      The value wrapped in a Try.
    • setPropertyIfAbsent

      public void setPropertyIfAbsent(@Nonnull String name, @Nonnull Property<?> value) throws ThreadContextPropertyException
      Description copied from interface: ThreadContext
      Sets a value for the property for the given name, if it has not been set before. Implementations have to ensure that this method is thread-safe.
      Specified by:
      setPropertyIfAbsent in interface ThreadContext
      Parameters:
      name - The name of the property.
      value - A Property.
      Throws:
      ThreadContextPropertyException - If there is an issue while setting the property.
    • removeProperty

      @Nonnull public <T> io.vavr.control.Option<Property<T>> removeProperty(@Nonnull String name) throws ClassCastException
      Description copied from interface: ThreadContext
      Removes the property with the given name.

      Caution: Implementations may not be thread-safe!

      Specified by:
      removeProperty in interface ThreadContext
      Type Parameters:
      T - The generic value type.
      Parameters:
      name - The name of the property.
      Returns:
      A Option holding the removed value, or Option.none() if the property did not exist before.
      Throws:
      ClassCastException - If the property cannot be cast to the desired type.
    • containsProperty

      public boolean containsProperty(@Nonnull String name)
      Description copied from interface: ThreadContext
      Check whether a property with the given name is present and readable.

      Caution: Implementations may not be thread-safe!

      Specified by:
      containsProperty in interface ThreadContext
      Parameters:
      name - The name of the property.
      Returns:
      A boolean indicating whether the property does exist and is readable.
    • duplicate

      @Nonnull public ThreadContext duplicate()
      Description copied from interface: ThreadContext
      Create a new ThreadContext containing all properties of this context. Both the new and the existing context will point to the same property objects. This is useful for passing on a context to a new thread, without the two contexts interfering with each other.

      Caution: Implementations may not be thread-safe!

      Specified by:
      duplicate in interface ThreadContext
      Returns:
      A new instance of ThreadContext.
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(@Nullable Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getProperties

      public ConcurrentMap<String,Property<?>> getProperties()