Class ThreadContext

java.lang.Object
org.rapidcontext.core.ctx.Context
org.rapidcontext.core.ctx.ThreadContext
Direct Known Subclasses:
CallContext, RequestContext

public abstract class ThreadContext extends Context
The base thread-level execution context. A new thread context is created for each procedure, web request or similar call, forming a call chain (or stack) of contexts. Each thread-level context is bound to a single execution thread. And each thread has (at most) a single active context that holds data related to a request, procedure call, etc.
Version:
1.0
  • Field Details

  • Constructor Details

    • ThreadContext

      protected ThreadContext(String id)
      Creates a new thread-level execution context.
      Parameters:
      id - the context identifier (name)
  • Method Details

    • active

      public static ThreadContext active()
      Returns the currently active thread context. If no thread-local context is available, null is returned.
      Returns:
      the currently active thread context, or null
    • logRepr

      protected static String logRepr(Object obj, boolean indent, int maxLen)
      Returns a log representation of an object.
      Parameters:
      obj - the value to log
      indent - the indentation enabled flag
      maxLen - the maximum output length
      Returns:
      the log representation
    • created

      public Date created()
      Returns the context creation time. Normally only set on the request context (or the top-most call context).
      Returns:
      the context creation time
    • request

      public Request request()
      Returns the context request.
      Returns:
      the context request
    • session

      public Session session()
      Returns the context session if set.
      Returns:
      the context session, or null if not set
    • sessionRequired

      public Session sessionRequired()
      Returns the context session if set, or creates a new one.
      Returns:
      the context session (possibly a new one)
    • user

      public User user()
      Returns the context user if set.
      Returns:
      the context user, or null if not set (anonymous)
    • isLogging

      public boolean isLogging()
      Checks if trace logging is enabled.
      Returns:
      true if trace logging is enabled, or false otherwise
    • hasAccess

      public boolean hasAccess(String path, String permission)
      Checks if the context user has a specified permission for a storage path.
      Parameters:
      path - the object storage path
      permission - the permission to check
      Returns:
      true if access is granted, or false otherwise
      See Also:
    • hasDirectAccess

      public boolean hasDirectAccess(String path, String permission)
      Checks if the context user has a specified permission for a storage path, ignoring any indirect matches.
      Parameters:
      path - the object storage path
      permission - the permission to check
      Returns:
      true if access is granted, or false otherwise
      See Also:
    • hasSearchAccess

      public boolean hasSearchAccess(String path)
      Checks if the context user has search access for a storage path.
      Parameters:
      path - the object storage path
      Returns:
      true if access is granted, or false otherwise
    • hasReadAccess

      public boolean hasReadAccess(String path)
      Checks if the context user has read access for a storage path.
      Parameters:
      path - the object storage path
      Returns:
      true if access is granted, or false otherwise
    • hasWriteAccess

      public boolean hasWriteAccess(String path)
      Checks if the context user has write access for a storage path.
      Parameters:
      path - the object storage path
      Returns:
      true if access is granted, or false otherwise
    • requireAccess

      public void requireAccess(String path, String permission) throws SecurityException
      Verifies that the context user has a specified permission for a storage path.
      Parameters:
      path - the object storage path
      permission - the required permission
      Throws:
      SecurityException - if access was denied
    • requireSearchAccess

      public void requireSearchAccess(String path) throws SecurityException
      Verifies that the context user has search access for a storage path.
      Parameters:
      path - the object storage path
      Throws:
      SecurityException - if access was denied
    • requireReadAccess

      public void requireReadAccess(String path) throws SecurityException
      Verifies that the context user has read access for a storage path.
      Parameters:
      path - the object storage path
      Throws:
      SecurityException - if access was denied
    • requireWriteAccess

      public void requireWriteAccess(String path) throws SecurityException
      Verifies that the context user has write access for a storage path.
      Parameters:
      path - the object storage path
      Throws:
      SecurityException - if access was denied
    • log

      public String log()
      Returns the current trace log text.
      Returns:
      the current trace log text, or null if not enabled
    • log

      public void log(String message)
      Logs a message to the trace log. This also enables trace logging for this context (and sub-contexts). Call this method with a null message to just enable trace logging.
      Parameters:
      message - the message to log, or null
    • logTrace

      public void logTrace(Object obj)
      Logs a message if trace logging is enabled.
      Parameters:
      obj - the message text or value
    • logRequest

      public void logRequest(String name, Object[] args)
      Logs a call request if trace logging is enabled.
      Parameters:
      name - the request name or similar
      args - the call arguments
    • logResponse

      public void logResponse(Object obj)
      Logs a call response if trace logging is enabled.
      Parameters:
      obj - the response message or value
    • logError

      public void logError(Object obj)
      Logs an error if trace logging is enabled.
      Parameters:
      obj - the error message or exception