Package de.hybris.platform.util
Class SingletonCreator
- java.lang.Object
-
- de.hybris.platform.util.SingletonCreator
-
public class SingletonCreator extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSingletonCreator.Creator<T>abstract class used to for the Singleton creation.static classSingletonCreator.SingletonCreateExceptionstatic classSingletonCreator.SingletonDestroyException
-
Field Summary
Fields Modifier and Type Field Description static org.apache.log4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description SingletonCreator()creates a new SingletonCreator instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()voiddestroy()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<T> TgetSingleton(SingletonCreator.Creator<T> creator)returns a single instance created by the given Creator.<T> TgetSingleton(java.lang.Class<T> clazz)returns a single instance of the specified class.<T> TgetSingletonIfExists(SingletonCreator.Creator<T> creator)booleanisDestroyed()<T> TreplaceSingleton(SingletonCreator.Creator<T> creator)
-
-
-
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
-
replaceSingleton
public <T> T replaceSingleton(SingletonCreator.Creator<T> creator)
-
getSingletonIfExists
public <T> T getSingletonIfExists(SingletonCreator.Creator<T> creator)
-
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()
-
-