Date: Monday, February 26, 2007 @ 18:28:23
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/ConnectionParameters.hpp (1.33 -> 1.34)
          src/Connection.cpp (1.113 -> 1.114) src/ConnectionParameters.cpp
          (1.28 -> 1.29) src/ControllerPool.cpp (1.21 -> 1.22)

ControllerPool references are now handled by ConnectionParameters rather than 
by Connection
Added some debug info in ControllerPoolManager
Fixes CAROB-129


----------------------------------+
 include/ConnectionParameters.hpp |   26 ++++++++++++++++++++++----
 src/Connection.cpp               |    8 ++------
 src/ConnectionParameters.cpp     |   34 ++++++++++++++++++++++++++--------
 src/ControllerPool.cpp           |   10 ++++++++++
 4 files changed, 60 insertions(+), 18 deletions(-)


Index: carob/include/ConnectionParameters.hpp
diff -u carob/include/ConnectionParameters.hpp:1.33 
carob/include/ConnectionParameters.hpp:1.34
--- carob/include/ConnectionParameters.hpp:1.33 Tue Dec  5 12:06:09 2006
+++ carob/include/ConnectionParameters.hpp      Mon Feb 26 18:28:22 2007
@@ -83,8 +83,24 @@
                        bool                 persistentConnection = 
DEFAULT_CONNECTION_PERSISTENCY,
                        bool                 retrieveSQLWarnings = 
DEFAULT_RETRIEVE_SQL_WARNINGS)
                    throw (ConnectionException, UnexpectedException);
+  /**
+   * Copy contructor.
+   * Copies fields and adds a reference to the controller pool
+   *
+   * @param from instance to copy settings from
+   */
+  ConnectionParameters(const ConnectionParameters& from);
+  /**
+   * Destructor, frees the reference to the controller pool
+   */
        virtual ~ConnectionParameters();
   /**
+   * Assignement operator - does the same as copy constructor
+   * @param from instance to copy settings from
+   * @see ConnectionParameters(const ConnectionParameters& from)
+   */
+  ConnectionParameters& operator = (const ConnectionParameters& from);
+  /**
    * Validates database name. If invalid returns false and set param char to 
the
    * first invalid character.
    */
@@ -104,8 +120,6 @@
   int                 getPingDelayInMs();
   /** Gives the controller timeout in milliseconds */
   int                 getControllerTimeoutInMs();
-  /** Inform ControllerPoolManager that we don't need controller_pool anymore 
*/
-  void                releaseControllerPool();
   /** Tell whether the connection must remain persistent */
   bool                getPersistentConnection() const { return 
persistent_connections; }
   /** Whether the controller should retrieve SQL warnings */
@@ -121,8 +135,12 @@
   std::wstring        user_pass;
   /** Controller connection policy */
   ConnectPolicy       connect_policy;
-  /** Controller pool obtained from controller list and connect policy */
-  AbstractControllerPool* controller_pool;
+  /**
+   * Controller pool obtained from controller list and connect policy. This
+   * object is created lazily when function #getControllerPool() is called for
+   * the first time
+   */
+  AbstractControllerPool* controller_pool_ptr;
   /** Ping delay in milliseconds */
   int                 ping_delay_in_ms;
   /** Controller timeout in milliseconds */
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.113 carob/src/Connection.cpp:1.114
--- carob/src/Connection.cpp:1.113      Fri Feb  9 17:52:52 2007
+++ carob/src/Connection.cpp    Mon Feb 26 18:28:23 2007
@@ -127,7 +127,6 @@
 
     // Clean all: we are in constructor, destructor won't be called !
     delete driverSocketPtr; driverSocketPtr = NULL;
-    parameters.releaseControllerPool();
     throw;
   }
   catch (const std::exception& se)
@@ -135,7 +134,6 @@
     logFatal(fctName, StaticCodecs::fromASCII(se.what()));
 
     delete driverSocketPtr; driverSocketPtr = NULL;
-    parameters.releaseControllerPool();
     throw;
   }
   catch (...)
@@ -143,7 +141,6 @@
     logFatal(fctName, L"unknown exception type");
 
     delete driverSocketPtr; driverSocketPtr = NULL;
-    parameters.releaseControllerPool();
     throw;
   }
 
@@ -153,7 +150,6 @@
 {
   close();
   // driverSocketPtr is deleted in close()
-  parameters.releaseControllerPool();
 }
 
 void Connection::sendCommand(const DriverSocket& socket, int command)
@@ -234,7 +230,7 @@
     controller_pool.forceControllerDown(connected_controller);
     closeSocket();
     // Recurse until no more controller
