T
- The type of the instances being served by the factory.public abstract class AbstractTypedRecyclingFactory<T> extends Object implements TypedRecyclingFactory<T>
AbstractTypedRecyclingFactory
is an abstract implementation of
the TypedRecyclingFactory
taking care on recycling and reusing
instances.
In case you want to support configuration of a recyclable instance with
Properties
via the createInstance(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 createInstance(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 WeakReference
s 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 |
---|
AbstractTypedRecyclingFactory()
Default constructor creating a
AbstractTypedRecyclingFactory . |
AbstractTypedRecyclingFactory(int aMaxRecycledInstanceNumber)
Constructor creating a
AbstractTypedRecyclingFactory which allows
only a given maximum of recycled instances to be contained in this
factory. |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
T |
createInstance()
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 |
createInstance(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.
|
int |
getInstanceCount()
Returns the number of recycled instances currently being managed by the
AbstractTypedRecyclingFactory . |
protected abstract T |
newInstance()
To be implemented by you, called by
createInstance() 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
createInstance(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.
|
public AbstractTypedRecyclingFactory()
AbstractTypedRecyclingFactory
.public AbstractTypedRecyclingFactory(int aMaxRecycledInstanceNumber)
AbstractTypedRecyclingFactory
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 createInstance()
TypedFactory
createInstance
in interface TypedFactory<T>
public T createInstance(Properties aProperties)
TypedFactory
createInstance
in interface TypedFactory<T>
aProperties
- The dynamic properties which are used to configure the
desired bean.public void recycleInstance(T aInstance)
TypedRecycling
Clearable
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 TypedRecycling<T>
aInstance
- The object to be recycled and offered fore reuse.public int getInstanceCount()
AbstractTypedRecyclingFactory
.createInstance()
(or
createInstance(Properties)
) invocation.protected abstract T newInstance()
createInstance()
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)
createInstance(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.