Date: Friday, February 10, 2006 @ 09:49:49
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.54 -> 1.55) src/Connection.cpp (1.60
          -> 1.61)

Remember controller we are connected to (so reconnect() can suspect the 
controller)
Implemented full reconnect


------------------------+
 include/Connection.hpp |    4 ++
 src/Connection.cpp     |   70 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 56 insertions(+), 18 deletions(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.54 carob/include/Connection.hpp:1.55
--- carob/include/Connection.hpp:1.54   Thu Feb  9 15:50:12 2006
+++ carob/include/Connection.hpp        Fri Feb 10 09:49:49 2006
@@ -403,6 +403,8 @@
   AbstractControllerConnectPolicy* connect_policy_ptr;
   /** The parameters of this connection */
   ConnectionParameters parameters;
+  /** The controller we are connected to */
+  ControllerInfo      connected_controller;
   /**
    * List of pointers to the [parameter]statements created by this connection.
    * Kept in order to destroy them when closing connection
@@ -542,7 +544,7 @@
    * 
    * @throw //TODO
    */
-  void reconnect() throw (UnexpectedException);
+  void reconnect() throw (NoMoreControllerException, UnexpectedException);
   /**
    * Forbids Connection creation that would lead to unexpected state.
    * A connection is either created, ie. connected to a controller or destroyed
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.60 carob/src/Connection.cpp:1.61
--- carob/src/Connection.cpp:1.60       Thu Feb  9 15:50:12 2006
+++ carob/src/Connection.cpp    Fri Feb 10 09:49:49 2006
@@ -110,12 +110,12 @@
         userPassSend = false;
   if (connect_policy_ptr == NULL)
     throw DriverException(L"Connection policy error. Aborting.");
-  ControllerInfo controller = connect_policy_ptr->getController();
+  connected_controller = connect_policy_ptr->getController();
   if (isInfoEnabled())
   {
     wstring msg = L"Authenticating with controller "
-                      + controller.getHostName() + L":"
-                      + toWString(static_cast<int>(controller.getHostPort()));
+                      + connected_controller.getHostName() + L":"
+                      + 
toWString(static_cast<int>(connected_controller.getHostPort()));
     if (isInfoEnabled())
       logInfo(fctName, msg);
   }
@@ -123,8 +123,8 @@
   {
     //Here is the connection protocol...
     // 1. connect to the controller
-    driverSocketPtr = new DriverSocket(controller.getHostName(),
-                                       controller.getHostPort());
+    driverSocketPtr = new DriverSocket(connected_controller.getHostName(),
+                                       connected_controller.getHostPort());
     // 2. sent the Protocol version information
     *driverSocketPtr<<ProtocolVersion;
     protocolVersionSend = true;
@@ -141,8 +141,8 @@
   catch (ConnectionException connExcpt)
   {
     wstring msg = L"Unable to connect to controller on "
-                  + controller.getHostName()
-                  + L":" + 
toWString(static_cast<int>(controller.getHostPort()))
+                  + connected_controller.getHostName()
+                  + L":" + 
toWString(static_cast<int>(connected_controller.getHostPort()))
                   + L" (" + connExcpt.description() + L").";
     if (isErrorEnabled())
       logError(fctName, msg);
@@ -151,8 +151,8 @@
   }
   catch (SocketIOException sockIOExcpt)
   {
-    wstring msg = L"Could not authentify to " + controller.getHostName()
-                  + L":" + 
toWString(static_cast<int>(controller.getHostPort()));
+    wstring msg = L"Could not authentify to " + 
connected_controller.getHostName()
+                  + L":" + 
toWString(static_cast<int>(connected_controller.getHostPort()));
     if (!protocolVersionSend)
     {
       msg+=L". Error while sending protocol version ("
@@ -947,7 +947,7 @@
   return results;
 }
 
-void Connection::reconnect() throw (UnexpectedException)
+void Connection::reconnect() throw (NoMoreControllerException, 
UnexpectedException)
 {
   wstring fctName(L"Connection::reconnect");
   //Wait until other methods/Commands are done
@@ -955,9 +955,35 @@
 
   // close everything
   close();
-  // try to reconnect to the same controller
+
+  // try to reconnect to the same controller if it has never been suspected of
+  // failure before
+  if (!connect_policy_ptr->isSuspectedOfFailure(connected_controller))
+  {
+    try
+    {
+      if (initConnection() && finalizeConnect())
+      {
+        if (isInfoEnabled())
+          logInfo(fctName, L"Connection succeded");
+        isClosed = false;
+      }
+    }
+    catch (...)
+    {
+      //Do some clean up: we are in constructor so if we throw an exception, 
the
+      //destructor will never be called...
+      delete driverSocketPtr; driverSocketPtr = NULL;
+      delete connect_policy_ptr; connect_policy_ptr = NULL;
+    }
+  }
+  if (isClosed)
+  {
+    connect_policy_ptr->suspectControllerOfFailure(connected_controller);
+  }
   try
   {
+    connected_controller = connect_policy_ptr->getController();
     if (initConnection() && finalizeConnect())
     {
       if (isInfoEnabled())
@@ -965,14 +991,24 @@
       isClosed = false;
     }
   }
-  catch (...)
+  catch (AuthenticationException ae)
+  {
+    // Should not happen, this probably mean an inconsistency in controller
+    // configuration but safely ignore (see below)
+    wstring msg = L"Warning! Authentication exception received on connection 
retry, controller configuration might be inconsistent";
+    if (isWarningEnabled())
+      logWarning(fctName, msg);
+    throw DriverException(msg+ae.description());
+  }
+  catch (ConnectionException ce)
   {
-    //Do some clean up: we are in constructor so if we throw an exception, the
-    //destructor will never be called...
-    delete driverSocketPtr; driverSocketPtr = NULL;
-    delete connect_policy_ptr; connect_policy_ptr = NULL;
+    // Should not happen, this probably mean an inconsistency in controller
+    // configuration but safely ignore (see below)
+    wstring msg = L"Warning! Connection exception received on connection 
retry, controller configuration might be inconsistent";
+    if (isWarningEnabled())
+      logWarning(fctName, msg);
+    throw DriverException(msg+ce.description());
   }
-  
 }
 
 

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

Reply via email to