Title: [commits] (vajda) [11189] - removed support for unused persistent collection queue subscriptions
Revision
11189
Author
vajda
Date
2006-07-18 12:24:59 -0700 (Tue, 18 Jul 2006)

Log Message

- removed support for unused persistent collection queue subscriptions
- refactored transient collection queue subscriptions to use watchers
- renamed view.notificationQueueSubscribe() to view.watchCollectionQueue()
- upgraded build to chandlerdb 0.6-32

Modified Paths

Removed Paths

Diff

Modified: trunk/chandler/Makefile (11188 => 11189)

--- trunk/chandler/Makefile	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/Makefile	2006-07-18 19:24:59 UTC (rev 11189)
@@ -66,7 +66,7 @@
 
 # these get installed into release or debug
 ARCHIVES=$(CHANDLERARCHIVES)/Launchers-$(SNAP)-0.8-$(BP)8.tar.gz \
-         $(CHANDLERARCHIVES)/chandlerdb-$(SNAP)-0.6-$(BP)31.tar.gz \
+         $(CHANDLERARCHIVES)/chandlerdb-$(SNAP)-0.6-$(BP)32.tar.gz \
          $(CHANDLERARCHIVES)/db-$(SNAP)-4.4.20-$(BP)5.tar.gz \
          $(CHANDLERARCHIVES)/python-$(SNAP)-2.4.3-$(BP)3.tar.gz \
          $(CHANDLERARCHIVES)/epydoc-$(SNAP)-2.1-$(BP)9.tar.gz \

Modified: trunk/chandler/application/Application.py (11188 => 11189)

--- trunk/chandler/application/Application.py	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/application/Application.py	2006-07-18 19:24:59 UTC (rev 11189)
@@ -561,10 +561,13 @@
         mainViewRoot = self.mainFrame.mainViewRoot.unRender()
         if __debug__:
             from osaf.framework.blocks.Block import Block
-            for value in self.UIRepositoryView._subscribers.itervalues():
-                for uuid in value:
-                    item = self.UIRepositoryView.findUUID(uuid)
-                    assert not isinstance (item, Block)
+            view = self.UIRepositoryView
+            for uWatched, watchers in view._watchers.iteritems():
+                watchers = watchers.get(view.SUBSCRIBERS)
+                if watchers:
+                    for watcher in watchers:
+                        item = view.findUUID(watcher.watchingItem)
+                        assert not isinstance(item, Block)
             
         self.mainFrame.SetSizer (None)
 

Modified: trunk/chandler/parcels/osaf/framework/blocks/Block.py (11188 => 11189)

--- trunk/chandler/parcels/osaf/framework/blocks/Block.py	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/parcels/osaf/framework/blocks/Block.py	2006-07-18 19:24:59 UTC (rev 11189)
@@ -90,11 +90,6 @@
     contents = schema.One(ContentItem, otherName="contentsOwner")
     contentsCollection = schema.One(ContentItem, defaultValue=None)
 
-    # Must be provided in order to subcribe to collection notifications.
-    # In order to subscribe to more than one collection, this attribute
-    # should be declared with schema.Sequence().
-    subscribesTo = schema.One(ContentCollection, otherName="subscribers")
-
     # Blocks instances can be put into ListCollections or AppCollections
     collections = schema.Sequence(otherName='inclusions')
 
@@ -454,7 +449,8 @@
         # If this looks like a collection, we'll subscribe to
         # collection notifications.
         if isinstance(contents, ContentCollection):
-            self.itsView.notificationQueueSubscribe(contents, self)
+            self.itsView.watchCollectionQueue(self, contents,
+                                              'onCollectionNotification')
 
         # Do item subscription, if this block wants us to watch 
         # something and has an onItemNotification method
@@ -496,7 +492,8 @@
         # unsubscribe from collection notifications
         contents = getattr (self, 'contents', None)
         if contents is not None and isinstance(contents, ContentCollection):
-            self.itsView.notificationQueueUnsubscribe(contents, self)
+            self.itsView.unwatchCollectionQueue(self, contents,
+                                                'onCollectionNotification')
             
         # do item notifications, too, if we had any
         try:

Modified: trunk/chandler/parcels/osaf/pim/collections.py (11188 => 11189)

