Package com.helger.web.scope.mgr
Class WebScopeManager
- java.lang.Object
-
- com.helger.web.scope.mgr.WebScopeManager
-
@Immutable public final class WebScopeManager extends Object
This is the main manager class for web scope handling.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_SESSION_PASSIVATION_ALLOWED
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IGlobalWebScopegetGlobalScope()static IGlobalWebScopegetGlobalScopeOrNull()static IRequestWebScopegetRequestScope()static IRequestWebScopegetRequestScopeOrNull()static ISessionWebScopegetSessionScope()Get or create a session scope based on the current request scope.static ISessionWebScopegetSessionScope(boolean bCreateIfNotExisting)Get the session scope from the current request scope.static ISessionWebScopeinternalGetOrCreateSessionScope(jakarta.servlet.http.HttpSession aHttpSession, boolean bCreateIfNotExisting, boolean bItsOkayToCreateANewScope)Internal method which does the main logic for session web scope creationstatic ISessionWebScopeinternalGetSessionScope(boolean bCreateIfNotExisting, boolean bItsOkayToCreateANewSession)Get the session scope from the current request scope.static ISessionWebScopeinternalGetSessionScope(IRequestWebScope aRequestScope, boolean bCreateIfNotExisting, boolean bItsOkayToCreateANewSession)Get the session scope of the provided request scope.static booleanisGlobalScopePresent()static booleanisRequestScopePresent()static booleanisSessionPassivationAllowed()static IGlobalWebScopeonGlobalBegin(jakarta.servlet.ServletContext aServletContext)To be called, when the global web scope is initialized.static IGlobalWebScopeonGlobalBegin(jakarta.servlet.ServletContext aServletContext, Function<? super jakarta.servlet.ServletContext,? extends IGlobalWebScope> aFactory)static voidonGlobalEnd()To be called, when the global web scope is destroyed.static IRequestWebScopeonRequestBegin(jakarta.servlet.http.HttpServletRequest aHttpRequest, jakarta.servlet.http.HttpServletResponse aHttpResponse)static <T extends IRequestWebScope>
TonRequestBegin(jakarta.servlet.http.HttpServletRequest aHttpRequest, jakarta.servlet.http.HttpServletResponse aHttpResponse, BiFunction<? super jakarta.servlet.http.HttpServletRequest,? super jakarta.servlet.http.HttpServletResponse,T> aFactory)static voidonRequestEnd()static ISessionWebScopeonSessionBegin(jakarta.servlet.http.HttpSession aHttpSession)To be called, when a session web scope is initialized.static <T extends ISessionWebScope>
TonSessionBegin(jakarta.servlet.http.HttpSession aHttpSession, Function<? super jakarta.servlet.http.HttpSession,T> aFactory)static voidonSessionEnd(jakarta.servlet.http.HttpSession aHttpSession)To be called, when a session web scope is destroyed.static voidsetSessionPassivationAllowed(boolean bSessionPassivationAllowed)Allow or disallow session passivation
-
-
-
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:
trueif session passivation is allowed. Default isDEFAULT_SESSION_PASSIVATION_ALLOWED
-
setSessionPassivationAllowed
public static void setSessionPassivationAllowed(boolean bSessionPassivationAllowed)
Allow or disallow session passivation- Parameters:
bSessionPassivationAllowed-trueto enable session passivation,falseto 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 withinServletContextListener.contextInitialized(jakarta.servlet.ServletContextEvent)- Parameters:
aServletContext- The source servlet context to be used to retrieve the scope ID. May not benull- Returns:
- The created global web scope
-
onGlobalBegin
@Nonnull public static IGlobalWebScope onGlobalBegin(@Nonnull jakarta.servlet.ServletContext aServletContext, @Nonnull Function<? super jakarta.servlet.ServletContext,? extends IGlobalWebScope> aFactory)
-
isGlobalScopePresent
public static boolean isGlobalScopePresent()
- Returns:
trueif a global scope is defined,falseif none is defined
-
getGlobalScopeOrNull
@Nullable public static IGlobalWebScope getGlobalScopeOrNull()
- Returns:
- The global scope object or
nullif no global web scope is present.
-
getGlobalScope
@Nonnull public static IGlobalWebScope getGlobalScope()
- Returns:
- The global scope object and never
null. - Throws:
IllegalStateException- If no global web scope object is present
-
onGlobalEnd
public static void onGlobalEnd()
To be called, when the global web scope is destroyed. Most commonly this is called from withinServletContextListener.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 withinHttpSessionListener.sessionCreated(jakarta.servlet.http.HttpSessionEvent)- Parameters:
aHttpSession- The source session to base the scope on. May not benull- Returns:
- The created global session scope
-
onSessionBegin
@Nonnull public static <T extends ISessionWebScope> T onSessionBegin(@Nonnull jakarta.servlet.http.HttpSession aHttpSession, @Nonnull Function<? super jakarta.servlet.http.HttpSession,T> aFactory)
-
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 sessionbCreateIfNotExisting- iftrueif a new session web scope is created, if none is presentbItsOkayToCreateANewScope- iftrueno 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:
nullif 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 callinggetSessionScope(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- iftruea new session scope (and a new HTTP session if required) is created if none is existing so far.- Returns:
nullif 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- iftruea new session scope (and a new HTTP session if required) is created if none is existing so far.bItsOkayToCreateANewSession- iftrueno warning is emitted, if a new session scope must be created. This is e.g. used when renewing a session.- Returns:
nullif 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 benull.bCreateIfNotExisting- iftruea new session scope (and a new HTTP session if required) is created if none is existing so far.bItsOkayToCreateANewSession- iftrueno warning is emitted, if a new session scope must be created. This is e.g. used when renewing a session.- Returns:
nullif 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 withinHttpSessionListener.sessionDestroyed(jakarta.servlet.http.HttpSessionEvent)- Parameters:
aHttpSession- The source session to destroy the matching scope. May not benull
-
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)
-
getRequestScopeOrNull
@Nullable public static IRequestWebScope getRequestScopeOrNull()
-
isRequestScopePresent
public static boolean isRequestScopePresent()
-
getRequestScope
@Nonnull public static IRequestWebScope getRequestScope()
-
onRequestEnd
public static void onRequestEnd()
-
-