Design
PooliT has a very simple core API consisting of four interfaces:
Pooler and PoolHandler for pooling purposes, and
Cacher and CacheHandler for caching purposes.
The core API is found in the ca.huy.poolit package.
The Pooler interface defines methods to retrieve and return
objects to a pool. It is left to classes implementing this interface to
establish the pooling algorithm to be used. Several Poolers are
provided with PooliT that offer simple pooling strategies -- like
FixedPooler that store objects in an array -- to more complex
strategies, such as TimeoutPooler that will clean up objects which
have not been used for an extended period of time. Poolers
provided with PooliT can be found in the
ca.huy.poolit.poolers package. Please consult the javadoc to
find other Poolers provided with PooliT. Poolers
should not be tied to a particular class to be pooled. Poolers
are meant to be able to pool any type of object, and should only be concerned
about the pooling algorithm.
The PoolHandler interface defines methods to create, destroy and
check the integrity of objects that are being pooled. Poolers
call the PoolHandler to perform the three actions mentioned when needed
because the handlers contain the logic to perform these operations for a particular
class. Several PoolHandlers are packaged with PooliT and can be
found in the ca.huy.poolit.handlers package. Some
examples of classes that have handlers provided by PooliT:
java.net.Socketjava.sql.Connectionjavax.naming.InitialContext
The Cacher interface defines methods to retrieve and store objects
in a cache. Objects stored are keyed so that they may be retrieved later with the
same key (like a Map). Classes implementing this interface only concern themselves with
how objects are cached and not the types of objects being cached. If an object
is not found in a cache, the Cacher will call the CacheHandler
to create the requested object. Think of a Cacher as a repository where the same
instance given its keys can be retrieved by multiple objects. Contrast that to a
Pooler where each request to a Pooler results in a different instance being returned
each time.
The CacheHandler interface defines methods to create and destroy objects
that are being cached. CacheHandler defines methods that are similar to
methods found in PoolHandler. Most classes found in the
ca.huy.poolit.handlers implement both these interfaces because behaviourily
they are very similar.