Package cd.connect.context
Class ConnectContext
- java.lang.Object
-
- cd.connect.context.ConnectContext
-
public class ConnectContext extends java.lang.ObjectWe use the underlying MDC of the logging library to store these as essentially they are used for logging, so much be compatible. Objects always get stored as JSON mapped strings, and the key is changed to "json."- Author:
- Richard Vowles - https://plus.google.com/+RichardVowles
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringJSON_PREFIXstatic NamedConnectContextrequestIdstatic NamedConnectContextscenarioId
-
Constructor Summary
Constructors Constructor Description ConnectContext()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclear()Clear the logging context (usually this thread)static java.lang.Stringget(java.lang.String key)Gets a key and returns the string representation of it.static <T> Tget(java.lang.String key, java.lang.Class<T> clazz)Takes the given key, finds the json: prefix version of it.static java.util.Map<java.lang.String,java.lang.String>getContext()static voidremove(java.lang.String key)Remove the specific key.static voidset(java.lang.String key, java.lang.Object value)logging contexts can generally only deal with stringsstatic voidsetContext(java.util.Map<java.lang.String,java.lang.String> pushContext)
-
-
-
Field Detail
-
requestId
public static NamedConnectContext requestId
-
scenarioId
public static NamedConnectContext scenarioId
-
JSON_PREFIX
public static final java.lang.String JSON_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
clear
public static void clear()
Clear the logging context (usually this thread)
-
remove
public static void remove(java.lang.String key)
Remove the specific key. Use clear to remove them all, always wrap this in a try/finally.- Parameters:
key- - key to remove from context
-
set
public static void set(java.lang.String key, java.lang.Object value)logging contexts can generally only deal with strings- Parameters:
key- - the key to use, will be replaced with json.KEY if value is object. If the value is a JSON object that needs to be preserved as a JSON object, use the JSON_PREFIX in your key.value- - java.lang variants are stored as strings, other objects are converted to JSON
-
get
public static java.lang.String get(java.lang.String key)
Gets a key and returns the string representation of it.- Parameters:
key- - key and will try and find the json version of it if missing.*- Returns:
- - always returns a string
-
get
public static <T> T get(java.lang.String key, java.lang.Class<T> clazz)Takes the given key, finds the json: prefix version of it.- Type Parameters:
T- - the type- Parameters:
key- - the key to get (minus the json prefix)clazz- - the class to serialize into- Returns:
- - null (if not found) or new instance of object
-
getContext
public static java.util.Map<java.lang.String,java.lang.String> getContext()
-
setContext
public static void setContext(java.util.Map<java.lang.String,java.lang.String> pushContext)
-
-