SessionPoolContainer: added getPool() and FastMutex locking

This commit is contained in:
Aleksandar Fabijanic 2009-05-12 20:04:27 +00:00
parent 6fa5bcf09f
commit 0bd881fd5e
2 changed files with 21 additions and 3 deletions

View File

@ -44,6 +44,7 @@
#include "Poco/Data/Session.h"
#include "Poco/Data/SessionPool.h"
#include "Poco/HashMap.h"
#include "Poco/Mutex.h"
namespace Poco {
@ -74,7 +75,12 @@ public:
/// ignored and session is returned from the existing pool.
Session get(const std::string& name);
/// Returns a Session.
/// Returns the requested Session.
/// Throws NotFoundException if session is not found.
SessionPool& getPool(const std::string& name);
/// Returns a SessionPool reference.
/// Throws NotFoundException if session is not found.
void remove(const std::string& name);
/// Removes a SessionPool.
@ -92,6 +98,7 @@ private:
SessionPoolContainer& operator = (const SessionPoolContainer&);
SessionPoolMap _sessionPools;
Poco::FastMutex _mutex;
};

View File

@ -43,6 +43,9 @@
#include <algorithm>
using Poco::FastMutex;
namespace Poco {
namespace Data {
@ -59,6 +62,7 @@ SessionPoolContainer::~SessionPoolContainer()
void SessionPoolContainer::add(SessionPool* pPool)
{
FastMutex::ScopedLock lock(_mutex);
poco_check_ptr (pPool);
if (_sessionPools.find(pPool->name()) != _sessionPools.end())
@ -75,6 +79,7 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
int maxSessions,
int idleTime)
{
FastMutex::ScopedLock lock(_mutex);
std::string name = SessionPool::name(sessionKey, connectionString);
SessionPoolMap::Iterator it = _sessionPools.find(name);
@ -92,6 +97,12 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
Session SessionPoolContainer::get(const std::string& name)
{
return getPool(name).get();
}
SessionPool& SessionPoolContainer::getPool(const std::string& name)
{
URI uri(name);
std::string path = uri.getPath();
@ -99,7 +110,7 @@ Session SessionPoolContainer::get(const std::string& name)
std::string n = Session::uri(uri.getScheme(), path.substr(1));
SessionPoolMap::Iterator it = _sessionPools.find(n);
if (_sessionPools.end() == it) throw NotFoundException(n);
return it->second->get();
return *it->second;
}