Class QContext

java.lang.Object
com.kingsrook.qqq.backend.core.context.QContext

public class QContext extends Object
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 Details

    • init

      public static void init(QInstance qInstance, QSession qSession)
      Most common method to set or init the context - e.g., set the current thread with a QInstance and QSession.
    • 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

      public static void init(CapturedContext capturedContext)
      Init a new thread with the context captured from a different thread. e.g., when starting some async task.
    • capture

      public static CapturedContext 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

      public static QInstance getQInstance()
    • getQSession

      public static QSession getQSession()
    • getQBackendTransaction

      public static QBackendTransaction getQBackendTransaction()
    • getActionStack

      public static Stack<AbstractActionInput> 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

      public static void pushAction(AbstractActionInput action)
    • popAction

      public static void popAction()
    • setQInstance

      public static void setQInstance(QInstance qInstance)
    • setQSession

      public static void setQSession(QSession qSession)
    • setTransaction

      public static void setTransaction(QBackendTransaction transaction)
    • clearTransaction

      public static void clearTransaction()
    • getFirstActionInStack

      public static Optional<AbstractActionInput> getFirstActionInStack()
    • getObject

      public static Serializable getObject(String key)
      get one named object from the Context for the current thread. may return null.
    • getObject

      public static <T extends Serializable> Optional<T> getObject(String key, Class<T> type)
      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

      public static void setObject(String key, Serializable object)
      put a named object into the Context for the current thread.
    • removeObject

      public static void removeObject(String key)
      remove a named object from the Context of the current thread.
    • getObjects

      public static Map<String,Serializable> getObjects()
      get the full map of named objects for the current thread (possibly null).
    • setObjects

      public static void setObjects(Map<String,Serializable> objects)
      fully replace the map of named objets for the current thread.