--- trunk/chandler/parcels/osaf/pim/collections.py	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/parcels/osaf/pim/collections.py	2006-07-18 19:24:59 UTC (rev 11189)
@@ -35,17 +35,6 @@
     """
     The base class for Chandler Collection types.
 
-    ContentCollection instances are items wrapping a collection value and
-    provide a C{subscribers} ref collection for clients to subscribe to their
-    notifications. Subscriber items must provide a C{subscribesTo} inverse
-    attribute and a method of the following signature::
-        C{onCollectionNotification(op, collection, name, item)}
-
-    where C{op} is one of C{add}, C{remove}, C{refresh} or C{changed},
-    C{collection} is the Collection item, C{name} is the attribute
-    containing the collection value and C{item} the item in the collection
-    that was added, removed, refreshed or changed.
-
     This class is abstract. Base concrete subclasses must use the
     C{schema.CollectionClass} metaclass and declare the collection attribute
     and its name as in the examples below::
@@ -104,7 +93,7 @@
     schema.addClouds(
         copying = schema.Cloud(
             invitees,
-            byRef=['contentsOwner', 'subscribers']
+            byRef=['contentsOwner']
         ),
         sharing = schema.Cloud(none=["displayName"]),
     )

Modified: trunk/chandler/parcels/osaf/pim/tests/TestCollections.py (11188 => 11189)

--- trunk/chandler/parcels/osaf/pim/tests/TestCollections.py	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/parcels/osaf/pim/tests/TestCollections.py	2006-07-18 19:24:59 UTC (rev 11189)
@@ -26,7 +26,6 @@
     we should change notifications to work on callables -- John is cool with that.
     """
     log = schema.Sequence(initialValue=[])
-    subscribesTo = schema.One(ContentCollection, otherName="subscribers")
 
     def checkLog(self, op, item, other, index=-1):
         if len(self.log) == 0:
@@ -43,7 +42,7 @@
                 continue
             return rec[0] == op and (rec[3] == other or rec[3] == other.itsUUID)
 
-    def onCollectionNotification(self, op, collection, name, other):
+    def queuedChange(self, op, collection, name, other):
         if name != 'watches':
             self.log.append((op, collection, name, other))
 
@@ -126,8 +125,8 @@
         u = UnionCollection('u', itsView=self.view,
                             sources=[ self.b1, self.b2 ])
 
-        self.b1.notificationQueueSubscribe(self.nh)
-        u.notificationQueueSubscribe(self.nh1)
+        self.view.watchCollectionQueue(self.nh, self.b1, 'queuedChange')
+        self.view.watchCollectionQueue(self.nh1, u, 'queuedChange')
 
         # add i to b1
         self.b1.add(self.i)
@@ -151,15 +150,15 @@
         test addSource
         """
         u = UnionCollection('u', itsView=self.view)
-        u.notificationQueueSubscribe(self.nh)
+        self.view.watchCollectionQueue(self.nh, u, 'queuedChange')
 
         self.b1.add(self.i)
         self.b2.add(self.i)
         self.b2.add(self.i1)
 
         # make transient subscriptions
-        self.view.notificationQueueSubscribe(self.b1, self.nh1)
-        self.view.notificationQueueSubscribe(self.b2, self.nh2)
+        self.view.watchCollectionQueue(self.nh1, self.b1, 'queuedChange')
+        self.view.watchCollectionQueue(self.nh2, self.b2, 'queuedChange')
 
         u.addSource(self.b1)
         self.view.dispatchNotifications()
@@ -183,8 +182,8 @@
         """
         d = DifferenceCollection('d', itsView=self.view,
                                  sources=[ self.b1, self.b2 ])
-        self.b1.notificationQueueSubscribe(self.nh)
-        d.notificationQueueSubscribe(self.nh1)
+        self.view.watchCollectionQueue(self.nh, self.b1, 'queuedChange')
+        self.view.watchCollectionQueue(self.nh1, d, 'queuedChange')
 
         self.b1.add(self.i)
         self.view.dispatchNotifications()      
@@ -196,7 +195,7 @@
         self.failUnless(self.nh.checkLog("add", self.b1, self.i1))
         self.failUnless(self.nh1.checkLog("add", d, self.i1))
 
-        self.b2.notificationQueueSubscribe(self.nh2)
+        self.view.watchCollectionQueue(self.nh2, self.b2, 'queuedChange')
         self.b2.add(self.i2)
         self.view.dispatchNotifications()
         self.failUnless(self.nh2.checkLog("add", self.b2, self.i2))
@@ -221,12 +220,12 @@
         ic = DifferenceCollection("ic", itsView=self.view,
                                   sources=[ iu, exclusions ])
 
-        inclusions.notificationQueueSubscribe(self.nh)
-        rule.notificationQueueSubscribe(self.nh1)
-        exclusions.notificationQueueSubscribe(self.nh2)
+        self.view.watchCollectionQueue(self.nh, inclusions, 'queuedChange')
+        self.view.watchCollectionQueue(self.nh1, rule, 'queuedChange')
+        self.view.watchCollectionQueue(self.nh2, exclusions, 'queuedChange')
 
         nh3 = NotifyHandler("nh3", itsView=self.view)
