Package com.helixframework.env
Class HelixContext
java.lang.Object
com.helixframework.env.HelixContext
- All Implemented Interfaces:
Serializable
Thread local context holder for values.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the helix context variable that contains the current error id.static final StringName of the helix context variable that contains the current request id.static final StringName of the helix context variable that contains the current span id.static final StringName of the helix context variable that contains the current trace id. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks to see if the context contains an attribute with the supplied key.getAttribute(String key) Gets an attribute from the thread local context.static <T> Optional<T>getAttribute(String key, Class<T> clazz) Gets an attribute from the thread local context.static <T> TgetAttributeOrDefault(String key, T defaultValue, Class<T> clazz) Gets an attribute from the thread local context.Gets all attributes on the thread local context.getAttributes(String prefix) Gets all attributes on the thread local context whose keys start with the supplied prefix.static voidreset()Resets the thread local context holder; removing all attributes from the context.static voidsetAttribute(String key, Object value) Sets an attribute in the thread local context.static voidsetAttribute(String key, Object value, boolean includeInMDC) Sets an attribute in the thread local context and optionally adds it to the mapped diagnostic context.static voidsetAttributes(Map<String, Object> attrs) Sets attributes on the thread local context.static voidsetAttributes(Map<String, Object> attrs, boolean includeInMdc) Sets all attributes in the thread local context and optionally adds them to the mapped diagnostic context.
-
Field Details
-
CTX_REQUEST_ID_NAME
Name of the helix context variable that contains the current request id.- See Also:
-
CTX_ERROR_ID_NAME
Name of the helix context variable that contains the current error id.- See Also:
-
CTX_TRACE_ID_NAME
Name of the helix context variable that contains the current trace id.- See Also:
-
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
Sets all attributes in the thread local context and optionally adds them to the mapped diagnostic context.- Parameters:
attrs- attributesincludeInMdc- add to mapped diagnostic context
-
setAttribute
Sets an attribute in the thread local context.- Parameters:
key- attribute keyvalue- attribute value
-
setAttribute
Sets an attribute in the thread local context and optionally adds it to the mapped diagnostic context.- Parameters:
key- attribute keyvalue- attribute valueincludeInMDC- add to mapped diagnostic context
-
getAttributes
Gets all attributes on the thread local context.- Returns:
- map of all attributes on thread local context
-
setAttributes
Sets attributes on the thread local context.- Parameters:
attrs- attributes
-
getAttributes
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
Gets an attribute from the thread local context.- Type Parameters:
T- type of attribute value- Parameters:
key- key of the value in the contextclazz- type of attribute value- Returns:
- an optional of the attribute value
-
getAttribute
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
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 contextdefaultValue- default value to return when attribute is not foundclazz- type of attribute value- Returns:
- the attribute value or the default value if not found
-
contains
Checks to see if the context contains an attribute with the supplied key.- Parameters:
key- key of the value in the context- Returns:
trueif the context contains an attribute with the key; otherwisefalse
-