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/src (Connection.cpp): msg#00068

db.carob.cvs

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

Date: Tuesday, February 21, 2006 @ 17:51:43
Author: gilles
Path: /cvsroot/carob/carob/src

Modified: Connection.cpp (1.68 -> 1.69)

controller retrieval transfered from initConnection to constructor so we can
call initConnection from reconnect()
moved isClosed=true at beginning of close() function to have it set even if an
exception is thrown
fixed statementExecuteXXX logging
fixed statementExecute() & statementExecuteUpdateWithKeys() sanity checks so
they are not done at each reconnection anymore
fixed problem in reconnect(): don't delete connection policy anymore in here


----------------+
Connection.cpp | 92 ++++++++++++++++++++++++-------------------------------
1 files changed, 41 insertions(+), 51 deletions(-)


Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.68 carob/src/Connection.cpp:1.69
--- carob/src/Connection.cpp:1.68 Fri Feb 17 17:15:45 2006
+++ carob/src/Connection.cpp Tue Feb 21 17:51:43 2006
@@ -87,6 +87,10 @@
persistent_connection = parameters.getPersistentConnection();
try
{
+ if (connect_policy_ptr == NULL)
+ throw DriverException(L"Connection policy error. Aborting.");
+ connected_controller = connect_policy_ptr->getController();
+
//Do the authentication stuff, then receive ack and other params
if (initConnection() && finalizeConnect())
{
@@ -132,17 +136,10 @@
dbNameSend = false,
userNameSend = false,
userPassSend = false;
- if (connect_policy_ptr == NULL)
- throw DriverException(L"Connection policy error. Aborting.");
- connected_controller = connect_policy_ptr->getController();
if (isInfoEnabled())
- {
- wstring msg = L"Authenticating with controller "
+ logInfo(fctName, L"Authenticating with controller "
+ connected_controller.getHostName() + L":"
- +
toWString(static_cast<int>(connected_controller.getHostPort()));
- if (isInfoEnabled())
- logInfo(fctName, msg);
- }
+ +
toWString(static_cast<int>(connected_controller.getHostPort())));
try
{
//Here is the connection protocol...
@@ -312,6 +309,7 @@
//Wait until other methods/Commands are done
LockScope ls(&connectionCS);

+ isClosed = true;
//delete all statement created by this connection
for (std::list<Statement*>::iterator iter = created_statements.begin();
iter != created_statements.end(); iter++)
@@ -324,35 +322,34 @@
{
return false;
}
-
+ bool closeOK = false;
+ if (isDebugEnabled())
+ logDebug(fctName, L"Closing connection");
try
{
- if (driverSocketPtr != NULL)
- {
- if (isDebugEnabled())
- logDebug(fctName, L"Closing connection");
-
- sendCommand(*driverSocketPtr, Close);
-
- isClosed = true;
- bool closeOK;
- closeOK = receiveBoolOrException();
-
- //now close the socket itself
- closeOK &= driverSocketPtr->closeSocket();
-
- return closeOK;
- }
+ // Try to cleanly close the connection (also on controller side)
+ sendCommand(*driverSocketPtr, Close);
+ closeOK = receiveBoolOrException();
+ }
+ catch (...)
+ {
+ if (isWarnEnabled())
+ logWarn(fctName, L"Could not warn controller we are closing connection");
+ }
+ try
+ {
+ //now close the socket itself
+ closeOK &= driverSocketPtr->closeSocket();
+ return closeOK;
}
//catch any exception, log an error and return false (no exception forward)
catch (...)
{
- if (isErrorEnabled())
+ if (isWarnEnabled())
{
- logError(fctName, L"Exception while closing connection");
+ logWarn(fctName, L"Caught exception while closing connection");
}
//Don't re-throw = transparent closing
- return false;
}
return false;
}
@@ -604,17 +601,13 @@
DriverResultSet* retVal = NULL;

FO_TRY_NTIMES(RECONNECT_RETRIES)
-
setConnectionParametersOnRequest(request);
+ if (isDebugEnabled())
+ logDebug(fctName, L"Sending read request " +
static_cast<wstring>(request));
sendCommand(*driverSocketPtr, StatementExecuteQuery);
request.sendToStream(*driverSocketPtr);
-
- if (isDebugEnabled())
- logDebug(fctName, L"Executing read request "
- + static_cast<wstring>(request));

retVal = receiveResultSet();
-
FO_CATCH_NTIMES
return retVal;
}
@@ -634,6 +627,8 @@

FO_TRY_NTIMES(RECONNECT_RETRIES)
setConnectionParametersOnRequest(request);
+ if (isDebugEnabled())
+ logDebug(fctName, L"Sending write request " +
static_cast<wstring>(request));
sendCommand(*driverSocketPtr, StatementExecuteUpdate);
writeRequestOnStream(request);
request.setId(receiveLongOrException());
@@ -662,20 +657,19 @@
wstring fctName(L"Connection::statementExecute");

LockScope ls(&connectionCS);
+ checkIfConnected();
+ beginTransactionIfNeeded();

std::list<ResultSetOrUpdateCount> results;

FO_TRY_NTIMES(RECONNECT_RETRIES)
- checkIfConnected();
- beginTransactionIfNeeded();
+ if (isDebugEnabled())
+ logDebug(fctName, L"Sending request " + static_cast<wstring>(request));
setConnectionParametersOnRequest(request);
if (!autoCommit)
writeExecutedInTransaction = true;
sendCommand(*driverSocketPtr, StatementExecute);
request.sendToStream(*driverSocketPtr);
- if (isDebugEnabled())
- logDebug(fctName, L"Executing Statement.execute("
- + static_cast<wstring>(request) + L")");
request.setId(receiveLongOrException());
FO_CATCH_NTIMES
try
@@ -713,19 +707,20 @@

LockScope ls(&connectionCS);

+ checkIfConnected();
+ beginTransactionIfNeeded();
+
std::list<ResultSetOrUpdateCount> result;
for (int failuresCnt=0; failuresCnt<RECONNECT_RETRIES; failuresCnt++)
{ // this for is in the case we were disconnected and the controller did not
// get the update request
FO_TRY_NTIMES(RECONNECT_RETRIES)
- checkIfConnected();
- beginTransactionIfNeeded();
setConnectionParametersOnRequest(request);
- sendCommand(*driverSocketPtr, StatementExecuteUpdateWithKeys);
- request.sendToStream(*driverSocketPtr);
if (isDebugEnabled())
logDebug(fctName, L"Executing write request with keys: "
+ static_cast<wstring>(request));
+ sendCommand(*driverSocketPtr, StatementExecuteUpdateWithKeys);
+ request.sendToStream(*driverSocketPtr);
request.setId(receiveLongOrException());
FO_CATCH_NTIMES
try
@@ -792,10 +787,8 @@
*driverSocketPtr<<cursorName;
*driverSocketPtr<<fetchSize;
if (isDebugEnabled())
- {
logDebug(fctName, L"Fetching next " + toWString(fetchSize) + L" from "
+ cursorName);
- }
TypeTag tag(*driverSocketPtr);

if (tag == TT_EXCEPTION)
@@ -1066,16 +1059,13 @@
if (initConnection() && finalizeConnect())
{
if (isInfoEnabled())
- logInfo(fctName, L"Connection succeded");
+ logInfo(fctName, L"Reconnection to the same controller succeded");
isClosed = false;
}
}
catch (...)
- {
- //Do some clean up: we are in constructor so if we throw an exception,
the
- //destructor will never be called...
+ { //ignore but detroy socket if created
delete driverSocketPtr; driverSocketPtr = NULL;
- delete connect_policy_ptr; connect_policy_ptr = NULL;
}
}
if (isClosed)


<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