-        ic.notificationQueueSubscribe(nh3)
+        self.view.watchCollectionQueue(nh3, ic, 'queuedChange')
 
         inclusions.add(self.i)
         self.view.dispatchNotifications()
@@ -267,7 +266,7 @@
                             kind=k)
         k2 = KindCollection(itsView=self.view,
                             kind=self.i.itsKind)
-        k2.notificationQueueSubscribe(self.nh)
+        self.view.watchCollectionQueue(self.nh, k2, 'queuedChange')
 
         i = SimpleItem("new i", itsView=self.view)
         self.view.dispatchNotifications()       
@@ -298,8 +297,8 @@
                                 source=self.b1,
                                 filterExpression=u"len(view[uuid].label) > 3",
                                 filterAttributes=["label"])
-        self.b1.notificationQueueSubscribe(self.nh)
-        f1.notificationQueueSubscribe(self.nh1)
+        self.view.watchCollectionQueue(self.nh, self.b1, 'queuedChange')
+        self.view.watchCollectionQueue(self.nh1, f1, 'queuedChange')
 
         self.b1.add(self.i)
         self.view.dispatchNotifications()
@@ -329,8 +328,8 @@
                                 filterAttributes=["label"])
         nh3 = NotifyHandler("nh3", itsView=self.view)
 
-        k1.notificationQueueSubscribe(self.nh2)
-        f2.notificationQueueSubscribe(nh3)
+        self.view.watchCollectionQueue(self.nh2, k1, 'queuedChange')
+        self.view.watchCollectionQueue(nh3, f2, 'queuedChange')
 
         fred = SimpleItem("fred", label=uw("fred"), itsView=self.view)
         self.view.dispatchNotifications()
@@ -402,8 +401,8 @@
                                 filterAttributes=["label"])
         nh3 = NotifyHandler("nh3", itsView=self.view)
 
-        k1.notificationQueueSubscribe(self.nh2)
-        f2.notificationQueueSubscribe(nh3)
+        self.view.watchCollectionQueue(self.nh2, k1, 'queuedChange')
+        self.view.watchCollectionQueue(nh3, f2, 'queuedChange')
 
         self.i.label = uw("xxx")
         print nh3.log
@@ -439,7 +438,7 @@
         l = ListCollection(itsView=self.view)
 
         u = UnionCollection(itsView=self.view)
-        u.notificationQueueSubscribe(self.nh)
+        self.view.watchCollectionQueue(self.nh, u, 'queuedChange')
 
         u.addSource(f)
         u.addSource(l)

Modified: trunk/chandler/repository/item/Collection.py (11188 => 11189)

