Package com.helger.scope.singleton
Class AbstractRequestSingleton
- java.lang.Object
-
- com.helger.scope.singleton.AbstractSingleton
-
- com.helger.scope.singleton.AbstractRequestSingleton
-
- All Implemented Interfaces:
IScopeDestructionAware
public abstract class AbstractRequestSingleton extends AbstractSingleton
This is the base class for singleton objects that reside in the request scope. This class can be used for web scopes and non-web scopes as it handled in the same object.- Author:
- Philip Helger
- See Also:
EScope.REQUEST
-
-
Field Summary
-
Fields inherited from class com.helger.scope.singleton.AbstractSingleton
m_aRWLock
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRequestSingleton()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.helger.commons.collection.impl.ICommonsList<AbstractRequestSingleton>getAllRequestSingletons()Get all instantiated singleton objects registered in the current request scope.static <T extends AbstractRequestSingleton>
TgetRequestSingleton(Class<T> aClass)Get the singleton object in the current request scope, using the passed class.static <T extends AbstractRequestSingleton>
TgetRequestSingletonIfInstantiated(Class<T> aClass)Get the singleton object if it is already instantiated inside the current request scope ornullif it is not instantiated.static booleanisRequestSingletonInstantiated(Class<? extends AbstractRequestSingleton> aClass)Check if a singleton is already instantiated inside the current request scope-
Methods inherited from class com.helger.scope.singleton.AbstractSingleton
getAllSingletons, getSingleton, getSingletonIfInstantiated, getSingletonScopeKey, isDestroyed, isInDestruction, isInInstantiation, isInPreDestruction, isInstantiated, isSingletonInstantiated, isUsableObject, onAfterInstantiation, onBeforeDestroy, onBeforeScopeDestruction, onDestroy, onScopeDestruction, readAbstractSingletonFields, setDestroyed, setInDestruction, setInInstantiation, setInPreDestruction, setInstantiated, toString, writeAbstractSingletonFields
-
-
-
-
Method Detail
-
getRequestSingleton
@Nonnull public static final <T extends AbstractRequestSingleton> T getRequestSingleton(@Nonnull Class<T> aClass)
Get the singleton object in the current request scope, using the passed class. If the singleton is not yet instantiated, a new instance is created.- Type Parameters:
T- The type to be returned- Parameters:
aClass- The class to be used. May not benull. The class must be public as needs to have a public no-argument constructor.- Returns:
- The singleton object and never
null.
-
getRequestSingletonIfInstantiated
@Nullable public static final <T extends AbstractRequestSingleton> T getRequestSingletonIfInstantiated(@Nonnull Class<T> aClass)
Get the singleton object if it is already instantiated inside the current request scope ornullif it is not instantiated.- Type Parameters:
T- The type to be returned- Parameters:
aClass- The class to be checked. May not benull.- Returns:
- The singleton for the specified class is already instantiated,
nullotherwise.
-
isRequestSingletonInstantiated
public static final boolean isRequestSingletonInstantiated(@Nonnull Class<? extends AbstractRequestSingleton> aClass)
Check if a singleton is already instantiated inside the current request scope- Parameters:
aClass- The class to be checked. May not benull.- Returns:
trueif the singleton for the specified class is already instantiated,falseotherwise.
-
getAllRequestSingletons
@Nonnull @ReturnsMutableCopy public static final com.helger.commons.collection.impl.ICommonsList<AbstractRequestSingleton> getAllRequestSingletons()
Get all instantiated singleton objects registered in the current request scope.- Returns:
- A non-
nulllist with all instances of this class in the current request scope.
-
-