Class WebScopeManager


  • @Immutable
    public final class WebScopeManager
    extends Object
    This is the main manager class for web scope handling.
    Author:
    Philip Helger
    • Field Detail

      • DEFAULT_SESSION_PASSIVATION_ALLOWED

        public static final boolean DEFAULT_SESSION_PASSIVATION_ALLOWED
        See Also:
        Constant Field Values
    • Method Detail

      • isSessionPassivationAllowed

        public static boolean isSessionPassivationAllowed()
        Returns:
        true if session passivation is allowed. Default is DEFAULT_SESSION_PASSIVATION_ALLOWED
      • setSessionPassivationAllowed

        public static void setSessionPassivationAllowed​(boolean bSessionPassivationAllowed)
        Allow or disallow session passivation
        Parameters:
        bSessionPassivationAllowed - true to enable session passivation, false to disable it
      • onGlobalBegin

        @Nonnull
        public static IGlobalWebScope onGlobalBegin​(@Nonnull
                                                    jakarta.servlet.ServletContext aServletContext)
        To be called, when the global web scope is initialized. Most commonly this is called from within ServletContextListener.contextInitialized(jakarta.servlet.ServletContextEvent)
        Parameters:
        aServletContext - The source servlet context to be used to retrieve the scope ID. May not be null
        Returns:
        The created global web scope
      • isGlobalScopePresent

        public static boolean isGlobalScopePresent()
        Returns:
        true if a global scope is defined, false if none is defined
      • getGlobalScopeOrNull

        @Nullable
        public static IGlobalWebScope getGlobalScopeOrNull()
        Returns:
        The global scope object or null if no global web scope is present.
      • onGlobalEnd

        public static void onGlobalEnd()
        To be called, when the global web scope is destroyed. Most commonly this is called from within ServletContextListener.contextDestroyed(jakarta.servlet.ServletContextEvent)
      • onSessionBegin

        @Nonnull
        public static ISessionWebScope onSessionBegin​(@Nonnull
                                                      jakarta.servlet.http.HttpSession aHttpSession)
        To be called, when a session web scope is initialized. Most commonly this is called from within HttpSessionListener.sessionCreated(jakarta.servlet.http.HttpSessionEvent)
        Parameters:
        aHttpSession - The source session to base the scope on. May not be null
        Returns:
        The created global session scope
      • internalGetOrCreateSessionScope

        @Nullable
        @DevelopersNote("This is only for project-internal use!")
        public static ISessionWebScope internalGetOrCreateSessionScope​(@Nonnull
                                                                       jakarta.servlet.http.HttpSession aHttpSession,
                                                                       boolean bCreateIfNotExisting,
                                                                       boolean bItsOkayToCreateANewScope)
        Internal method which does the main logic for session web scope creation
        Parameters:
        aHttpSession - The underlying HTTP session
        bCreateIfNotExisting - if true if a new session web scope is created, if none is present
        bItsOkayToCreateANewScope - if true no warning is emitted, if a new session scope must be created. This is e.g. used when renewing a session or when activating a previously passivated session.
        Returns:
        null if no session scope is present, and bCreateIfNotExisting is false
      • getSessionScope

        @Nonnull
        public static ISessionWebScope getSessionScope()
        Get or create a session scope based on the current request scope. This is the same as calling getSessionScope(ScopeManager.DEFAULT_CREATE_SCOPE)
        Returns:
        Never null.
      • getSessionScope

        @Nullable
        public static ISessionWebScope getSessionScope​(boolean bCreateIfNotExisting)
        Get the session scope from the current request scope.
        Parameters:
        bCreateIfNotExisting - if true a new session scope (and a new HTTP session if required) is created if none is existing so far.
        Returns:
        null if no session scope is present, and none should be created.
      • internalGetSessionScope

        @Nullable
        @DevelopersNote("This is only for project-internal use!")
        public static ISessionWebScope internalGetSessionScope​(boolean bCreateIfNotExisting,
                                                               boolean bItsOkayToCreateANewSession)
        Get the session scope from the current request scope.
        Parameters:
        bCreateIfNotExisting - if true a new session scope (and a new HTTP session if required) is created if none is existing so far.
        bItsOkayToCreateANewSession - if true no warning is emitted, if a new session scope must be created. This is e.g. used when renewing a session.
        Returns:
        null if no session scope is present, and none should be created.
      • internalGetSessionScope

        @Nullable
        @DevelopersNote("This is only for project-internal use!")
        public static ISessionWebScope internalGetSessionScope​(@Nullable
                                                               IRequestWebScope aRequestScope,
                                                               boolean bCreateIfNotExisting,
                                                               boolean bItsOkayToCreateANewSession)
        Get the session scope of the provided request scope.
        Parameters:
        aRequestScope - The request scope it is about. May be null.
        bCreateIfNotExisting - if true a new session scope (and a new HTTP session if required) is created if none is existing so far.
        bItsOkayToCreateANewSession - if true no warning is emitted, if a new session scope must be created. This is e.g. used when renewing a session.
        Returns:
        null if no session scope is present, and none should be created.
      • onSessionEnd

        public static void onSessionEnd​(@Nonnull
                                        jakarta.servlet.http.HttpSession aHttpSession)
        To be called, when a session web scope is destroyed. Most commonly this is called from within HttpSessionListener.sessionDestroyed(jakarta.servlet.http.HttpSessionEvent)
        Parameters:
        aHttpSession - The source session to destroy the matching scope. May not be null
      • onRequestBegin

        @Nonnull
        public static IRequestWebScope onRequestBegin​(@Nonnull
                                                      jakarta.servlet.http.HttpServletRequest aHttpRequest,
                                                      @Nonnull
                                                      jakarta.servlet.http.HttpServletResponse aHttpResponse)
      • onRequestBegin

        @Nonnull
        public static <T extends IRequestWebScope> T onRequestBegin​(@Nonnull
                                                                    jakarta.servlet.http.HttpServletRequest aHttpRequest,
                                                                    @Nonnull
                                                                    jakarta.servlet.http.HttpServletResponse aHttpResponse,
                                                                    @Nonnull
                                                                    BiFunction<? super jakarta.servlet.http.HttpServletRequest,​? super jakarta.servlet.http.HttpServletResponse,​T> aFactory)
      • isRequestScopePresent

        public static boolean isRequestScopePresent()
      • onRequestEnd

        public static void onRequestEnd()