mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-11 02:25:59 +01:00
enh(MongoDB): connect to server in pool activateObject.
This commit is contained in:
@@ -70,7 +70,16 @@ public:
|
|||||||
|
|
||||||
void activateObject(MongoDB::ReplicaSetConnection::Ptr pObject)
|
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)
|
void deactivateObject(MongoDB::ReplicaSetConnection::Ptr pObject)
|
||||||
|
|||||||
@@ -27,14 +27,10 @@ namespace Poco {
|
|||||||
namespace MongoDB {
|
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)
|
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():
|
Connection::Connection() = default;
|
||||||
_address(),
|
|
||||||
_socket()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Connection::Connection(const std::string& hostAndPort):
|
Connection::Connection(const std::string& hostAndPort):
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ Net::SocketAddress ReplicaSetConnection::address() const
|
|||||||
{
|
{
|
||||||
if (_connection.isNull())
|
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();
|
return _connection->address();
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ Connection& ReplicaSetConnection::connection()
|
|||||||
{
|
{
|
||||||
if (_connection.isNull())
|
if (_connection.isNull())
|
||||||
{
|
{
|
||||||
throw Poco::NullPointerException("Not connected to any server");
|
throw Poco::NullPointerException("Not connected to any server: connection not available.");
|
||||||
}
|
}
|
||||||
return *_connection;
|
return *_connection;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user