[rhmessaging-commits] rhmessaging commits: r4414 - in mgmt/trunk: rosemary/python/rosemary and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Nov 15 11:59:26 EST 2010


Author: tmckay
Date: 2010-11-15 11:59:25 -0500 (Mon, 15 Nov 2010)
New Revision: 4414

Modified:
   mgmt/trunk/mint/python/mint/update.py
   mgmt/trunk/rosemary/python/rosemary/model.py
Log:
Replaced obj._sync_time with two attributes, obj._save_time and obj._load_time to more explicitly track activity on an object.  Marked set_object_attributes() as an internal method (by "_" convention).  The new obj._save_time alleviates the need for obj_.last_write_time which was added to allow forced writes to the database after an interval.  jross and tmckay.



Modified: mgmt/trunk/mint/python/mint/update.py
===================================================================
--- mgmt/trunk/mint/python/mint/update.py	2010-11-12 19:53:20 UTC (rev 4413)
+++ mgmt/trunk/mint/python/mint/update.py	2010-11-15 16:59:25 UTC (rev 4414)
@@ -252,17 +252,6 @@
         if cls._package is self.model.org_apache_qpid_broker:
             self.maybe_drop_sample(obj)
 
-        # We want a time stamp that shows the last time an
-        # object was written through to the database.  If we see that
-        # updates are coming in, but an object is not being
-        # written through because values are the same,
-        # we want to force a write after a while.  This prevents
-        # objects from being filtered out in the UI.
-
-        # Initialize our tracking timestamp here if it does not yet exist.
-        if not hasattr(obj,"_last_write_time"):
-            obj._last_write_time = obj._qmf_update_time
-
         self.update_object(cursor, stats, obj)
 
     def get_agent_id(self):
@@ -352,7 +341,7 @@
 
         self.process_deferred_links(cursor, obj)
 
-        obj._sync_time = datetime.now()
+        obj._save_time = datetime.now()
 
         self.model.print_event(3, "Created %s", obj)
 
@@ -391,13 +380,13 @@
 
          # force a write if it's been too long, even if the values match
         if object_columns \
-                or obj._last_write_time < obj._qmf_update_time - timedelta(hours=1):
+                or obj._save_time < obj._qmf_update_time - timedelta(hours=1):
             object_columns.append(cls.sql_table._qmf_update_time)
 
             sql = cls.sql_update_object.emit(object_columns)
             statements.append(sql)
 
-            obj._last_write_time = obj._qmf_update_time
+            obj._save_time = datetime.now()
 
         if sample_columns:
             sample_columns.append(cls.sql_samples_table._qmf_update_time)
@@ -413,8 +402,6 @@
         sql = "; ".join(statements)
         self.execute_sql(cursor, sql, obj.__dict__)
 
-        obj._sync_time = datetime.now()
-
         self.model.print_event(4, "Updated %s", obj)
 
         stats.objects_updated += 1

Modified: mgmt/trunk/rosemary/python/rosemary/model.py
===================================================================
--- mgmt/trunk/rosemary/python/rosemary/model.py	2010-11-12 19:53:20 UTC (rev 4413)
+++ mgmt/trunk/rosemary/python/rosemary/model.py	2010-11-15 16:59:25 UTC (rev 4414)
@@ -350,7 +350,7 @@
 
         obj = RosemaryObject(self, None)
 
-        self.set_object_attributes(obj, self.sql_table._columns, record)
+        self._set_object_attributes(obj, self.sql_table._columns, record)
 
         return obj
 
@@ -369,7 +369,7 @@
         for record in cursor.fetchall():
             obj = RosemaryObject(self, None)
 
-            self.set_object_attributes(obj, self.sql_table._columns, record)
+            self._set_object_attributes(obj, self.sql_table._columns, record)
 
             selection.append(obj)
 
@@ -418,7 +418,7 @@
         if not values:
             raise RosemaryNotFound()
 
-        self.set_object_attributes(obj, self.sql_table._columns, values)
+        self._set_object_attributes(obj, self.sql_table._columns, values)
 
     def load_object_by_qmf_id(self, cursor, obj):
         assert isinstance(obj, RosemaryObject)
@@ -432,21 +432,21 @@
         if not values:
             raise RosemaryNotFound()
 
-        self.set_object_attributes(obj, self.sql_table._columns, values)
+        self._set_object_attributes(obj, self.sql_table._columns, values)
 
-    def set_object_attributes(self, obj, columns, values):
+    def _set_object_attributes(self, obj, columns, values):
         assert isinstance(obj, RosemaryObject)
 
         for column, value in zip(columns, values):
             setattr(obj, column.name, value)
 
-        obj._sync_time = datetime.now()
+        obj._load_time = datetime.now()
 
     def save_object(self, cursor, obj, columns=None):
         assert isinstance(obj, RosemaryObject)
         assert obj._id, obj
 
-        if obj._sync_time:
+        if obj._load_time or obj._save_time:
             sql = self.sql_update_object
         else:
             sql = self.sql_insert_object
@@ -456,7 +456,7 @@
 
         sql.execute(cursor, obj.__dict__, columns=columns)
 
-        obj._sync_time = datetime.now()
+        obj._save_time = datetime.now()
 
     def add_object_sample(self, cursor, obj, columns=None):
         assert isinstance(obj, RosemaryObject)
@@ -731,7 +731,8 @@
 
         self._class = cls
         self._id = id
-        self._sync_time = None
+        self._load_time = None
+        self._save_time = None
         self._sample_time = None
 
     # XXX prefix these with _
@@ -782,7 +783,7 @@
 
     def __repr__(self):
         name = self.__class__.__name__
-        args = (name, self._class, self._id, self._sync_time)
+        args = (name, self._class, self._id, self._save_time)
         return "%s(%s,%i,%s)" % args
 
 class RosemaryNotFound(Exception):



More information about the rhmessaging-commits mailing list