T - The type of the instances being served by the factory.public abstract class AbstractRecyclableTypeFactory<T> extends Object implements RecyclableTypeFactory<T>
AbstractRecyclableTypeFactory is an abstract implementation of
the RecyclableTypeFactory taking care on recycling and reusing
instances.
In case you want to support configuration of a recyclable instance with
Properties via the toInstance(Properties) method, make
sure your recyclable instances provide some method for reconfiguring your
instances with the provided Properties.
Implement the Configurable interface with the context being of type
Properties, so that your recyclable instances are re-configured via
the Configurable.initialize(Object) method; this is the default
behavior of the toInstance(Properties) implementation when
serving recycled instances. Override that method in case you take care
yourself on configuration of a reusable instance.
CAUTION: The recyclable instances provided are stored in a
WeakHashMap using WeakReferences in order to prevent filling
up of the recyclable objects which could cause a memory leak.
Also a given maximum of recycled instances to be contained in this factory
can be configured. In case the max number of recycled instances being managed
is reached, then calls to recycleInstance(Object) will be ignored,
meaning that no more instances will be internally be stored. This measure can
be used in addition to the weak collection we use for this Implementation.
| Constructor and Description |
|---|
AbstractRecyclableTypeFactory()
Default constructor creating a
AbstractRecyclableTypeFactory. |
AbstractRecyclableTypeFactory(int aMaxRecycledInstanceNumber)
Constructor creating a
AbstractRecyclableTypeFactory which allows
only a given maximum of recycled instances to be contained in this
factory. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
int |
getInstanceCount()
Returns the number of recycled instances currently being managed by the
AbstractRecyclableTypeFactory. |
protected abstract T |
newInstance()
To be implemented by you, called by
toInstance() in case
there are no more recycled objects available (provided via
recycleInstance(Object)).
-------------------------------------------------------------------------
This method creates / retrieves an instance of the given type with the
given identifier (name) constructed as defined in one to many
configuration files. |
protected abstract T |
newInstance(Properties aProperties)
To be implemented by you, called by
toInstance(Properties)
in case there are no more recycled objects available (provided via
recycleInstance(Object)).
-------------------------------------------------------------------------
This method creates / retrieves an instance of the given type with the
given identifier (name) constructed as defined in one to many
configuration files. |
void |
recycleInstance(T aInstance)
Makes the provided instance available for reuse by the factory.
|
T |
toInstance()
This method creates / retrieves an instance of the given type with the
given identifier (name) constructed as defined in one to many
configuration files.
|
T |
toInstance(Properties aProperties)
This method creates / retrieves an instance of the given type with the
given identifier (name) constructed as defined in one to many
configuration files.
|
public AbstractRecyclableTypeFactory()
AbstractRecyclableTypeFactory.public AbstractRecyclableTypeFactory(int aMaxRecycledInstanceNumber)
AbstractRecyclableTypeFactory which allows
only a given maximum of recycled instances to be contained in this
factory. In case the max number of recycled instances being managed is
reached, then calls to recycleInstance(Object) will be ignored,
meaning that no more instances will be internally be stored. This measure
can be used in addition to the weak collection we use for this
Implementation.aMaxRecycledInstanceNumber - The max number of recycled instances
which is not to be exceeded when internally storing recycled
instances. A value of -1 does disable that limit.public T toInstance()
TypeFactorytoInstance in interface TypeFactory<T>public T toInstance(Properties aProperties)
TypeFactorytoInstance in interface TypeFactory<T>aProperties - The dynamic properties which are used to configure the
desired bean.public void recycleInstance(T aInstance)
TypeRecyclableClearable
interface, then the provided instance is cleared by invoking the
Clearable.clear() method. In case an instance to be recycled
implements the Resetable interface, then the provided instance is
reseted by invoking the Resetable.reset() method.recycleInstance in interface TypeRecyclable<T>aInstance - The object to be recycled and offered fore reuse.public void clear()
clear in interface org.refcodes.collection.Clearablepublic int getInstanceCount()
AbstractRecyclableTypeFactory.toInstance() (or
toInstance(Properties)) invocation.protected abstract T newInstance()
toInstance() in case
there are no more recycled objects available (provided via
recycleInstance(Object)).
-------------------------------------------------------------------------
This method creates / retrieves an instance of the given type with the
given identifier (name) constructed as defined in one to many
configuration files. How the instance is configured, created or retrieved
is up to the nature (implementation) of the according factory.T - The type which is to be fabricated by the factory method.ClassCastException - in case the fabricated type is not type
compatible with the required type T.protected abstract T newInstance(Properties aProperties)
toInstance(Properties)
in case there are no more recycled objects available (provided via
recycleInstance(Object)).
-------------------------------------------------------------------------
This method creates / retrieves an instance of the given type with the
given identifier (name) constructed as defined in one to many
configuration files. How the instance is configured, created or retrieved
is up to the nature (implementation) of the according factory.T - The type which is to be fabricated by the factory method.aProperties - The dynamic properties which are used to configure the
desired bean.ClassCastException - in case the fabricated type is not type
compatible with the required type T.Copyright © 2016. All rights reserved.