Class ConnectContext


  • public class ConnectContext
    extends java.lang.Object
    We 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
    • Constructor Summary

      Constructors 
      Constructor Description
      ConnectContext()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Clear the logging context (usually this thread)
      static java.lang.String get​(java.lang.String key)
      Gets a key and returns the string representation of it.
      static <T> T get​(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 void remove​(java.lang.String key)
      Remove the specific key.
      static void set​(java.lang.String key, java.lang.Object value)
      logging contexts can generally only deal with strings
      static void setContext​(java.util.Map<java.lang.String,​java.lang.String> pushContext)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConnectContext

        public ConnectContext()
    • 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)