Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

CVS update of carob (include/Connection.hpp src/Connection.cpp): msg#00032

db.carob.cvs

Subject: CVS update of carob (include/Connection.hpp src/Connection.cpp)

Date: Thursday, February 9, 2006 @ 15:50:12
Author: gilles
Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.53 -> 1.54) src/Connection.cpp (1.59
-> 1.60)

Remember connection parameters
Replaced (int) by static_cast
Added reconnect() declaration and started implem (only reconnects to the same
controller for now)


------------------------+
include/Connection.hpp | 20 ++++++++++---
src/Connection.cpp | 68 ++++++++++++++++++++++++++++++++++-------------
2 files changed, 65 insertions(+), 23 deletions(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.53 carob/include/Connection.hpp:1.54
--- carob/include/Connection.hpp:1.53 Wed Jan 25 17:00:50 2006
+++ carob/include/Connection.hpp Thu Feb 9 15:50:12 2006
@@ -22,6 +22,7 @@
#ifndef _CONNECTION_H_
#define _CONNECTION_H_

+#include "ConnectionParameters.hpp"
#include "DriverResultSet.hpp"

#include "CriticalSection.hpp"
@@ -312,7 +313,6 @@
* Warning: this function only sends the connection infos, but there is no
* guaranty that we are connected afterwards. {@link #finalizeConnect()} will
* do the job of checking and finishing connection establishment.
- * @param cp parameters of the connection
* @return true if the connection initialization succeeds
* @throw DriverException if the connect policy is NULL
* @throw ConnectionException if the requested controller could not be
@@ -321,12 +321,12 @@
* IO exception occured during authentication (premature close of
* connection)
*/
- bool initConnection(const ConnectionParameters& cp)
+ bool initConnection()
throw (DriverException, ConnectionException,
AuthenticationException, UnexpectedException);
/**
* Reads the controller acknowledgements and misc parameters that finish
- * connection. {@link #initConnection(const ConnectionParameters&)} must be
+ * connection. {@link #initConnection()} must be
* called before this
* @return true upon successfull connection
* @throw ConnectionException if the virtual database is not available on the
@@ -399,9 +399,10 @@

/** Persistent connection identifier if persistentConnection is true */
int64_t persistent_connection_id;
- /**
- * Controller connection policy used for this connection */
+ /** Controller connection policy used for this connection */
AbstractControllerConnectPolicy* connect_policy_ptr;
+ /** The parameters of this connection */
+ ConnectionParameters parameters;
/**
* List of pointers to the [parameter]statements created by this connection.
* Kept in order to destroy them when closing connection
@@ -534,6 +535,15 @@
ControllerException, ProtocolException,
UnexpectedException);
/**
+ * Tries first to reconnect to the same controller. If unsuccessfull,
notifies
+ * the suspicion of failure for the current controller and reconnects to a
+ * controller chosen using the policy specified in the connection parameters
+ * of this connection.
+ *
+ * @throw //TODO
+ */
+ void reconnect() throw (UnexpectedException);
+ /**
* Forbids Connection creation that would lead to unexpected state.
* A connection is either created, ie. connected to a controller or destroyed
* @see #Connection(const ConnectionParameters&)
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.59 carob/src/Connection.cpp:1.60
--- carob/src/Connection.cpp:1.59 Tue Jan 24 18:54:51 2006
+++ carob/src/Connection.cpp Thu Feb 9 15:50:12 2006
@@ -45,23 +45,24 @@
writeExecutedInTransaction(false),
mustBeginTransaction(false),
persistent_connection(false),
- connect_policy_ptr(NULL)
+ connect_policy_ptr(NULL),
+ parameters(prms)
{
wstring fctName(L"Connection::Connection");
- switch (prms.getConnectPolicy())
+ switch (parameters.getConnectPolicy())
{
case ROUND_ROBIN:
- connect_policy_ptr = new
RoundRobinConnectPolicy(prms.getControllerList(),
-
prms.getRetryInterval());
+ connect_policy_ptr = new
RoundRobinConnectPolicy(parameters.getControllerList(),
+
parameters.getRetryInterval());
break;
default:
- throw DriverException(L"Unsupported connection policy #" +
toWString(prms.getConnectPolicy()));
+ throw DriverException(L"Unsupported connection policy #" +
toWString(parameters.getConnectPolicy()));
}
- persistent_connection = prms.getPersistentConnection();
+ persistent_connection = parameters.getPersistentConnection();
try
{
//Do the authentication stuff, then receive ack and other params
- if (initConnection(prms) && finalizeConnect())
+ if (initConnection() && finalizeConnect())
{
if (isInfoEnabled())
logInfo(fctName, L"Connection succeded");
@@ -98,7 +99,7 @@
socket<<(int32_t)command;
}

-bool Connection::initConnection(const ConnectionParameters& prms)
+bool Connection::initConnection()
throw (DriverException, ConnectionException, AuthenticationException,
UnexpectedException)
{
@@ -114,7 +115,7 @@
{
wstring msg = L"Authenticating with controller "
+ controller.getHostName() + L":"
- + toWString((int)controller.getHostPort());
+ + toWString(static_cast<int>(controller.getHostPort()));
if (isInfoEnabled())
logInfo(fctName, msg);
}
@@ -123,24 +124,25 @@
//Here is the connection protocol...
// 1. connect to the controller
driverSocketPtr = new DriverSocket(controller.getHostName(),
- controller.getHostPort());
+ controller.getHostPort());
// 2. sent the Protocol version information
*driverSocketPtr<<ProtocolVersion;
protocolVersionSend = true;
// 3. send the database name
- *driverSocketPtr<<prms.getDatabaseName();
+ *driverSocketPtr<<parameters.getDatabaseName();
dbNameSend = true;
//TODO: See if we need a fflush here...
// 4. send user/pass
- *driverSocketPtr<<prms.getUserName();
+ *driverSocketPtr<<parameters.getUserName();
userNameSend = true;
- *driverSocketPtr<<prms.getUserPass();
+ *driverSocketPtr<<parameters.getUserPass();
userPassSend = true;
}
catch (ConnectionException connExcpt)
{
- wstring msg = L"Unable to connect to controller on " +
controller.getHostName()
- + L":" + toWString((int)controller.getHostPort())
+ wstring msg = L"Unable to connect to controller on "
+ + controller.getHostName()
+ + L":" +
toWString(static_cast<int>(controller.getHostPort()))
+ L" (" + connExcpt.description() + L").";
if (isErrorEnabled())
logError(fctName, msg);
@@ -150,7 +152,7 @@
catch (SocketIOException sockIOExcpt)
{
wstring msg = L"Could not authentify to " + controller.getHostName()
- + L":" + toWString((int)controller.getHostPort());
+ + L":" +
toWString(static_cast<int>(controller.getHostPort()));
if (!protocolVersionSend)
{
msg+=L". Error while sending protocol version ("
@@ -626,7 +628,7 @@
writeRequestOnStream(request);
request.setId(receiveLongOrException());
requestIdIsSet = true;
- controllerResponse = (int)receiveIntOrException();
+ controllerResponse = static_cast<int>(receiveIntOrException());
}
catch (SocketIOException sioe)
{
@@ -900,7 +902,7 @@
{
sendCommand(*driverSocketPtr, RetrieveExecuteUpdateResult);
*driverSocketPtr << request.getId();
- return (int)receiveIntOrException();
+ return static_cast<int>(receiveIntOrException());
}
std::list<ResultSetOrUpdateCount> Connection::retrieveExecuteResult(const
Request &request)
throw (SocketIOException, BackendException, ControllerException,
@@ -944,3 +946,33 @@
while (hasResult || resultReceived.updateCount != -1);
return results;
}
+
+void Connection::reconnect() throw (UnexpectedException)
+{
+ wstring fctName(L"Connection::reconnect");
+ //Wait until other methods/Commands are done
+ LockScope ls(&connectionCS);
+
+ // close everything
+ close();
+ // try to reconnect to the same 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;
+ }
+
+}
+
+


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | advertise | OSDir is an inevitable website. super tiny logo