enh(MongoDB): connect to server in pool activateObject.

This commit is contained in:
Matej Kenda
2025-12-03 10:59:34 +01:00
parent 0e7252b193
commit 0411455ef0
3 changed files with 15 additions and 14 deletions

View File

@@ -70,7 +70,16 @@ public:
void activateObject(MongoDB::ReplicaSetConnection::Ptr pObject)
{
// No action needed - connection is established lazily
if (!pObject->isConnected())
{
try {
pObject->reconnect();
}
catch (Poco::Exception& e)
{
// Ignore connect error. c->isConnected() can be used to determine if the connection is valid.
}
}
}
void deactivateObject(MongoDB::ReplicaSetConnection::Ptr pObject)

View File

@@ -27,14 +27,10 @@ namespace Poco {
namespace MongoDB {
Connection::SocketFactory::SocketFactory()
{
}
Connection::SocketFactory::SocketFactory() = default;
Connection::SocketFactory::~SocketFactory()
{
}
Connection::SocketFactory::~SocketFactory() = default;
Poco::Net::StreamSocket Connection::SocketFactory::createSocket(const std::string& host, int port, Poco::Timespan connectTimeout, bool secure)
@@ -53,11 +49,7 @@ Poco::Net::StreamSocket Connection::SocketFactory::createSocket(const std::strin
}
Connection::Connection():
_address(),
_socket()
{
}
Connection::Connection() = default;
Connection::Connection(const std::string& hostAndPort):

View File

@@ -86,7 +86,7 @@ Net::SocketAddress ReplicaSetConnection::address() const
{
if (_connection.isNull())
{
throw Poco::NullPointerException("Not connected to any server");
throw Poco::NullPointerException("Not connected to any server: address not available.");
}
return _connection->address();
}
@@ -96,7 +96,7 @@ Connection& ReplicaSetConnection::connection()
{
if (_connection.isNull())
{
throw Poco::NullPointerException("Not connected to any server");
throw Poco::NullPointerException("Not connected to any server: connection not available.");
}
return *_connection;
}