Class HelixContext

java.lang.Object
com.helixframework.env.HelixContext
All Implemented Interfaces:
Serializable

public final class HelixContext extends Object implements Serializable
Thread local context holder for values.
See Also:
  • Field Details

    • CTX_REQUEST_ID_NAME

      public static final String CTX_REQUEST_ID_NAME
      Name of the helix context variable that contains the current request id.
      See Also:
    • CTX_ERROR_ID_NAME

      public static final String CTX_ERROR_ID_NAME
      Name of the helix context variable that contains the current error id.
      See Also:
    • CTX_TRACE_ID_NAME

      public static final String CTX_TRACE_ID_NAME
      Name of the helix context variable that contains the current trace id.
      See Also:
    • CTX_SPAN_ID_NAME

      public static final String CTX_SPAN_ID_NAME
      Name of the helix context variable that contains the current span id.
      See Also:
  • Method Details

    • reset

      public static void reset()
      Resets the thread local context holder; removing all attributes from the context.
    • setAttributes

      public static void setAttributes(Map<String,Object> attrs, boolean includeInMdc)
      Sets all attributes in the thread local context and optionally adds them to the mapped diagnostic context.
      Parameters:
      attrs - attributes
      includeInMdc - add to mapped diagnostic context
    • setAttribute

      public static void setAttribute(String key, Object value)
      Sets an attribute in the thread local context.
      Parameters:
      key - attribute key
      value - attribute value
    • setAttribute

      public static void setAttribute(String key, Object value, boolean includeInMDC)
      Sets an attribute in the thread local context and optionally adds it to the mapped diagnostic context.
      Parameters:
      key - attribute key
      value - attribute value
      includeInMDC - add to mapped diagnostic context
    • getAttributes

      public static Map<String,Object> getAttributes()
      Gets all attributes on the thread local context.
      Returns:
      map of all attributes on thread local context
    • setAttributes

      public static void setAttributes(Map<String,Object> attrs)
      Sets attributes on the thread local context.
      Parameters:
      attrs - attributes
    • getAttributes

      public static Map<String,Object> getAttributes(String prefix)
      Gets all attributes on the thread local context whose keys start with the supplied prefix.
      Parameters:
      prefix - key prefix
      Returns:
      map of all attributes on the thread local context whose keys start with the prefix
    • getAttribute

      public static <T> Optional<T> getAttribute(String key, Class<T> clazz)
      Gets an attribute from the thread local context.
      Type Parameters:
      T - type of attribute value
      Parameters:
      key - key of the value in the context
      clazz - type of attribute value
      Returns:
      an optional of the attribute value
    • getAttribute

      public static Optional<String> getAttribute(String key)
      Gets an attribute from the thread local context.
      Parameters:
      key - key of the value in the context
      Returns:
      an optional of the attribute value
    • getAttributeOrDefault

      public static <T> T getAttributeOrDefault(String key, T defaultValue, Class<T> clazz)
      Gets an attribute from the thread local context. If the value is not found then the default value is returned.
      Type Parameters:
      T - type of attribute value
      Parameters:
      key - key of the value in the context
      defaultValue - default value to return when attribute is not found
      clazz - type of attribute value
      Returns:
      the attribute value or the default value if not found
    • contains

      public static boolean contains(String key)
      Checks to see if the context contains an attribute with the supplied key.
      Parameters:
      key - key of the value in the context
      Returns:
      true if the context contains an attribute with the key; otherwise false