-    connectToNextController();
+    return connectToNextController();
   }
   catch (SocketIOException sockIOExcpt)
   {
@@ -245,7 +241,7 @@
     controller_pool.forceControllerDown(connected_controller);
     closeSocket();
     // Recurse until no more controller
-    connectToNextController();
+    return connectToNextController();
   }
   catch (VirtualDatabaseUnavailableException vdbue)
   {
Index: carob/src/ConnectionParameters.cpp
diff -u carob/src/ConnectionParameters.cpp:1.28 
carob/src/ConnectionParameters.cpp:1.29
--- carob/src/ConnectionParameters.cpp:1.28     Tue Jan  9 20:55:38 2007
+++ carob/src/ConnectionParameters.cpp  Mon Feb 26 18:28:23 2007
@@ -57,6 +57,7 @@
     user_name(uname),
     user_pass(upass),
     connect_policy(cp),
+    controller_pool_ptr(NULL),
     ping_delay_in_ms(pingDelayInMs),
     controller_timeout_in_ms(controllerTimeoutInMs),
     persistent_connections(persistentConnections),
@@ -71,20 +72,37 @@
     controller_timeout_in_ms = DEFAULT_CONTROLLER_TIMEOUT;
 }
 
-ConnectionParameters::~ConnectionParameters()
-{
+ConnectionParameters::ConnectionParameters(const ConnectionParameters& from) :
+    controller_list(from.controller_list),
+    database_name(from.database_name),
+    user_name(from.user_name),
+    user_pass(from.user_pass),
+    connect_policy(from.connect_policy),
+    controller_pool_ptr(from.controller_pool_ptr),
+    ping_delay_in_ms(from.ping_delay_in_ms),
+    controller_timeout_in_ms(from.controller_timeout_in_ms),
+    persistent_connections(from.persistent_connections),
+    retrieve_sql_warnings(from.retrieve_sql_warnings)
+{
+  if (controller_pool_ptr != NULL)
+    // we are now pointing to the controller pool, so we have to add a 
reference
+    // to it via the controller pool manager
+    controller_pool_ptr = &ControllerPoolManager::getPool(controller_list,
+        connect_policy, ping_delay_in_ms, controller_timeout_in_ms);
 }
 
-AbstractControllerPool& ConnectionParameters::getControllerPool()
+ConnectionParameters::~ConnectionParameters()
 {
-  controller_pool = &ControllerPoolManager::getPool(controller_list,
-      connect_policy, ping_delay_in_ms, controller_timeout_in_ms);
-  return *controller_pool;
+  if (controller_pool_ptr != NULL)
+    ControllerPoolManager::freePool(controller_pool_ptr);
 }
 
-void ConnectionParameters::releaseControllerPool()
+AbstractControllerPool& ConnectionParameters::getControllerPool()
 {
-  ControllerPoolManager::freePool(controller_pool);
+  if (controller_pool_ptr == NULL)
+    controller_pool_ptr = &ControllerPoolManager::getPool(controller_list,
+        connect_policy, ping_delay_in_ms, controller_timeout_in_ms);
+  return *controller_pool_ptr;
 }
 
 const wstring& ConnectionParameters::checkDatabaseName(const wstring& dbname) 
const
Index: carob/src/ControllerPool.cpp
diff -u carob/src/ControllerPool.cpp:1.21 carob/src/ControllerPool.cpp:1.22
--- carob/src/ControllerPool.cpp:1.21   Mon Feb 12 18:53:30 2007
+++ carob/src/ControllerPool.cpp        Mon Feb 26 18:28:23 2007
@@ -281,6 +281,8 @@
     ConnectPolicy cp, int pingDelayInMs, int controllerTimeoutInMs)
     throw (DriverException, UnexpectedException)
 {
+  const wchar_t fctName[] = L"ControllerPoolManager::getPool()";
+
   // iterate through the list to find the wanted pool, if present
   PoolIndex idx;
   idx.controllers = ctrls;
@@ -292,6 +294,9 @@
       = pool_map.find(idx);
   if (pool != pool_map.end())
   {
+    if (isDebugEnabled())
+      logDebug(fctName, L"Reusing pool \""
+          + static_cast<wstring>(*(pool->second)) + L"\"");
     pool->second->addRef();
     return *(pool->second);
   }
@@ -307,6 +312,8 @@
   }
   new_pool->addRef();
   pool_map[idx] = static_cast<AbstractControllerPool*>(new_pool);
+  if (isDebugEnabled())
+    logDebug(fctName, L"Creating new pool \"" + 
static_cast<wstring>(*new_pool) + L"\"");
   return *new_pool;
 }
 
@@ -328,6 +335,9 @@
     {
       if (pool->removeRef() == 0)
       {
+        if (isDebugEnabled())
+          logDebug(fctName, L"No more references to pool \""
+              + static_cast<wstring>(*pool) + L"\" - deleting it");
         pool_map.erase(iter); // don't mind about iter, we won't use it anymore
         delete pool;
       }

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to