I'm moving this to dev@ in the interest of broader exposure...
I like this, and only have a few quibbles:
1. I think that the booleans should be called inSameView and inOtherViews. This is semantically the difference between the two kinds of subscriptions, and it's better to present that rather than the implementation via monitors or commit (yes, I know that I started it by naming the old methods badly).
2. If we allow callbacks to be selected based on the views affected, then do we want to allow different callbacks for each case?
In the future, please feel free to send stuff like this directly to [EMAIL PROTECTED]
Ted
On Feb 17, 2005, at 4:18 PM, Alec Flett wrote:
John and I were talking about the monitor/subscribe thing (I had mentioned that I had a light plate for 0.5 and wanted to pitch in)
We talked about subscribe vs. monitor, and how rare it would be that you'd want to know about only view changes or only commit changes. I had to agree with John, I can't see a reason you'd want one but not the other.. but no sense in losing that flexibility just yet.
So I merged monitor() and unMonitor() into subscribe() and unsubscribe() with optional parameters which reflect what you actually want to listen for changes on.� This was a pretty simplistic merge, but basically I retain the two different callback lists, including their somewhat inconsistent naming (_callbacks and monitorCallbacks)
I'd like to float the API change and if so, I might do more cleanup in this department, and add the time-based notification throttling that John was talking about.
Alec Index: Query.py =================================================================== RCS file: /usr/local/cvsrep/chandler/repository/query/Query.py,v retrieving revision 1.24 diff -u -r1.24 Query.py --- Query.py 8 Feb 2005 21:40:58 -0000 1.24 +++ Query.py 18 Feb 2005 00:14:51 -0000 @@ -84,7 +84,7 @@ self._logical_plan = None self.stale = True
- def subscribe(self, callbackItem = None, callbackMethodName = None):
+ def subscribe(self, callbackItem = None, callbackMethodName = None, thisView = True, commits = True):
"""
This query should subscribe to repository changes
@@ -93,24 +93,45 @@
@param callbackMethodName: The name of the callback method on the callbackItem
@type callbackMethodName: string
+
+ @param thisView: if we should subscribe to changes in the current view
+ @type thisView: Boolean
+ @param commits: if we should subscribe to changes from commits
+ @type commits: Boolean
"""
if callbackItem is not None:
- self._callbacks [callbackItem.itsUUID] = callbackMethodName
+ if thisView:
+ self._callbacks [callbackItem.itsUUID] = callbackMethodName
+ if commits:
+ self.monitorCallbacks[callbackItem.itsUUID] = callbackMethodName
+ #@@@ add monitor for items in result set
log.debug(u"RepoQuery<>.subscribe(): %s" % (self.queryString))
self.itsView.addNotificationCallback(self.queryCallback)
- def unsubscribe(self, callbackItem=None):
+ def unsubscribe(self, callbackItem=None, thisView = True, commits = True):
"""
This query should stop subscribing to repository changes. If you don't specify a
callbackItemUUID, all subscriptions will be removed.
@param callbackItem: callbackItem to be removed
@type callbackItem: Item
+ @param thisView: if we should remove the item from the view subscriptions
+ @type thisView: Boolean
+ @param commits: if we should remove the item from the commit subscriptions
+ @type commits: Boolean
"""
if callbackItem is None:
- self._callbacks = {}
+ if commits:
+ self._callbacks = {}
+ if thisView:
+ self.monitorCallbacks = {}
else:
- del self._callbacks [callbackItem.itsUUID]
+ if commits:
+ del self._callbacks [callbackItem.itsUUID]
+ if thisView:
+ del self.monitorCallbacks [callbackItem.itsUUID]
+ #@@@ remove monitor for items in result set
+
self.itsView.removeNotificationCallback(self.queryCallback)
return len (self._callbacks)
@@ -234,35 +255,6 @@
return plan
- def monitor(self, callbackItem = None, callbackMethodName = None):
- """
- This query should subscribe to monitor changes
-
- @param callbackItem: a Chandler Item that provides a callback method
- @type callbackItem: Item
-
- @param callbackMethodName: The name of the callback method on the callbackItem
- @type callbackMethodName: string
- """
- if callbackItem is not None:
- self.monitorCallbacks[callbackItem.itsUUID] = callbackMethodName
- #@@@ add monitor for items in result set
-
- def unMonitor(self, callbackItem=None):
- """
- This query should stop subscribing to monitor changes. If you don't specify a
- callbackItemUUID, all subscriptions will be removed.
-
- @param callbackItem: callbackItem to be removed
- @type callbackItem: Item
- """
- if callbackItem is None:
- self.monitorCallbacks = {}
- else:
- del self.monitorCallbacks [callbackItem.itsUUID]
- #@@@ remove monitor for items in result set
- return len (self._callbacks)
-
def monitorCallback(self, op, item, attribute, *args, **kwds):
flag = self._logical_plan.monitored(op, item, attribute, *args, **kwds)
if flag is not None:
---- Ted Leung Open Source Applications Foundation (OSAF) PGP Fingerprint: 1003 7870 251F FA71 A59A CEE3 BEBA 2B87 F5FC 4B42
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Open Source Applications Foundation "Dev" mailing list http://lists.osafoundation.org/mailman/listinfo/dev
