Package org.rapidcontext.core.ctx
Class ThreadContext
java.lang.Object
org.rapidcontext.core.ctx.Context
org.rapidcontext.core.ctx.ThreadContext
- Direct Known Subclasses:
CallContext,RequestContext
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe creation time context attribute.static final StringThe log context attribute.static final StringThe request context attribute.static final StringThe session context attribute.static final StringThe user context attribute.static final intThe maximum number of characters to store in the log buffer.Fields inherited from class org.rapidcontext.core.ctx.Context
actives, CX_DIRECTORY, CX_ENVIRONMENT, CX_SCHEDULER, CX_STORAGE, id, parent, root -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThreadContext(String id) Creates a new thread-level execution context. -
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadContextactive()Returns the currently active thread context.created()Returns the context creation time.booleanChecks if the context user has a specified permission for a storage path.booleanhasDirectAccess(String path, String permission) Checks if the context user has a specified permission for a storage path, ignoring any indirect matches.booleanhasReadAccess(String path) Checks if the context user has read access for a storage path.booleanhasSearchAccess(String path) Checks if the context user has search access for a storage path.booleanhasWriteAccess(String path) Checks if the context user has write access for a storage path.booleanChecks if trace logging is enabled.log()Returns the current trace log text.voidLogs a message to the trace log.voidLogs an error if trace logging is enabled.protected static StringReturns a log representation of an object.voidlogRequest(String name, Object[] args) Logs a call request if trace logging is enabled.voidlogResponse(Object obj) Logs a call response if trace logging is enabled.voidLogs a message if trace logging is enabled.request()Returns the context request.voidrequireAccess(String path, String permission) Verifies that the context user has a specified permission for a storage path.voidrequireReadAccess(String path) Verifies that the context user has read access for a storage path.voidrequireSearchAccess(String path) Verifies that the context user has search access for a storage path.voidrequireWriteAccess(String path) Verifies that the context user has write access for a storage path.session()Returns the context session if set.Returns the context session if set, or creates a new one.user()Returns the context user if set.
-
Field Details
-
MAX_LOG_LENGTH
public static final int MAX_LOG_LENGTHThe maximum number of characters to store in the log buffer.- See Also:
-
CX_CREATED
The creation time context attribute.- See Also:
-
CX_LOG
The log context attribute.- See Also:
-
CX_REQUEST
The request context attribute.- See Also:
-
CX_SESSION
The session context attribute.- See Also:
-
CX_USER
The user context attribute.- See Also:
-
-
Constructor Details
-
ThreadContext
Creates a new thread-level execution context.- Parameters:
id- the context identifier (name)
-
-
Method Details
-
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
Returns a log representation of an object.- Parameters:
obj- the value to logindent- the indentation enabled flagmaxLen- the maximum output length- Returns:
- the log representation
-
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
Returns the context request.- Returns:
- the context request
-
session
Returns the context session if set.- Returns:
- the context session, or null if not set
-
sessionRequired
Returns the context session if set, or creates a new one.- Returns:
- the context session (possibly a new one)
-
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
Checks if the context user has a specified permission for a storage path.- Parameters:
path- the object storage pathpermission- the permission to check- Returns:
- true if access is granted, or false otherwise
- See Also:
-
hasDirectAccess
Checks if the context user has a specified permission for a storage path, ignoring any indirect matches.- Parameters:
path- the object storage pathpermission- the permission to check- Returns:
- true if access is granted, or false otherwise
- See Also:
-
hasSearchAccess
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
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
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
Verifies that the context user has a specified permission for a storage path.- Parameters:
path- the object storage pathpermission- the required permission- Throws:
SecurityException- if access was denied
-
requireSearchAccess
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
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
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
Returns the current trace log text.- Returns:
- the current trace log text, or null if not enabled
-
log
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
Logs a message if trace logging is enabled.- Parameters:
obj- the message text or value
-
logRequest
Logs a call request if trace logging is enabled.- Parameters:
name- the request name or similarargs- the call arguments
-
logResponse
Logs a call response if trace logging is enabled.- Parameters:
obj- the response message or value
-
logError
Logs an error if trace logging is enabled.- Parameters:
obj- the error message or exception
-