fatalmind::ResourcePool< Type > Class Template Reference

#include <ResourcePool.hh>

Inherits fatalmind::ResourcePoolInterface< Type >< 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 Commands
 The available commands for this pool.

Public Member Functions

 ResourcePool (const typename Type::factory_t &, const ResourcePoolOptions &o=ResourcePoolOptions::defaultOptions)
 The constructor needs at least a Factory, and will create a new pool.
virtual ~ResourcePool ()
 Destructor closes all open resources.
virtual
Type::resource_t & 
get ()
 Returns a plain resource to be used.
virtual bool free (typename Type::resource_t &)
 Marks a resource as free.
virtual bool fail (typename Type::resource_t &)
 Marks a resource as bad.
virtual void downsize ()
 closes unused resources.
ResourcePoolStats getStats () const
const FactorygetFactory () const
 returns a const reference to the Factory of this Pool.
ResourcePoolEventObserver::event_t setLogEvents (ResourcePoolEventObserver::event_t events)
 Sets the bitmask for the events to be logged.
virtual void execute (Command< Type > &)
 Executes a command with a resource from this pool.

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_ptr
freePool_t
typedef RefWrap
< typename
Type::resource_t > 
plainresource_ptr
typedef std::map
< plainresource_ptr,
resource_ptr
usedPool_t

Protected Member Functions

void sleepit (int tryno) const
Type::resource_t * moveToUsed ()
virtual const
ResourcePoolOptions
getOptions ()
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 >::Commands

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::Commands::SQLSelect /endverbatim is now equivalent to /verbatim oracle::PoolType::Commands::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 o = ResourcePoolOptions::defaultOptions 
) [inline]

The constructor needs at least a Factory, and will create a new pool.

Parameters:
o The options control some aspects of the pool. E.g. it's maximum size and behaviour in case of error.
e The Event Oberserver can be used to get notified about some events like failure. ResourcePoolEventObserver for details.


Member Function Documentation

template<class Type>
Type::resource_t & fatalmind::ResourcePool< Type >::get (  )  [inline, virtual]

Returns a plain resource to be used.

This has to be free()ed or fail()ed.

Exceptions:
CreateException If the ResourcePool could not find a valid resource within the given constraints (MaxTry, Max).
... Other exceptions may arise, especially if thrown in Factory::create_resource.
Deprecated:
Altought it is not really deprecated, the get(), free() fail() mechanism is not the best practice. use the execute() method instead.

Implements fatalmind::ResourcePoolInterface< Type >.

template<class Type>
bool fatalmind::ResourcePool< Type >::free ( typename Type::resource_t &   )  [inline, virtual]

Marks a resource as free.

This resource will be re-used by get() calls. The free() method calls the postcheck() method of the resource to determine if the resource is valid.

Deprecated:
Altought it is not really deprecated, the get(), free() fail() mechanism is not the best practice. use the execute() method instead.

Implements fatalmind::ResourcePoolInterface< Type >.

template<class Type>
bool fatalmind::ResourcePool< Type >::fail ( typename Type::resource_t &   )  [inline, virtual]

Marks a resource as bad.

The ResourcePool will throw this resource away and NOT return it to the pool of available connections.

Deprecated:
Altought it is not really deprecated, the get(), free() fail() mechanism is not the best practice. use the execute() method instead.

Implements fatalmind::ResourcePoolInterface< Type >.

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.

template<class Type>
void fatalmind::ResourcePool< Type >::execute ( Command< Type > &  cmd  )  [inline, virtual]

Executes a command with a resource from this pool.

Using this method is the recommended way to use ResourcePool. It handles the processing of get()/free()/fail() calls.

See Command::execute for details how to implement such commands, or see PoolType::Commands for a list of available commands for a PoolType.

Implements fatalmind::ResourcePoolInterface< Type >.

Examples:
selectrow.cc.


The documentation for this class was generated from the following files:
Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3