--- trunk/chandler/repository/item/Collection.py	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/repository/item/Collection.py	2006-07-18 19:24:59 UTC (rev 11189)
@@ -29,17 +29,6 @@
 
 class Collection(Item):
     """
-    Collection instances are items wrapping a collection attribute value and
-    provide a C{subscribers} ref collection for clients to subscribe to their
-    notifications. Subscriber items must provide a C{subscribesTo} inverse
-    attribute and a method of the following signature::
-        C{onCollectionNotification(op, collection, name, item)}
-
-    where C{op} is one of C{add}, C{remove}, C{refresh} or C{changed},
-    C{collection} is the Collection item, C{name} is the attribute
-    containing the collection value and C{item} the item in the collection
-    that was added, removed, refreshed or changed.
-
     This class is abstract. Base concrete subclasses must use the
     C{CollectionClass} metaclass, must be declared tied to a kind that
     provides the collection attribute, and must declare its name as in the
@@ -56,38 +45,13 @@
 
     def _collectionChanged(self, op, change, name, other):
 
-        if change == 'dispatch':
+        view = self.itsView
+        watchers = view._watchers.get(self.itsUUID)
+        if watchers and view.SUBSCRIBERS in watchers:
+            view.queueNotification(self, op, change, name, other)
 
-            subscribers = getattr(self, 'subscribers', None)
-            if subscribers:
-                for subscriber in subscribers:
-                    subscriber.onCollectionNotification(op, self, name, other)
+        super(Collection, self)._collectionChanged(op, change, name, other)
 
-            view = self.itsView
-            subscribers = view._subscribers.get(self.itsUUID)
-            if subscribers:
-                notFound = None
-                for subscriber in subscribers:
-                    item = view.findUUID(subscriber)
-                    if item is not None:
-                        item.onCollectionNotification(op, self, name, other)
-                    elif notFound is None:
-                        notFound = [subscriber]
-                    else:
-                        notFound.append(subscriber)
-                if notFound:
-                    for subscriber in notFound:
-                        view.notificationQueueUnsubscribe(self, subscriber)
-
-        else:
-            view = self.itsView
-
-            if (getattr(self, 'subscribers', None) or
-                view._subscribers.get(self.itsUUID)):
-                view.queueNotification(self, op, change, name, other)
-
-            super(Collection, self)._collectionChanged(op, change, name, other)
-
     def __contains__(self, obj):
 
         return obj in getattr(self, self.__collection__)
@@ -127,15 +91,6 @@
         else:
             return remove(other)
 
-    def notificationQueueSubscribe(self, subscriber):
-
-        self.subscribers.add(subscriber)
-
-    def notificationQueueUnsubscribe(self, subscriber):
-
-        if subscriber in self.subscribers:
-            self.subscribers.remove(subscriber)
-
     def getSourceCollection(self):
 
         return self.itsView, (self.itsUUID, self.__collection__)

Modified: trunk/chandler/repository/packs/schema/model/Collection.kind (11188 => 11189)

--- trunk/chandler/repository/packs/schema/model/Collection.kind	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/repository/packs/schema/model/Collection.kind	2006-07-18 19:24:59 UTC (rev 11189)
@@ -11,7 +11,7 @@
 
       <!-- 
          - plus local attributes below: 
-         -   subscribers
+         - 
         -->
     </ref>
 
@@ -23,21 +23,4 @@
       <value name="python">repository.item.Collection.Collection</value>
     </attribute>
   </item>
-
-  <item withSchema="True">
-    <name>subscribers</name>
-    <kind type="path">//Schema/Core/Attribute</kind>
-    <class module="repository.schema.Attribute">Attribute</class>
-    <parent type="path">//Schema/Core/Collection</parent>
-
-    <ref name="kinds" otherName="attributes"
-         cardinality="list" otherCard="list">
-      <ref type="path" otherAlias="subscribers">..</ref>
-    </ref>
-
-    <attribute name="cardinality">list</attribute>
-    <attribute name="otherName">subscribesTo</attribute>
-    <attribute name="initialValue" type="list"></attribute>
-  </item>
-
 </items>

Deleted: trunk/chandler/repository/packs/schema/model/clouds/Collection.cloud (11188 => 11189)

--- trunk/chandler/repository/packs/schema/model/clouds/Collection.cloud	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/repository/packs/schema/model/clouds/Collection.cloud	2006-07-18 19:24:59 UTC (rev 11189)
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-
-<items>
-
-  <item>
-    <name>Collection</name>
-    <kind type="path">//Schema/Core/Cloud</kind>
-
-    <ref name="endpoints">
-      <!-- 
-         - plus local endpoints below:
-         -     subscribers
-        -->
-    </ref>
-
-    <ref name="kind" otherAlias="export"
-         type="path">//Schema/Core/Collection</ref>
-  </item>
-
-  <item>
-    <name>subscribers</name>
-    <kind type="path">//Schema/Core/Endpoint</kind>
-    <parent type="path">//Schema/Core/Clouds/Collection</parent>
-
-    <ref name="clouds">
-      <ref otherAlias="subscribers" type="path">..</ref>
-    </ref>
-
-    <attribute name="attribute">
-      <value>subscribers</value>
-    </attribute>
-    <attribute name="includePolicy">byRef</attribute>
-  </item>
-
-</items>

Modified: trunk/chandler/repository/packs/schema.pack (11188 => 11189)

--- trunk/chandler/repository/packs/schema.pack	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/repository/packs/schema.pack	2006-07-18 19:24:59 UTC (rev 11189)
@@ -38,7 +38,6 @@
         <item file="Struct.cloud" />
         <item file="Cloud.cloud" />
         <item file="Endpoint.cloud" />
-        <item file="Collection.cloud" />
       </item>
 
       <item file="Mixins.namespace" />

Modified: trunk/chandler/repository/persistence/RepositoryView.py (11188 => 11189)

--- trunk/chandler/repository/persistence/RepositoryView.py	2006-07-18 19:09:41 UTC (rev 11188)
+++ trunk/chandler/repository/persistence/RepositoryView.py	2006-07-18 19:24:59 UTC (rev 11189)
@@ -59,8 +59,9 @@
     # 0.6.5: changed format of abstract sets to store an optional id
     # 0.6.6: added support for MethodFilteredSet
     # 0.6.7: watchers reworked to use RefDict
+    # 0.6.8: removed support for persistent collection queue subscriptions
     
-    CORE_SCHEMA_VERSION = 0x00060700
+    CORE_SCHEMA_VERSION = 0x00060800
 
     def __init__(self, repository, name, version):
         """
