SessionPool sessions feature/property setters and getters

SessionPoolContainer
This commit is contained in:
Aleksandar Fabijanic
2008-10-13 19:20:17 +00:00
parent 087550a844
commit 9a024d4516
13 changed files with 361 additions and 8 deletions

View File

@@ -75,7 +75,7 @@ public:
int idle() const;
/// Returns the number of seconds the session has not been used.
private:
SessionPool& _owner;
Poco::AutoPtr<SessionImpl> _pImpl;

View File

@@ -44,6 +44,8 @@
#include "Poco/Data/PooledSessionHolder.h"
#include "Poco/Data/PooledSessionImpl.h"
#include "Poco/Data/Session.h"
#include "Poco/HashMap.h"
#include "Poco/Any.h"
#include "Poco/Timer.h"
#include "Poco/Mutex.h"
#include <list>
@@ -53,7 +55,7 @@ namespace Poco {
namespace Data {
class Data_API SessionPool
class Data_API SessionPool: public RefCountedObject
/// This class implements session pooling for POCO Data.
///
/// Creating a connection to a database is often a time consuming
@@ -131,10 +133,27 @@ public:
int available() const;
/// Returns the number of available (idle + remaining capacity) sessions.
const std::string name() const;
/// Returns the name for this pool.
void setFeature(const std::string& name, bool state);
/// Sets feature for all the sessions.
bool getFeature(const std::string& name);
/// Returns the requested feature.
void setProperty(const std::string& name, const Poco::Any& value);
/// Sets property for all sessions.
Poco::Any getProperty(const std::string& name);
/// Returns the requested property.
protected:
typedef Poco::AutoPtr<PooledSessionHolder> PooledSessionHolderPtr;
typedef Poco::AutoPtr<PooledSessionImpl> PooledSessionImplPtr;
typedef std::list<PooledSessionHolderPtr> SessionList;
typedef Poco::AutoPtr<PooledSessionHolder> PooledSessionHolderPtr;
typedef Poco::AutoPtr<PooledSessionImpl> PooledSessionImplPtr;
typedef std::list<PooledSessionHolderPtr> SessionList;
typedef Poco::HashMap<std::string, bool> FeatureMap;
typedef Poco::HashMap<std::string, Poco::Any> PropertyMap;
void purgeDeadSessions();
int deadImpl(SessionList& rSessions);
@@ -154,12 +173,20 @@ private:
SessionList _idleSessions;
SessionList _activeSessions;
Poco::Timer _janitorTimer;
FeatureMap _featureMap;
PropertyMap _propertyMap;
mutable Poco::FastMutex _mutex;
friend class PooledSessionImpl;
};
inline const std::string SessionPool::name() const
{
return format("%s://%s", _sessionKey, _connectionString);
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,108 @@
//
// SessionPoolContainer.h
//
// $Id: //poco/Main/Data/include/Poco/Data/SessionPoolContainer.h#4 $
//
// Library: Data
// Package: SessionPoolContainering
// Module: SessionPoolContainer
//
// Definition of the SessionPoolContainer class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Data_SessionPoolContainer_INCLUDED
#define Data_SessionPoolContainer_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/SessionPool.h"
#include "Poco/HashMap.h"
namespace Poco {
namespace Data {
class Data_API SessionPoolContainer
/// This class implements container of session pools.
{
public:
SessionPoolContainer();
/// Creates the SessionPoolContainer for sessions with the given session parameters.
~SessionPoolContainer();
/// Destroys the SessionPoolContainer.
void add(SessionPool* pPool);
/// Adds existing session pool to the container.
Session add(const std::string& sessionKey,
const std::string& connectionString,
int minSessions = 1,
int maxSessions = 32,
int idleTime = 60);
/// Adds a new session pool to the container and returns a Session from
/// newly created pool.
Session get(const std::string& name);
/// Returns a Session.
void remove(const std::string& name);
/// Removes a SessionPool.
int count() const;
/// Returns the number of session pols in the container.
private:
typedef HashMap<std::string, AutoPtr<SessionPool> > SessionPoolMap;
SessionPoolContainer(const SessionPoolContainer&);
SessionPoolContainer& operator = (const SessionPoolContainer&);
SessionPoolMap _sessionPools;
};
inline void SessionPoolContainer::remove(const std::string& name)
{
_sessionPools.erase(name);
}
inline int SessionPoolContainer::count() const
{
return static_cast<int>(_sessionPools.size());
}
} } // namespace Poco::Data
#endif // Data_SessionPoolContainer_INCLUDED