Skip to content
Snippets Groups Projects
Commit 8000709c authored by Marco De Marco's avatar Marco De Marco
Browse files

Before protocol manager refactoring

parent 290b5392
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,7 @@ Client::~Client() ...@@ -38,7 +38,7 @@ Client::~Client()
if(m_thread_sp) if(m_thread_sp)
{ {
m_thread_sp->interrupt(); //m_thread_sp->interrupt();
m_thread_sp->join(); m_thread_sp->join();
} }
...@@ -82,7 +82,7 @@ void Client::stop() ...@@ -82,7 +82,7 @@ void Client::stop()
if(m_thread_sp) if(m_thread_sp)
{ {
m_thread_sp->interrupt(); //m_thread_sp->interrupt();
m_thread_sp->join(); m_thread_sp->join();
} }
...@@ -411,6 +411,8 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte ...@@ -411,6 +411,8 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte
{ {
WARN_STREAM << "Client::handleReadData() bad I/O" << endl; WARN_STREAM << "Client::handleReadData() bad I/O" << endl;
fileWrapper_sp->cleanUp();
onTransferFailed(); onTransferFailed();
} }
} }
......
...@@ -117,7 +117,7 @@ protected: ...@@ -117,7 +117,7 @@ protected:
const boost::system::error_code&); const boost::system::error_code&);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Transfer result methods // [Protected] Protocol and transfer result handler methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void onTransferCompleted(FileWrapper::SP); void onTransferCompleted(FileWrapper::SP);
......
...@@ -80,24 +80,36 @@ bool ProtocolManager::hasNextFile() ...@@ -80,24 +80,36 @@ bool ProtocolManager::hasNextFile()
m_recoveryMode = false; m_recoveryMode = false;
return true; return true;
} }
else if(m_failedFileRowset_sp &&
if(m_failedFileRowset_sp &&
m_failedFileRowsetIt != m_failedFileRowset_sp->end()) m_failedFileRowsetIt != m_failedFileRowset_sp->end())
{ {
DEBUG_STREAM << "ProtocolManager::hasNextFile() from failed list" << endl; boost::posix_time::ptime now(boost::posix_time::second_clock::local_time());
if(m_recoveryModeTime.is_not_a_date_time())
m_recoveryModeTime = now;
//FIXME: inhibition of retry for n seconds boost::posix_time::time_duration diff = now - m_recoveryModeTime;
if(diff.total_seconds() > 30)
{
DEBUG_STREAM << "ProtocolManager::hasNextFile() from failed list" << endl;
m_recoveryModeTime = now;
m_recoveryMode = true; m_recoveryMode = true;
return true; return true;
} }
else else
{ {
DEBUG_STREAM << "ProtocolManager::hasNextFile() "
<< "wait from failed list" << endl;
}
}
DEBUG_STREAM << "ProtocolManager::hasNextFile() lists empty" << endl; DEBUG_STREAM << "ProtocolManager::hasNextFile() lists empty" << endl;
m_recoveryMode = false; m_recoveryMode = false;
return false; return false;
} }
}
//============================================================================== //==============================================================================
// ProtocolManager::createRequest() // ProtocolManager::createRequest()
...@@ -280,6 +292,7 @@ void ProtocolManager::setFileTransfered(FileWrapper::SP fileWrapper_sp) ...@@ -280,6 +292,7 @@ void ProtocolManager::setFileTransfered(FileWrapper::SP fileWrapper_sp)
throw std::invalid_argument("Empty file name found on failed list"); throw std::invalid_argument("Empty file name found on failed list");
string fileName = m_failedFileRowsetIt->get<1>().get(); string fileName = m_failedFileRowsetIt->get<1>().get();
//FIXME: not incremented in case of exception!!!
++m_failedFileRowsetIt; ++m_failedFileRowsetIt;
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction(); DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
...@@ -315,9 +328,40 @@ void ProtocolManager::setFileFailed() throw(std::logic_error, std::runtime_error ...@@ -315,9 +328,40 @@ void ProtocolManager::setFileFailed() throw(std::logic_error, std::runtime_error
throw std::invalid_argument("Empty file name found on new list"); throw std::invalid_argument("Empty file name found on new list");
string fileName = m_newFileRowsetIt->get<1>().get(); string fileName = m_newFileRowsetIt->get<1>().get();
if(!m_newFileRowsetIt->get<2>())
throw std::invalid_argument("Empty update time found on new list");
std::tm currentTm = m_newFileRowsetIt->get<2>().get();
INFO_STREAM << "ProtocolManager::setFileFailed() file "
<< fileName << " version " << fileVersion << " transfered" << endl;
boost::posix_time::ptime currentPtime =
boost::posix_time::ptime_from_tm(currentTm);
boost::posix_time::ptime nextPtime(boost::posix_time::pos_infin);
//FIXME: not incremented in case of exception!!!
++m_newFileRowsetIt; ++m_newFileRowsetIt;
if(m_newFileRowsetIt != m_newFileRowset_sp->end())
{
if(!m_newFileRowsetIt->get<2>())
throw std::invalid_argument("Empty next update time found on new list");
std::tm nextTm = m_newFileRowsetIt->get<2>().get();
nextPtime =boost::posix_time::ptime_from_tm(nextTm);
}
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction();
if(nextPtime > currentPtime)
m_dBManager_sp->persistLastTimestamp(currentPtime);
m_dBManager_sp->addFailedFile(fileVersion, fileName); m_dBManager_sp->addFailedFile(fileVersion, fileName);
auxTransaction_sp->commit();
mainTransaction_sp->commit();
} }
else else
{ {
......
...@@ -97,9 +97,12 @@ protected: ...@@ -97,9 +97,12 @@ protected:
//Address and port of remote endpoint //Address and port of remote endpoint
std::string m_remoteEndpoint; std::string m_remoteEndpoint;
//Processing file from recovery list //Processing file from failed list
bool m_recoveryMode; bool m_recoveryMode;
//Processing file from failed list last timestamp
boost::posix_time::ptime m_recoveryModeTime;
//New file list shared pointer //New file list shared pointer
DBManager::NewFileRowsetSP m_newFileRowset_sp; DBManager::NewFileRowsetSP m_newFileRowset_sp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment