Class SingletonCreator


  • public class SingletonCreator
    extends java.lang.Object
    • Field Detail

      • log

        public static final org.apache.log4j.Logger log
    • Constructor Detail

      • SingletonCreator

        public SingletonCreator()
        creates a new SingletonCreator instance
    • Method Detail

      • getSingleton

        public <T> T getSingleton​(java.lang.Class<T> clazz)
        returns a single instance of the specified class. This is done by calling the newInstance() method on the class object. this method guarantees that only one instance is being created for this SingletonCreator instance. These instances will be cached and returned on subsequent calls of this method. Implementation note: This method implicitly creates a Creator instance and passes this to the getSingleton( Creator ) method. The key of this Creator instance (the getID() method) uses the full qualified class name (Class.getName()) to identify this singleton.
        Parameters:
        clazz - the Class for which the instance should be created
        Returns:
        T the singleton instance
      • getSingleton

        public <T> T getSingleton​(SingletonCreator.Creator<T> creator)
        returns a single instance created by the given Creator. this method guarantees that only one instance is being created for this SingletonCreator instance. These instances will be cached in a Map keyed by the creator.getID() result are and returned on subsequent calls of this method.
        Parameters:
        creator - the Creator
        Returns:
        T the singleton instance
      • destroy

        public void destroy()
        destroys this SingletonCreator instance this method will call the destroy() method of each SingletonCreator.Creator instance that was used when calling getSingleton() in reverse order to allow you to cleanup correctly
      • isDestroyed

        public boolean isDestroyed()
      • clear

        public void clear()