version 1.54, 2006/01/30 16:16:42
|
version 1.54.2.3, 2008/01/02 21:07:59
|
|
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
// NOCHKSRC |
|
|
#include "CIMClientRep.h" | #include "CIMClientRep.h" |
| |
// l10n | // l10n |
|
|
: | : |
MessageQueue(PEGASUS_QUEUENAME_CLIENT), | MessageQueue(PEGASUS_QUEUENAME_CLIENT), |
_timeoutMilliseconds(timeoutMilliseconds), | _timeoutMilliseconds(timeoutMilliseconds), |
_connected(false) |
_connected(false), |
|
_doReconnect(false) |
{ | { |
// | // |
// Create Monitor and HTTPConnector | // Create Monitor and HTTPConnector |
|
|
_connectHost, | _connectHost, |
_connectPortNumber, | _connectPortNumber, |
_connectSSLContext.get(), | _connectSSLContext.get(), |
|
_timeoutMilliseconds, |
responseDecoder.get())); | responseDecoder.get())); |
| |
// | // |
|
|
_requestEncoder->setDataStorePointer(&perfDataStore); | _requestEncoder->setDataStorePointer(&perfDataStore); |
_responseDecoder->setDataStorePointer(&perfDataStore); | _responseDecoder->setDataStorePointer(&perfDataStore); |
| |
|
_doReconnect = false; |
_connected = true; | _connected = true; |
|
_httpConnection->setSocketWriteTimeout(_timeoutMilliseconds/1000+1); |
} | } |
| |
void CIMClientRep::_disconnect() | void CIMClientRep::_disconnect() |
|
|
| |
_connected = false; | _connected = false; |
} | } |
} |
|
| |
void CIMClientRep::_reconnect() |
// Reconnect no longer applies |
{ |
_doReconnect = false; |
_disconnect(); |
|
_authenticator.clearReconnect(); |
// Let go of the cached request message if we have one |
_connect(); |
_authenticator.setRequestMessage(0); |
} | } |
| |
void CIMClientRep::connect( | void CIMClientRep::connect( |
|
|
const Uint32 expectedResponseMessageType | const Uint32 expectedResponseMessageType |
) | ) |
{ | { |
if (!_connected) |
if (!_connected && !_doReconnect) |
{ | { |
request.reset(); |
|
throw NotConnectedException(); | throw NotConnectedException(); |
} | } |
| |
|
if (_doReconnect) |
|
{ |
|
_connect(); |
|
_doReconnect = false; |
|
} |
|
|
String messageId = XmlWriter::getNextMessageId(); | String messageId = XmlWriter::getNextMessageId(); |
const_cast<String &>(request->messageId) = messageId; | const_cast<String &>(request->messageId) = messageId; |
| |
|
|
// Check to see if incoming queue has a message | // Check to see if incoming queue has a message |
// | // |
| |
Message* response = dequeue(); |
AutoPtr<Message> response(dequeue()); |
| |
if (response) |
if (response.get()) |
{ | { |
// Shouldn't be any more messages in our queue | // Shouldn't be any more messages in our queue |
PEGASUS_ASSERT(getCount() == 0); | PEGASUS_ASSERT(getCount() == 0); |
| |
// | // |
// Reconnect to reset the connection |
// Close the connection if response contained a "Connection: Close" |
// if Server response contained a Connection: Close Header |
// header (e.g. at authentication challenge) |
// | // |
if (response->getCloseConnect() == true){ |
if (response->getCloseConnect() == true) |
_reconnect(); |
{ |
|
_disconnect(); |
|
_doReconnect = true; |
response->setCloseConnect(false); | response->setCloseConnect(false); |
} | } |
| |
|
|
{ | { |
| |
Exception* clientException = | Exception* clientException = |
((ClientExceptionMessage*)response)->clientException; |
((ClientExceptionMessage*)response.get())->clientException; |
delete response; |
|
| |
AutoPtr<Exception> d(clientException); | AutoPtr<Exception> d(clientException); |
| |
|
|
} | } |
else if (response->getType() == expectedResponseMessageType) | else if (response->getType() == expectedResponseMessageType) |
{ | { |
CIMResponseMessage* cimResponse = (CIMResponseMessage*)response; |
CIMResponseMessage* cimResponse = |
|
(CIMResponseMessage*)response.get(); |
| |
if (cimResponse->messageId != messageId) | if (cimResponse->messageId != messageId) |
{ | { |
|
|
| |
CIMClientResponseException responseException(mlString); | CIMClientResponseException responseException(mlString); |
| |
delete response; |
|
throw responseException; | throw responseException; |
} | } |
| |
|
|
cimResponse->cimException.getCode(), | cimResponse->cimException.getCode(), |
cimResponse->cimException.getMessage()); | cimResponse->cimException.getMessage()); |
cimException.setContentLanguages(responseContentLanguages); | cimException.setContentLanguages(responseContentLanguages); |
delete response; |
|
throw cimException; | throw cimException; |
} | } |
| |
|
|
perfDataStore.handler_prt->handleClientOpPerformanceData(item); | perfDataStore.handler_prt->handleClientOpPerformanceData(item); |
| |
}//end of if statmet that call the callback method | }//end of if statmet that call the callback method |
return response; |
return response.release(); |
} | } |
else if (dynamic_cast<CIMRequestMessage*>(response) != 0) |
else if (dynamic_cast<CIMRequestMessage*>(response.get()) != 0) |
{ | { |
// Respond to an authentication challenge |
// |
_requestEncoder->enqueue(response); |
// Respond to an authentication challenge. |
|
// Reconnect if the connection was closed. |
|
// |
|
if (_doReconnect) |
|
{ |
|
_connect(); |
|
} |
|
|
|
_requestEncoder->enqueue(response.release()); |
nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); | nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); |
stopMilliseconds = nowMilliseconds + _timeoutMilliseconds; | stopMilliseconds = nowMilliseconds + _timeoutMilliseconds; |
continue; | continue; |
|
|
| |
CIMClientResponseException responseException(mlString); | CIMClientResponseException responseException(mlString); |
| |
delete response; |
|
throw responseException; | throw responseException; |
} | } |
} | } |
|
|
// | // |
// Reconnect to reset the connection (disregard late response) | // Reconnect to reset the connection (disregard late response) |
// | // |
try |
|
{ |
_disconnect(); |
_reconnect(); |
_authenticator.resetChallengeStatus(); |
} |
_doReconnect = true; |
catch (...) |
|
{ |
|
} |
|
| |
// | // |
// Throw timed out exception: | // Throw timed out exception: |