Class QContext
java.lang.Object
com.kingsrook.qqq.backend.core.context.QContext
A collection of thread-local variables, to define the current context of the
QQQ code that is running. e.g., what QInstance is being used, what QSession
is active, etc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CapturedContextcapture()Capture all values from the current thread - meant to be used with the init overload that takes a CapturedContext, for setting up a child thread.static voidclear()Clear all values in the current thread.static voidstatic voidOpen an authorized action scope.static voidClose an authorized action scope opened by enterAuthorizedActionScope.static Stack<AbstractActionInput> static intGet the number of authorized action scopes that are currently open on this thread. 0 means that the code running now is not inside any core action (e.g., it is a middleware entry point, a custom route, or a script), so a core action called from here is an "outermost" call, subject to the instance's core permission-enforcement setting.static Optional<AbstractActionInput> static Serializableget one named object from the Context for the current thread.static <T extends Serializable>
Optional<T> get one named object from the Context for the current thread, cast to the specified type if possible.static Map<String, Serializable> get the full map of named objects for the current thread (possibly null).static QBackendTransactionstatic QInstancestatic QSessionstatic voidinit(CapturedContext capturedContext) Init a new thread with the context captured from a different thread.static voidMost common method to set or init the context - e.g., set the current thread with a QInstance and QSession.static voidinit(QInstance qInstance, QSession qSession, QBackendTransaction transaction, AbstractActionInput actionInput) Full flavor init method - also take a transaction and action input (to seed the stack).static voidstatic voidpushAction(AbstractActionInput action) static voidremoveObject(String key) remove a named object from the Context of the current thread.static voidsetObject(String key, Serializable object) put a named object into the Context for the current thread.static voidsetObjects(Map<String, Serializable> objects) fully replace the map of named objets for the current thread.static voidsetQInstance(QInstance qInstance) static voidsetQSession(QSession qSession) static voidsetTransaction(QBackendTransaction transaction) static <T extends Throwable>
voidwithTemporaryContext(CapturedContext context, UnsafeVoidVoidMethod<T> method)
-
Method Details
-
init
-
init
public static void init(QInstance qInstance, QSession qSession, QBackendTransaction transaction, AbstractActionInput actionInput) Full flavor init method - also take a transaction and action input (to seed the stack). -
withTemporaryContext
public static <T extends Throwable> void withTemporaryContext(CapturedContext context, UnsafeVoidVoidMethod<T> method) throws T - Throws:
T
-
init
Init a new thread with the context captured from a different thread. e.g., when starting some async task. -
capture
Capture all values from the current thread - meant to be used with the init overload that takes a CapturedContext, for setting up a child thread. -
clear
public static void clear()Clear all values in the current thread. -
getQInstance
-
getQSession
-
getQBackendTransaction
-
getActionStack
-
getAuthorizedActionScopeDepth
public static int getAuthorizedActionScopeDepth()Get the number of authorized action scopes that are currently open on this thread. 0 means that the code running now is not inside any core action (e.g., it is a middleware entry point, a custom route, or a script), so a core action called from here is an "outermost" call, subject to the instance's core permission-enforcement setting. -
enterAuthorizedActionScope
public static void enterAuthorizedActionScope()Open an authorized action scope. Meant to be called by core actions after they have applied whatever permission enforcement is owed to their caller (and by framework code that runs trusted internal work), always paired with exitAuthorizedActionScope in a finally block - or, preferably, use CorePermissionEnforcer.openAuthorizedScope() in a try-with-resources. -
exitAuthorizedActionScope
public static void exitAuthorizedActionScope()Close an authorized action scope opened by enterAuthorizedActionScope. -
pushAction
-
popAction
public static void popAction() -
setQInstance
-
setQSession
-
setTransaction
-
clearTransaction
public static void clearTransaction() -
getFirstActionInStack
-
getObject
get one named object from the Context for the current thread. may return null. -
getObject
get one named object from the Context for the current thread, cast to the specified type if possible. if not found, or wrong type, empty is returned. -
setObject
put a named object into the Context for the current thread. -
removeObject
remove a named object from the Context of the current thread. -
getObjects
get the full map of named objects for the current thread (possibly null). -
setObjects
fully replace the map of named objets for the current thread.
-