@@ -73,7 +74,6 @@
         """
 
         self._notifications = Queue()
-        self._subscribers = {}
 
         if not name:
             name = threading.currentThread().getName()
@@ -204,7 +204,6 @@
             repository._openViews.remove(self)
 
         self.flushNotifications()
-        self._subscribers.clear()
         self.clear()
 
         if repository is not None:
@@ -1124,10 +1123,19 @@
             while not queue.empty():
                 uItem, op, change, name, other = queue.get()
                 count += 1
-                item = self.find(uItem)
-                if item is not None:
-                    item._collectionChanged(op, 'dispatch', name, other)
 
+                watchers = self._watchers.get(uItem)
+                if watchers:
+                    watchers = watchers.get(self.SUBSCRIBERS)
+                    if watchers:
+                        try:
+                            collection = self[uItem]
+                        except KeyError:
+                            continue
+                        else:
+                            for watcher in watchers:
+                                watcher(op, change, collection, name, other)
+
             while self.isDirtyAgain():
                 self._dispatchChanges(self.mapChanges(True))
 
@@ -1147,28 +1155,6 @@
 
         return count
 
-    def notificationQueueSubscribe(self, collection, subscriber):
-
-        uCol = collection.itsUUID
-        uItem = subscriber.itsUUID
-        subscribers = self._subscribers.get(uCol)
-
-        if subscribers is None:
-            self._subscribers[uCol] = set((uItem,))
-        else:
-            subscribers.add(uItem)
-
-    def notificationQueueUnsubscribe(self, collection, subscriber):
-
-        uCol = collection.itsUUID
-        uItem = subscriber.itsUUID
-        subscribers = self._subscribers.get(uCol)
-
-        if subscribers and uItem in subscribers:
-            subscribers.remove(uItem)
-            if not subscribers:
-                del self._subscribers[uCol]
-
     def _dispatchHistory(self, history, refreshes, oldVersion, newVersion):
 
         raise NotImplementedError, "%s._dispatchHistory" %(type(self))
@@ -1179,26 +1165,22 @@
 
     def _registerWatch(self, watchingItem, watchedItem, cls, key, *args):
 
-        watchers = self._watchers
         uWatching = watchingItem.itsUUID
         uWatched = watchedItem.itsUUID
 
+        watchers = self._watchers.get(uWatched)
         if watchers is None:
-            self._watchers = {uWatched: {key: [cls(self, uWatching, *args)]}}
+            self._watchers[uWatched] = {key: [cls(self, uWatching, *args)]}
         else:
-            watchers = watchers.get(uWatched)
+            watchers = watchers.get(key)
             if watchers is None:
-                self._watchers[uWatched] = {key: [cls(self, uWatching, *args)]}
+                self._watchers[uWatched][key] = [cls(self, uWatching, *args)]
             else:
-                watchers = watchers.get(key)
-                if watchers is None:
-                    self._watchers[uWatched][key] = [cls(self, uWatching,*args)]
-                else:
-                    for watcher in watchers:
-                        if (watcher.watchingItem == uWatching and
-                            type(watcher) is cls and watcher.compare(*args)):
-                            return watcher
-                    watchers.append(cls(self, uWatching, *args))
+                for watcher in watchers:
+                    if (watcher.watchingItem == uWatching and
+                        type(watcher) is cls and watcher.compare(*args)):
+                        return watcher
+                watchers.append(cls(self, uWatching, *args))
                 
         if cls is TransientWatchItem:
             watchedItem._status |= CItem.T_WATCHED
@@ -1271,9 +1253,20 @@
         self._unregisterWatch(watchingItem, owner, TransientWatchCollection,
                               attribute, methodName)
 
+    def watchCollectionQueue(self, watchingItem, collection, methodName):
+        return self._registerWatch(watchingItem, collection,
+                                   TransientWatchCollection,
+                                   RepositoryView.SUBSCRIBERS, methodName)
+
+    def unwatchCollectionQueue(self, watchingItem, collection, methodName):
+        self._unregisterWatch(watchingItem, collection,
+                              TransientWatchCollection,
+                              RepositoryView.SUBSCRIBERS, methodName)
+
     itsUUID = UUID('3631147e-e58d-11d7-d3c2-000393db837c')
+    SUBSCRIBERS = UUID('4dc81eae-1689-11db-a0ac-0016cbc90838')
+
     itsPath = property(_getPath)
-    
     views = property(lambda self: self.repository.getOpenViews())
 
 




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to