diff options
author | Dan Goodliffe <randomdan@akira.random.lan> | 2014-11-29 16:43:25 +0000 |
---|---|---|
committer | Dan Goodliffe <randomdan@akira.random.lan> | 2014-11-29 16:43:25 +0000 |
commit | 8831f8aab0c049b494ba8c0dd8e6c5b45b747a74 (patch) | |
tree | ab08dd53d339ef10d0c9395d08c496af159040a4 | |
parent | Remove dependency on xml lib (functionality tested separately) (diff) | |
download | project2-8831f8aab0c049b494ba8c0dd8e6c5b45b747a74.tar.bz2 project2-8831f8aab0c049b494ba8c0dd8e6c5b45b747a74.tar.xz project2-8831f8aab0c049b494ba8c0dd8e6c5b45b747a74.zip |
Remove the continue on error options for plugables and add proper handling into implementations where errors can be ignored
-rw-r--r-- | project2/basics/caches/memoryCache.cpp | 2 | ||||
-rw-r--r-- | project2/basics/options/showHelp.h | 2 | ||||
-rw-r--r-- | project2/common/instanceStore.h | 4 | ||||
-rw-r--r-- | project2/common/instanceStore.impl.h | 26 | ||||
-rw-r--r-- | project2/common/library.cpp | 2 | ||||
-rw-r--r-- | project2/common/logger.h | 2 | ||||
-rw-r--r-- | project2/common/plugable.cpp | 4 | ||||
-rw-r--r-- | project2/common/plugable.h | 2 | ||||
-rw-r--r-- | project2/daemon/p2daemonAppEngine.cpp | 2 | ||||
-rw-r--r-- | project2/files/presenterCache.cpp | 18 | ||||
-rw-r--r-- | project2/json/couchSession.cpp | 16 | ||||
-rw-r--r-- | project2/sql/rdbmsDataSource.cpp | 6 | ||||
-rw-r--r-- | project2/sql/sqlCache.cpp | 25 | ||||
-rw-r--r-- | project2/xml/sessionXml.cpp | 29 | ||||
-rw-r--r-- | project2/xml/xmlCache.cpp | 9 | ||||
-rw-r--r-- | project2/xml/xmlDocumentCache.cpp | 2 |
16 files changed, 79 insertions, 72 deletions
diff --git a/project2/basics/caches/memoryCache.cpp b/project2/basics/caches/memoryCache.cpp index ee4f9b3..a69ca16 100644 --- a/project2/basics/caches/memoryCache.cpp +++ b/project2/basics/caches/memoryCache.cpp @@ -148,7 +148,7 @@ MemoryCache::CacheStore MemoryCache::Store; class CustomMemoryCacheLoader : public ElementLoader::For<MemoryCache> { public: - void onPeriodic() { + void onPeriodic() override { typedef MemoryCache::CacheStore::index<MemoryCache::IndexByTime>::type::iterator iter; iter x = MemoryCache::Store.get<MemoryCache::IndexByTime>().begin(); iter y = MemoryCache::Store.get<MemoryCache::IndexByTime>().upper_bound(time(NULL) - MemoryCache::CacheLife); diff --git a/project2/basics/options/showHelp.h b/project2/basics/options/showHelp.h index 21eec95..75fb4cb 100644 --- a/project2/basics/options/showHelp.h +++ b/project2/basics/options/showHelp.h @@ -6,7 +6,7 @@ class ShowHelpComponent : public ComponentLoader { public: - void onConfigLoad(); + void onConfigLoad() override; static Options::TargetPtr Option(); private: diff --git a/project2/common/instanceStore.h b/project2/common/instanceStore.h index 5557b43..9a669ef 100644 --- a/project2/common/instanceStore.h +++ b/project2/common/instanceStore.h @@ -37,7 +37,7 @@ class InstanceMap : public InstanceStore<Type, std::map<KeyType, boost::shared_p return safeMapLookup<E>(InstanceStore<Type, Store>::GetAll(), n); } - static void OnEach(const boost::function<void(const Value &)> & func, bool ContinueOnError = false); + static void OnEach(const boost::function<void(const Value &)> & func); }; /// Anonymous collection of instances @@ -45,7 +45,7 @@ template <class Type> class InstanceSet : public InstanceStore<Type, std::set<boost::shared_ptr<Type>>> { public: typedef InstanceStore<Type, std::set<boost::shared_ptr<Type>>> IStore; - static void OnAll(const boost::function<void(Type *)> & func, bool ContinueOnError = false); + static void OnAll(const boost::function<void(Type *)> & func); static void Remove(const boost::shared_ptr<Type> &); }; diff --git a/project2/common/instanceStore.impl.h b/project2/common/instanceStore.impl.h index 4152aba..dd64bd7 100644 --- a/project2/common/instanceStore.impl.h +++ b/project2/common/instanceStore.impl.h @@ -64,38 +64,20 @@ InstanceMap<Type, KeyType>::Remove(const KeyType & k) template <class Type, class KeyType> void -InstanceMap<Type, KeyType>::OnEach(const boost::function<void(const Value &)> & func, bool ContinueOnError) +InstanceMap<Type, KeyType>::OnEach(const boost::function<void(const Value &)> & func) { BOOST_FOREACH(const auto & l, IStore::GetAll()) { - if (ContinueOnError) { - try { - func(l); - } - catch (...) { - } - } - else { - func(l); - } + func(l); } IStore::prune(); } template <class Type> void -InstanceSet<Type>::OnAll(const boost::function<void(Type *)> & func, bool ContinueOnError) +InstanceSet<Type>::OnAll(const boost::function<void(Type *)> & func) { BOOST_FOREACH(const auto & l, IStore::GetAll()) { - if (ContinueOnError) { - try { - func(l.get()); - } - catch (...) { - } - } - else { - func(l.get()); - } + func(l.get()); } IStore::prune(); } diff --git a/project2/common/library.cpp b/project2/common/library.cpp index 0c4a83b..11dadb3 100644 --- a/project2/common/library.cpp +++ b/project2/common/library.cpp @@ -25,7 +25,7 @@ Library::~Library() STORAGEOF(Library) libraries; class LibraryLoader : public ElementLoader::For<Library> { public: - void onIteration() + void onIteration() override { libraries.clear(); } diff --git a/project2/common/logger.h b/project2/common/logger.h index cac35ad..7f6e7a0 100644 --- a/project2/common/logger.h +++ b/project2/common/logger.h @@ -73,7 +73,7 @@ class LogDriverLoaderImpl : public LogDriverLoader::For<LoggerType, LogDriverLoa level(LoggerType::level) { } - virtual void onConfigLoad() { + virtual void onConfigLoad() override { Logger()->setLoggerAt(this, level); if (level == -1) { instance.reset(); diff --git a/project2/common/plugable.cpp b/project2/common/plugable.cpp index 83d0cc5..969f530 100644 --- a/project2/common/plugable.cpp +++ b/project2/common/plugable.cpp @@ -1,8 +1,8 @@ #include "plugable.h" void -Plugable::onAllComponents(const boost::function<void(ComponentLoader *)> & func, bool coe) +Plugable::onAllComponents(const boost::function<void(ComponentLoader *)> & func) { - InstanceSet<ComponentLoader>::OnAll(func, coe); + InstanceSet<ComponentLoader>::OnAll(func); } diff --git a/project2/common/plugable.h b/project2/common/plugable.h index ce3439a..eaccd49 100644 --- a/project2/common/plugable.h +++ b/project2/common/plugable.h @@ -10,7 +10,7 @@ class ComponentLoader; class Plugable : public InstanceSet<ComponentLoader> { public: - static void onAllComponents(const boost::function<void(ComponentLoader *)> & func, bool coe = false); + static void onAllComponents(const boost::function<void(ComponentLoader *)> & func); }; /// All loaders, keyed by string, enum, int, etc diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp index 7a1c602..b48b75b 100644 --- a/project2/daemon/p2daemonAppEngine.cpp +++ b/project2/daemon/p2daemonAppEngine.cpp @@ -120,7 +120,7 @@ bool DaemonAppEngine::periodicCallback() { Logger()->messagebf(LOG_DEBUG, "%s: firing component periodics.", __PRETTY_FUNCTION__); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1), true); + Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1)); return true; } diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 09ee9ee..da63bf3 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -1,6 +1,7 @@ -#include "../common/presenterCache.h" -#include "../common/exceptions.h" -#include "../common/options.h" +#include "presenterCache.h" +#include "exceptions.h" +#include "logger.h" +#include "options.h" #include <safeMapFind.h> #include <fcntl.h> #include <attr/xattr.h> @@ -248,12 +249,17 @@ END_OPTIONS(FilePresenterCache) class FilePresenterCacheLoader : public ElementLoader::For<FilePresenterCache> { public: - void onIdle() + void onIdle() override { - emptyDir(FilePresenterCache::Store); + try { + emptyDir(FilePresenterCache::Store); + } + catch (...) { + Logger()->messagebf(LOG_WARNING, "Failed to purge presenter caches from %s", FilePresenterCache::Store); + } FilePresenterCache::openCaches.clear(); } - void onConfigLoad() + void onConfigLoad() override { FilePresenterCache::openCaches.clear(); } diff --git a/project2/json/couchSession.cpp b/project2/json/couchSession.cpp index ee7bad2..60acefa 100644 --- a/project2/json/couchSession.cpp +++ b/project2/json/couchSession.cpp @@ -2,8 +2,9 @@ #include "curlHelper.h" #include "safeMapFind.h" #include "exceptions.h" -#include "../libmisc/buffer.h" -#include "../libmisc/curlsup.h" +#include "logger.h" +#include "buffer.h" +#include "curlsup.h" #include <scriptLoader.h> #include <sessionContainer.h> #include <boost/bind.hpp> @@ -110,9 +111,14 @@ const Glib::ustring CouchSessionContainer::ExpiryKey("project2:expires"); class CustomCouchSessionLoader : public SessionContainerLoader::For<CouchSessionContainer> { public: - void onPeriodic() { - deleteSessions(); - compactDB(); + void onPeriodic() override { + try { + deleteSessions(); + compactDB(); + } + catch (...) { + Logger()->messagebf(LOG_WARNING, "Failed to purge expired sessions and compact DB"); + } } INITOPTIONS; diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index 7965a29..86c6a6e 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -13,7 +13,7 @@ SimpleMessageException(UnknownConnectionProvider); /// Specialized ElementLoader for instances of RdbmsDataSource; handles persistent DB connections class RdbmsDataSourceLoader : public ElementLoader::For<RdbmsDataSource> { public: - void onIdle() + void onIdle() override { // Disconnect all cached database connections RdbmsDataSource::dbhosts.clear(); @@ -22,7 +22,7 @@ class RdbmsDataSourceLoader : public ElementLoader::For<RdbmsDataSource> { { return con.second->isExpired(); } - void onPeriodic() + void onPeriodic() override { // Disconnect expired database connections RdbmsDataSource::DBHosts::iterator i; @@ -30,7 +30,7 @@ class RdbmsDataSourceLoader : public ElementLoader::For<RdbmsDataSource> { RdbmsDataSource::dbhosts.erase(i); } } - void onIteration() + void onIteration() override { RdbmsDataSource::changedDSNs.clear(); } diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp index c495528..f20bfe4 100644 --- a/project2/sql/sqlCache.cpp +++ b/project2/sql/sqlCache.cpp @@ -267,18 +267,21 @@ time_t SqlCache::CacheLife; class CustomSqlCacheLoader : public ElementLoader::For<SqlCache> { public: - void onIdle() + void onIdle() override { - if (!SqlCache::DataSource.empty()) { - boost::intrusive_ptr<CommonObjects> co = new CommonObjects(); - RdbmsDataSource * db = co->dataSource<RdbmsDataSource>(SqlCache::DataSource); - Buffer del; - del.appendf("DELETE FROM %s WHERE p2_time < ?", SqlCache::HeaderTable.c_str()); - auto con = db->getWritable(); - ModifyPtr m(con->newModifyCommand(del)); - m->bindParamT(0, boost::posix_time::microsec_clock::universal_time() - boost::posix_time::seconds(SqlCache::CacheLife)); - m->execute(); - db->commit(); + try { + if (!SqlCache::DataSource.empty()) { + boost::intrusive_ptr<CommonObjects> co = new CommonObjects(); + RdbmsDataSource * db = co->dataSource<RdbmsDataSource>(SqlCache::DataSource); + auto con = db->getWritable(); + ModifyPtr m(con->newModifyCommand(stringbf("DELETE FROM %s WHERE p2_time < ?", SqlCache::HeaderTable))); + m->bindParamT(0, boost::posix_time::microsec_clock::universal_time() - boost::posix_time::seconds(SqlCache::CacheLife)); + m->execute(); + db->commit(); + } + } + catch (...) { + Logger()->messagebf(LOG_WARNING, "Failed to purge expired caches from table %s", SqlCache::HeaderTable); } } }; diff --git a/project2/xml/sessionXml.cpp b/project2/xml/sessionXml.cpp index ff3beca..73bdccc 100644 --- a/project2/xml/sessionXml.cpp +++ b/project2/xml/sessionXml.cpp @@ -9,24 +9,28 @@ #include <boost/filesystem/convenience.hpp> #include <boost/lexical_cast.hpp> #include "options.h" +#include "logger.h" class CustomSessionContainerLoaderXml : public SessionContainerLoader::For<SessionContainerXml> { public: - void onBefore() + void onPeriodic() override { - boost::filesystem::create_directories(SessionContainerXml::xmlDir); - } - void onPeriodic() - { - boost::filesystem::directory_iterator end; - for (boost::filesystem::directory_iterator p(SessionContainerXml::xmlDir); p != end; ++p) { - xmlpp::DomParser session(p->path().string()); - xmlpp::Element * sess = session.get_document()->get_root_node(); - time_t expires = boost::lexical_cast<time_t>(sess->get_attribute_value("expires")); - if (expires < time(NULL)) { - boost::filesystem::remove(*p); + try { + if (boost::filesystem::is_directory(SessionContainerXml::xmlDir)) { + boost::filesystem::directory_iterator end; + for (boost::filesystem::directory_iterator p(SessionContainerXml::xmlDir); p != end; ++p) { + xmlpp::DomParser session(p->path().string()); + xmlpp::Element * sess = session.get_document()->get_root_node(); + time_t expires = boost::lexical_cast<time_t>(sess->get_attribute_value("expires")); + if (expires < time(NULL)) { + boost::filesystem::remove(*p); + } + } } } + catch (...) { + Logger()->messagebf(LOG_WARNING, "Failed to purge expired sessions in %s", SessionContainerXml::xmlDir); + } } }; DECLARE_OPTIONS(SessionContainerXml, "Session XML options") @@ -60,6 +64,7 @@ SessionContainerXml::SaveSession(SessionPtr currentSession) const xmlpp::Element * sess = d.create_root_node("session"); sess->set_attribute("expires", boost::lexical_cast<Glib::ustring>(currentSession->ExpiryTime())); currentSession->ForeachValue(boost::bind(appendToXmlNode, sess, _1, _2)); + boost::filesystem::create_directories(SessionContainerXml::xmlDir); boost::filesystem::path p = xmlDir / boost::lexical_cast<std::string>(currentSession->ID()); d.write_to_file(p.string()); } diff --git a/project2/xml/xmlCache.cpp b/project2/xml/xmlCache.cpp index bfa9c91..d6e2e04 100644 --- a/project2/xml/xmlCache.cpp +++ b/project2/xml/xmlCache.cpp @@ -87,9 +87,14 @@ time_t XmlCache::CacheLife; class CustomXmlCacheLoader : public ElementLoader::For<XmlCache> { public: - void onIdle() + void onIdle() override { - emptyDir(XmlCache::Store); + try { + emptyDir(XmlCache::Store); + } + catch (...) { + Logger()->messagebf(LOG_WARNING, "Failed to purge caches from %s", XmlCache::Store); + } } bool emptyDir(const boost::filesystem::path & dir) diff --git a/project2/xml/xmlDocumentCache.cpp b/project2/xml/xmlDocumentCache.cpp index 52165fb..b0d850d 100644 --- a/project2/xml/xmlDocumentCache.cpp +++ b/project2/xml/xmlDocumentCache.cpp @@ -109,7 +109,7 @@ class XmlDocumentCacheClearer : public ComponentLoader { public: typedef bool KeyType; - void onIteration() + void onIteration() override { Logger()->messagef(LOG_DEBUG, "%s: Clearing XML document cache", __PRETTY_FUNCTION__); XmlDocumentCache::documents.clear(); |