refs #476, improvements on gracefulShutdown

* gracefulShutdown in metar reader and other readers
* made m_shutdown thread safe
* Demoted log level for reader
* helper function finished or shutdown
This commit is contained in:
Klaus Basan
2015-11-07 18:51:10 +01:00
committed by Mathew Sutcliffe
parent 54448fd2b2
commit 4d3d9fa6be
8 changed files with 28 additions and 15 deletions

View File

@@ -37,7 +37,7 @@ namespace BlackCore
{ {
this->threadAssertCheck(); this->threadAssertCheck();
JsonDatastoreResponse datastoreResponse; JsonDatastoreResponse datastoreResponse;
if (m_shutdown || this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).info("Terminated data parsing process"); // for users CLogMessage(this).info("Terminated data parsing process"); // for users
nwReply->abort(); nwReply->abort();

View File

@@ -124,7 +124,7 @@ namespace BlackCore
QString replyMessage(nwReply->errorString()); QString replyMessage(nwReply->errorString());
this->threadAssertCheck(); this->threadAssertCheck();
if (this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO; CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated loading bootstrap files"); CLogMessage(this).info("Terminated loading bootstrap files");

View File

@@ -57,7 +57,7 @@ namespace BlackCore
this->threadAssertCheck(); this->threadAssertCheck();
// Worker thread, make sure to write no members here! // Worker thread, make sure to write no members here!
if (this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO; CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated booking parsing process"); // for users CLogMessage(this).info("terminated booking parsing process"); // for users
@@ -93,7 +93,7 @@ namespace BlackCore
CAtcStationList bookedStations; CAtcStationList bookedStations;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
if (this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO; CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated booking parsing process"); // for users CLogMessage(this).info("Terminated booking parsing process"); // for users

View File

@@ -173,7 +173,7 @@ namespace BlackCore
this->threadAssertCheck(); this->threadAssertCheck();
// Worker thread, make sure to write only synced here! // Worker thread, make sure to write only synced here!
if (this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO; CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users
@@ -200,9 +200,9 @@ namespace BlackCore
QStringList clientSectionAttributes; QStringList clientSectionAttributes;
Section section = SectionNone; Section section = SectionNone;
foreach(QString currentLine, lines) for (const QString &cl : lines)
{ {
if (this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO; CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated booking parsing process"); // for users CLogMessage(this).info("Terminated booking parsing process"); // for users
@@ -210,7 +210,7 @@ namespace BlackCore
} }
// parse lines // parse lines
currentLine = currentLine.trimmed(); QString currentLine(cl.trimmed());
if (currentLine.isEmpty()) continue; if (currentLine.isEmpty()) continue;
if (currentLine.startsWith(";")) if (currentLine.startsWith(";"))
{ {

View File

@@ -76,7 +76,7 @@ namespace BlackCore
this->threadAssertCheck(); this->threadAssertCheck();
// Worker thread, make sure to write thread safe! // Worker thread, make sure to write thread safe!
if (this->isFinished()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO; CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated METAR decoding process"); // for users CLogMessage(this).info("terminated METAR decoding process"); // for users
@@ -94,6 +94,7 @@ namespace BlackCore
QTextStream lineReader(&metarData); QTextStream lineReader(&metarData);
while (!lineReader.atEnd()) while (!lineReader.atEnd())
{ {
if (this->isFinishedOrShutdown()) { return; }
QString line = lineReader.readLine(); QString line = lineReader.readLine();
CMetar metar = m_metarDecoder.decode(line); CMetar metar = m_metarDecoder.decode(line);
if (metar != CMetar()) if (metar != CMetar())
@@ -117,7 +118,8 @@ namespace BlackCore
Q_UNUSED(invalidMetars); Q_UNUSED(invalidMetars);
if (invalidLineCount > 0) if (invalidLineCount > 0)
{ {
CLogMessage(this).warning("Reading METARs failed for %1 entries") << invalidLineCount; // Regular issue, log it, but do not show to user
CLogMessage(this).debug() << "Reading METARs failed for entries" << invalidLineCount;
} }
emit metarsRead(metars); emit metarsRead(metars);
emit dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFinished, metars.size()); emit dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFinished, metars.size());

View File

@@ -374,9 +374,10 @@ namespace BlackCore
this->disconnect(); // all signals this->disconnect(); // all signals
if (this->m_vatsimBookingReader) { this->m_vatsimBookingReader->gracefulShutdown(); } if (this->m_vatsimBookingReader) { this->m_vatsimBookingReader->gracefulShutdown(); }
if (this->m_vatsimDataFileReader) { this->m_vatsimDataFileReader->gracefulShutdown(); } if (this->m_vatsimDataFileReader) { this->m_vatsimDataFileReader->gracefulShutdown(); }
if (this->m_modelDataReader) { this->m_modelDataReader->gracefulShutdown(); } if (this->m_vatsimMetarReader) { this->m_vatsimMetarReader->gracefulShutdown(); }
if (this->m_icaoDataReader) { this->m_icaoDataReader->gracefulShutdown(); } if (this->m_modelDataReader) { this->m_modelDataReader->gracefulShutdown(); }
if (this->m_databaseWriter) { this->m_databaseWriter->gracefulShutdown(); } if (this->m_icaoDataReader) { this->m_icaoDataReader->gracefulShutdown(); }
if (this->m_databaseWriter) { this->m_databaseWriter->gracefulShutdown(); }
} }
const CLogCategoryList &CWebDataServices::getLogCategories() const CLogCategoryList &CWebDataServices::getLogCategories()

View File

@@ -19,6 +19,11 @@ namespace BlackMisc
m_updateTimer(new QTimer(this)) m_updateTimer(new QTimer(this))
{ } { }
bool CThreadedReader::isFinishedOrShutdown() const
{
return m_shutdown || isFinished();
}
QDateTime CThreadedReader::getUpdateTimestamp() const QDateTime CThreadedReader::getUpdateTimestamp() const
{ {
QReadLocker lock(&this->m_lock); QReadLocker lock(&this->m_lock);

View File

@@ -21,6 +21,7 @@
#include <QTimer> #include <QTimer>
#include <QNetworkReply> #include <QNetworkReply>
#include <QCoreApplication> #include <QCoreApplication>
#include <atomic>
namespace BlackMisc namespace BlackMisc
{ {
@@ -57,16 +58,20 @@ namespace BlackMisc
int interval() const; int interval() const;
//! Graceful shutdown //! Graceful shutdown
//! \threadsafe
void gracefulShutdown(); void gracefulShutdown();
protected: protected:
//! Constructor //! Constructor
CThreadedReader(QObject *owner, const QString &name); CThreadedReader(QObject *owner, const QString &name);
QTimer *m_updateTimer = nullptr; //!< update timer QTimer *m_updateTimer = nullptr; //!< update timer
bool m_shutdown = false; //!< in shutdown process std::atomic<bool> m_shutdown { false }; //!< in shutdown process
mutable QReadWriteLock m_lock {QReadWriteLock::Recursive}; //!< lock which can be used from the derived classes mutable QReadWriteLock m_lock {QReadWriteLock::Recursive}; //!< lock which can be used from the derived classes
//! Shutdown in progress or finished
bool isFinishedOrShutdown() const;
//! Make sure everthing runs correctly in own thread //! Make sure everthing runs correctly in own thread
void threadAssertCheck() const; void threadAssertCheck() const;