Change class access, better logging, trap reload errors.
authorScott Cantor <cantor.2@osu.edu>
Thu, 4 Jan 2007 02:52:11 +0000 (02:52 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 4 Jan 2007 02:52:11 +0000 (02:52 +0000)
xmltooling/util/ReloadableXMLFile.cpp
xmltooling/util/ReloadableXMLFile.h

index eaa5e92..30368ea 100644 (file)
@@ -158,12 +158,12 @@ pair<bool,DOMElement*> ReloadableXMLFile::load()
     }\r
     catch (XMLException& e) {\r
         auto_ptr_char msg(e.getMessage());\r
-        log.errorStream() << "Xerces error while loading resource (" << m_source << "): "\r
+        log.critStream() << "Xerces error while loading resource (" << m_source << "): "\r
             << msg.get() << CategoryStream::ENDLINE;\r
         throw XMLParserException(msg.get());\r
     }\r
-    catch (XMLToolingException& e) {\r
-        log.errorStream() << "error while loading configuration from ("\r
+    catch (exception& e) {\r
+        log.critStream() << "error while loading configuration from ("\r
             << (m_source.empty() ? "inline" : m_source) << "): " << e.what() << CategoryStream::ENDLINE;\r
         throw;\r
     }\r
@@ -202,6 +202,7 @@ Lockable* ReloadableXMLFile::lock()
 \r
         // Update the timestamp regardless. No point in repeatedly trying.\r
         m_filestamp=stat_buf.st_mtime;\r
+        Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").info("change detected, reloading local resource...");\r
     }\r
     else {\r
         if (isValid())\r
@@ -216,16 +217,21 @@ Lockable* ReloadableXMLFile::lock()
             m_lock->rdlock();\r
             return this;\r
         }\r
+        Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").info("local copy invalid, reloading remote resource...");\r
     }\r
     \r
     // Do this once...\r
-    do {\r
+    try {\r
         // At this point we're holding the write lock, so make sure we pop it.\r
         SharedLock lockwrap(m_lock,false);\r
         pair<bool,DOMElement*> ret=load();\r
         if (ret.first)\r
             ret.second->getOwnerDocument()->release();\r
-    } while(0);\r
+    } catch (exception& ex) {\r
+        Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").crit(\r
+            "maintaining existing configuration, error reloading resource (%s): %s", m_source.c_str(), ex.what()\r
+            );\r
+    }\r
     \r
     // If we made it here, the swap may or may not have worked, but we need to relock.\r
     m_lock->rdlock();\r
index 019f9b2..f150863 100644 (file)
@@ -61,14 +61,6 @@ namespace xmltooling {
             delete m_lock;
         }
 
-    public:
-        Lockable* lock();
-
-        void unlock() {
-            if (m_lock)
-                m_lock->unlock();
-        }
-
         /**
          * Loads configuration material.
          * 
@@ -90,12 +82,31 @@ namespace xmltooling {
             return true;
         }
 
-    private:
+        /** Root of the original DOM element passed into constructor. */
         const DOMElement* m_root;
-        bool m_local, m_validate;
+        
+        /** Indicates whether resources is local or remote. */
+        bool m_local;
+        
+        /** Use a validating parser when parsing XML. */
+        bool m_validate;
+        
+        /** Resource location, may be a local path or a URI. */
         std::string m_source;
+        
+        /** Last modification of local resource. */
         time_t m_filestamp;
+        
+        /** Shared lock for guarding reloads. */
         RWLock* m_lock;
+
+    public:
+        Lockable* lock();
+
+        void unlock() {
+            if (m_lock)
+                m_lock->unlock();
+        }
     };
 
 };