// create a unique id and look for it in our map
Sequence< PropertyValue > aInfo(_rInfo);
TConnectionMap::key_type nId;
OConnectionWrapper::createUniqueId(_rURL,aInfo,nId.m_pBuffer);
TConnectionMap::iterator aIter = m_aPool.find(nId);
if ( m_aPool.end() != aIter )
xConnection = getPooledConnection(aIter);
if ( !xConnection.is() )
xConnection = createNewConnection(_rURL,_rInfo);
return xConnection;
}
void SAL_CALL OConnectionPool::disposing( const css::lang::EventObject& Source )
{
Reference<XConnection> xConnection(Source.Source,UNO_QUERY); if(xConnection.is())
{
std::unique_lock aGuard(m_aMutex);
TActiveConnectionMap::iterator aIter = m_aActiveConnections.find(xConnection);
OSL_ENSURE(aIter != m_aActiveConnections.end(),"OConnectionPool::disposing: Connection wasn't in pool"); if(aIter != m_aActiveConnections.end())
{ // move the pooled connection back to the pool
aIter->second.aPos->second.nALiveCount = m_nALiveCount;
aIter->second.aPos->second.aConnections.push_back(aIter->second.xPooledConnection);
m_aActiveConnections.erase(aIter);
}
} else
{
m_xDriverNode.clear();
}
}
Reference< XConnection> OConnectionPool::createNewConnection(const OUString& _rURL,const Sequence< PropertyValue >& _rInfo)
{ // create new pooled connection
Reference< XPooledConnection > xPooledConnection = new ::connectivity::OPooledConnection(m_xDriver->connect(_rURL,_rInfo),m_xProxyFactory); // get the new connection from the pooled connection
Reference<XConnection> xConnection = xPooledConnection->getConnection(); if(xConnection.is())
{ // add our own as dispose listener to know when we should put the connection back to the pool
Reference< XComponent > xComponent(xConnection, UNO_QUERY); if (xComponent.is())
xComponent->addEventListener(this);
// save some information to find the right pool later on
Sequence< PropertyValue > aInfo(_rInfo);
TConnectionMap::key_type nId;
OConnectionWrapper::createUniqueId(_rURL,aInfo,nId.m_pBuffer);
TConnectionPool aPack;
// insert the new connection and struct into the active connection map
aPack.nALiveCount = m_nALiveCount;
TActiveConnectionInfo aActiveInfo;
aActiveInfo.aPos = m_aPool.emplace(nId,aPack).first;
aActiveInfo.xPooledConnection = std::move(xPooledConnection);
m_aActiveConnections.emplace(xConnection,aActiveInfo);
// look if the iterator aIter is still present in the active connection map bool isPresent = std::any_of(m_aActiveConnections.begin(), m_aActiveConnections.end(),
[&aIter](const TActiveConnectionMap::value_type& rEntry) { returnrEntry.second.aPos == aIter; }); if(!isPresent)
{// he isn't so we can delete him
aIter = m_aPool.erase(aIter);
} else
++aIter;
} else
++aIter;
} if(!m_aPool.empty())
m_xInvalidator->start();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.