Package com.helger.scope
Interface IScope
-
- All Superinterfaces:
com.helger.commons.id.IHasID<String>
- All Known Subinterfaces:
IGlobalScope,IRequestScope,ISessionScope
- All Known Implementing Classes:
AbstractScope,GlobalScope,RequestScope,SessionScope
public interface IScope extends com.helger.commons.id.IHasID<String>
This interface is used for all the common stuff of a scope. The following types of scopes are present:- Global scope - once and only once
- Application context - scope for an application (e.g. public and secure application in one web application)
- Session scope - for each user created session
- Session application context - scope for an application within a session
- Request scope - for each user request
IScopemust be thread safe!- Author:
- Philip Helger
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description com.helger.commons.collection.attr.IAttributeContainerAny<String>attrs()voiddestroyScope()Destroys the scopes and all child scopes.default com.helger.commons.collection.impl.ICommonsMap<String,IScopeRenewalAware>getAllScopeRenewalAwareAttributes()StringgetID()Get the ID of this scope.voidinitScope()Init the scope.booleanisDestroyed()booleanisInDestruction()booleanisValid()voidrunAtomic(Consumer<? super IScope> aConsumer)Perform stuff as a single action.<T> TrunAtomic(Function<? super IScope,? extends T> aFunction)Perform stuff as a single action.
-
-
-
Method Detail
-
initScope
void initScope()
Init the scope. In contrast to the constructor of a scope, this happens after the scope has been registered in the scope manager.
-
getID
String getID()
Get the ID of this scope. Each scope retrieves a unique ID within its type of scope (request, session, application). This method needs to be callable anytime and should not throw any exception!- Specified by:
getIDin interfacecom.helger.commons.id.IHasID<String>- Returns:
- the non-null ID of this context.
-
isValid
boolean isValid()
- Returns:
trueif this scope is neither in destruction nor destroyed.- See Also:
isInDestruction(),isDestroyed()
-
isInDestruction
boolean isInDestruction()
- Returns:
trueif the scope is currently in the process of destruction.
-
isDestroyed
boolean isDestroyed()
- Returns:
trueif the scope was already destroyed. This is especially important for long running scopes.
-
destroyScope
void destroyScope()
Destroys the scopes and all child scopes. This method is only automatically called, when a scope goes out of scope.
-
runAtomic
void runAtomic(@Nonnull Consumer<? super IScope> aConsumer)
Perform stuff as a single action. All actions are executed in a write-lock!- Parameters:
aConsumer- The consumer to be executed. May not benull. The parameter to the runnable isthisscope.
-
runAtomic
@Nullable <T> T runAtomic(@Nonnull Function<? super IScope,? extends T> aFunction)
Perform stuff as a single action. All actions are executed in a write-lock!- Type Parameters:
T- The return type of the callable- Parameters:
aFunction- The function to be executed. May not benull. The parameter to the callable isthisscope.- Returns:
- The result from the callable. May be
null.
-
attrs
@Nonnull @ReturnsMutableObject com.helger.commons.collection.attr.IAttributeContainerAny<String> attrs()
- Returns:
- The mutable scope attributes. Never
null.
-
getAllScopeRenewalAwareAttributes
@Nonnull @ReturnsMutableCopy default com.helger.commons.collection.impl.ICommonsMap<String,IScopeRenewalAware> getAllScopeRenewalAwareAttributes()
- Returns:
- The non-
nullmap with all contained attributes that implement theIScopeRenewalAwareinterface. May be empty.
-
-