Package org.opensaml.core.xml.util
Class AbstractSimpleSingletonFactory<Input,Output>
- java.lang.Object
-
- org.opensaml.core.xml.util.AbstractSingletonFactory<Input,Output>
-
- org.opensaml.core.xml.util.AbstractSimpleSingletonFactory<Input,Output>
-
- Type Parameters:
Input- the factory input class typeOutput- the factory output class type
- All Implemented Interfaces:
SingletonFactory<Input,Output>
public abstract class AbstractSimpleSingletonFactory<Input,Output> extends AbstractSingletonFactory<Input,Output>
A simple implementation ofSingletonFactory.A
WeakHashMapis used as the underlying store. This ensures that if the input class instance become otherwise unused (weakly reachable), the input class instance key used within the factory will not prevent the input class instance from being garbage-collected, thereby preventing a memory leak.NOTE: If the output class instance holds a strong or soft reference to the input class, do not use this factory. See instead
AbstractWrappedSingletonFactory. Usage of this class in that scenario will result in a memory leak, as the input class instance will never become weakly reachable and therefore never garbage collected.
-
-
Field Summary
Fields Modifier and Type Field Description private WeakHashMap<Input,Output>mapStorage for the factory.
-
Constructor Summary
Constructors Constructor Description AbstractSimpleSingletonFactory()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Outputget(Input input)Get the output instance currently associated with the input instance.protected voidput(Input input, Output output)Store the input and output instance association.-
Methods inherited from class org.opensaml.core.xml.util.AbstractSingletonFactory
createNewInstance, getInstance
-
-
-
-
Field Detail
-
map
private WeakHashMap<Input,Output> map
Storage for the factory.
-
-
Method Detail
-
get
protected Output get(Input input)
Get the output instance currently associated with the input instance.- Specified by:
getin classAbstractSingletonFactory<Input,Output>- Parameters:
input- the input instance key- Returns:
- the output instance which corresponds to the input instance, or null if not present
-
-