Class AbstractSessionSingleton

  • All Implemented Interfaces:
    IScopeDestructionAware

    @MustImplementEqualsAndHashcode
    public abstract class AbstractSessionSingleton
    extends AbstractSingleton
    This is the base class for singleton objects that reside in the session non-web scope.
    Author:
    Philip Helger
    See Also:
    EScope.SESSION
    • Constructor Detail

      • AbstractSessionSingleton

        protected AbstractSessionSingleton()
    • Method Detail

      • getSessionSingleton

        @Nonnull
        public static final <T extends AbstractSessionSingleton> T getSessionSingleton​(@Nonnull
                                                                                       Class<T> aClass)
        Get the singleton object in the current session 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 be null. The class must be public as needs to have a public no-argument constructor.
        Returns:
        The singleton object and never null.
      • getSessionSingletonIfInstantiated

        @Nullable
        public static final <T extends AbstractSessionSingleton> T getSessionSingletonIfInstantiated​(@Nonnull
                                                                                                     Class<T> aClass)
        Get the singleton object if it is already instantiated inside the current session scope or null if it is not instantiated.
        Type Parameters:
        T - The type to be returned
        Parameters:
        aClass - The class to be checked. May not be null.
        Returns:
        The singleton for the specified class is already instantiated, null otherwise.
      • isSessionSingletonInstantiated

        public static final boolean isSessionSingletonInstantiated​(@Nonnull
                                                                   Class<? extends AbstractSessionSingleton> aClass)
        Check if a singleton is already instantiated inside the current session scope
        Parameters:
        aClass - The class to be checked. May not be null.
        Returns:
        true if the singleton for the specified class is already instantiated, false otherwise.
      • getAllSessionSingletons

        @Nonnull
        @ReturnsMutableCopy
        public static final com.helger.commons.collection.impl.ICommonsList<AbstractSessionSingleton> getAllSessionSingletons()
        Get all instantiated singleton objects registered in the current session scope.
        Returns:
        A non-null list with all instances of this class in the current session scope.