fatalmind::ResourcePool< Type > Class Template Reference

#include <ResourcePool.hh>

Inherits fatalmind::_RPExecute< Type >.

List of all members.


Detailed Description

template<class Type>
class fatalmind::ResourcePool< Type >

A ResourcePool implements the very basic concept to pool resources.

Each resource is defined by a class called PoolType, e.g. there is a PoolType for SQL databases and TaskRunners. This type is the template arguement for a ResourcePool.

Currently ResourcePool has the following types included:

Examples:

select.cc, and selectrow.cc.


Public Types

typedef Type PoolType
 Gives access to the template parameter of ResourcePool.
typedef Type::factory_t Factory
 The factory class used for this pool.
typedef Type::command_t Command
 The available commands for this pool.

Public Member Functions

 ResourcePool (const typename Type::factory_t &, const ResourcePoolOptions &=ResourcePoolOptions::defaultOptions)
 Each ResourcePool requires a Factory, this is a class which is capable of creating new resources on demand.
virtual ~ResourcePool ()
 Destructor closes all open resources.
virtual Type::resource_t & get ()
virtual bool free (const typename Type::resource_t &)
virtual bool fail (const typename Type::resource_t &)
virtual void downsize ()
 closes unused resources.
ResourcePoolStats getStats () const
const FactorygetFactory () const
 returns a const reference to the Factory of this Pool.
virtual void execute (Command< Type > &)

Protected Types

typedef Type::ThreadingModell TM
typedef TM::FastCondVar condvar_t
typedef Synchronize< condvar_t > sync_t
typedef gc_ptr< typename
Type::resource_t, TM > 
resource_ptr
typedef std::deque< resource_ptrfreePool_t
typedef RefWrap< typename
Type::resource_t > 
plainresource_ptr
typedef std::map
< plainresource_ptr,
resource_ptr
usedPool_t

Protected Member Functions

bool sleepit (int tryno) const
Type::resource_t * moveToUsed ()
virtual const ResourcePoolOptionsgetOptions ()
void _downsize ()
void _inc_pool ()
void _waitForFree (const CreateException &, const SingleThreadedModel<>::Type)
void _waitForFree (const CreateException &, const MultiThreadedModel<>::Type)

Friends

class fatalmind::Command< Type >

Member Typedef Documentation

template<class Type>
typedef Type::command_t fatalmind::ResourcePool< Type >::Command

The available commands for this pool.

This is frequently used to access the commands without knowing the exact type of the ResourcePool. This is very useful to implement code which can easily migrated to another PoolType which offers the same commands.

consider this example: /code typedef ResourcePool<oracle::PoolType> RP; /endcode /verbatim RP::Command::SQLSelect /endverbatim is now equivalent to /verbatim oracle::PoolType::Command::SQLSelect/endverbatim but you don't need to know that this is for oracle.


Constructor & Destructor Documentation

template<class Type>
fatalmind::ResourcePool< Type >::ResourcePool ( const typename Type::factory_t &  a_factory,
const ResourcePoolOptions a_options = ResourcePoolOptions::defaultOptions 
) [inline]

Each ResourcePool requires a Factory, this is a class which is capable of creating new resources on demand.

The Options have reasonable defaults, so it is not mandatory to specify them.

References fatalmind::ResourcePoolOptions::getPreCreate().


Member Function Documentation

template<class Type>
const Factory& fatalmind::ResourcePool< Type >::getFactory (  )  const [inline]

returns a const reference to the Factory of this Pool.

The reference is valid as long as this ResourcePool itself is valid.


The documentation for this class was generated from the following files:

Generated on Mon Jun 9 11:27:03 2008 for ResourcePool by  doxygen 1.5.5