SessionPool diagnostics

This commit is contained in:
Alex Fabijanic 2014-02-10 21:33:38 -06:00
parent f993183637
commit 0ad18f3e80
4 changed files with 55 additions and 0 deletions

View File

@ -174,6 +174,10 @@ public:
/// Returns the requested property.
void shutdown();
/// Shuts down the session pool.
bool isActive() const;
/// Returns true if session pool is active (not shut down).
protected:
typedef Poco::AutoPtr<PooledSessionHolder> PooledSessionHolderPtr;
@ -233,6 +237,12 @@ inline std::string SessionPool::name() const
}
inline bool SessionPool::isActive() const
{
return !_shutdown;
}
} } // namespace Poco::Data

View File

@ -74,6 +74,16 @@ public:
/// newly created pool. If pool already exists, request to add is silently
/// ignored and session is returned from the existing pool.
bool has(const std::string& name) const;
/// Returns true if the requested name exists, false otherwise.
bool isActive(const std::string& sessionKey,
const std::string& connectionString = "") const;
/// Returns true if the session is active (i.e. not shut down).
/// If connectionString is empty string, sessionKey must be a
/// fully qualified session name as registered with the pool
/// container.
Session get(const std::string& name);
/// Returns the requested Session.
/// Throws NotFoundException if session is not found.
@ -102,6 +112,12 @@ private:
};
inline bool SessionPoolContainer::has(const std::string& name) const
{
return _sessionPools.find(name) != _sessionPools.end();
}
inline void SessionPoolContainer::remove(const std::string& name)
{
_sessionPools.erase(name);

View File

@ -97,6 +97,22 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
}
bool SessionPoolContainer::isActive(const std::string& sessionKey,
const std::string& connectionString) const
{
std::string name = connectionString.empty() ?
sessionKey : SessionPool::name(sessionKey, connectionString);
SessionPoolMap::const_iterator it = _sessionPools.find(name);
if (it != _sessionPools.end() && it->second->isActive())
{
return true;
}
return false;
}
Session SessionPoolContainer::get(const std::string& name)
{
return getPool(name).get();

View File

@ -214,7 +214,9 @@ void SessionPoolTest::testSessionPool()
assert (pool.dead() == 0);
assert (pool.allocated() == pool.used() + pool.idle());
assert (pool.isActive());
pool.shutdown();
assert (!pool.isActive());
try
{
Session s7(pool.get());
@ -236,6 +238,10 @@ void SessionPoolTest::testSessionPoolContainer()
SessionPoolContainer spc;
AutoPtr<SessionPool> pPool = new SessionPool("TeSt", "Cs");
spc.add(pPool);
assert (pPool->isActive());
assert (spc.isActive("test", "cs"));
assert (spc.isActive("test:///cs"));
assert (spc.has("test:///cs"));
assert (1 == spc.count());
Poco::Data::Session sess = spc.get("test:///cs");
@ -245,7 +251,14 @@ void SessionPoolTest::testSessionPoolContainer()
try { spc.add(pPool); fail ("must fail"); }
catch (SessionPoolExistsException&) { }
pPool->shutdown();
assert (!pPool->isActive());
assert (!spc.isActive("test", "cs"));
assert (!spc.isActive("test:///cs"));
spc.remove(pPool->name());
assert (!spc.has("test:///cs"));
assert (!spc.isActive("test", "cs"));
assert (!spc.isActive("test:///cs"));
assert (0 == spc.count());
try { spc.get("test"); fail ("must fail"); }
catch (NotFoundException&) { }