Class AuditRequestContext


  • public class AuditRequestContext
    extends Object
    Thread-local context for Commons Audit state.
    Since:
    13.0.0
    • Constructor Detail

      • AuditRequestContext

        public AuditRequestContext​(org.forgerock.services.TransactionId transactionId)
        Construct a new RequestContext.
        Parameters:
        transactionId - Non-null, TransactionId.
      • AuditRequestContext

        public AuditRequestContext​(org.forgerock.services.TransactionId transactionId,
                                   Map<String,​String> properties)
        Construct a new RequestContext with a copy of the given properties.
        Parameters:
        transactionId - Non-null, TransactionId.
        properties - Initial properties for this context.
    • Method Detail

      • copy

        public AuditRequestContext copy()
        Create a new instance of RequestContext, which will have a reference to the original TransactionId and a copy of the original properties. A copy can be used to hand over the context from one thread to another and therefore we make a copy of the properties in order to keep the map thread-safe. The transactionId is thread-safe and we want to see the sequence of sub-transactionIds shared across threads.
        Returns:
        a copy of this instance
      • getTransactionId

        public org.forgerock.services.TransactionId getTransactionId()
        Gets the transaction id.
        Returns:
        Non-null, TransactionId.
      • putProperty

        public static void putProperty​(String key,
                                       String value)
        Add a property to the request context. Changing a property for the same transaction in separate threads will only affect the property on the current thread. Properties are copied when the context is passed on from one thread to another.
        Parameters:
        key - the name of the property
        value - the value of the property
      • getProperty

        public static String getProperty​(String key)
        Get the value for the specified property.
        Parameters:
        key - the name of the property
        Returns:
        the value of the property or null if it has not been set
      • removeProperty

        public static String removeProperty​(String key)
        Remove the value for the specified property.
        Parameters:
        key - the name of the property
        Returns:
        the value of the property or null if it has not been set
      • get

        public static AuditRequestContext get()
        Gets the thread local RequestContext.
        Returns:
        Non-null, thread local RequestContext.
      • set

        public static void set​(AuditRequestContext auditRequestContext)
        Sets RequestContext of the current thread.
        Parameters:
        auditRequestContext - Non-null, RequestContext.
      • clear

        public static void clear()
        Discards the RequestContext of the current thread.
      • getTransactionIdValue

        public static String getTransactionIdValue()
        Gets the transaction value of the current thread.
        Returns:
        Non-null, TransactionId value.
      • createSubTransactionIdValue

        public static String createSubTransactionIdValue()
        Creates a sub transaction id from the transaction id of the current thread, for propagation to another process.
        Returns:
        Non-null, sub-TransactionId value.