[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.51 hub.py:1.20

Garrett Smith garrett at mojave-corp.com
Thu Aug 7 12:33:17 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv6429/src/zope/app/services

Modified Files:
	configure.zcml hub.py 
Log Message:
Added lazy unregistration to the object hub. It's currently possible to leave invalid object registrations when containers are deleted. These changes help to mitigate this problem until a more robust solution is in place. Details of the lazy unregistration are documented in test_objecthub.py.

These changes minimize the impact to the hub. More aggressive checks/unregistration of missing objects can be added if need be.

This change also includes the addition of a temporary hub method - unregisterMissingObjects - for unregistering invalid/missing objects. This functionality is exposed in the hub control form through a button the user can click to remove any missing objects.

=== Zope3/src/zope/app/services/configure.zcml 1.50 => 1.51 ===
--- Zope3/src/zope/app/services/configure.zcml:1.50	Sun Aug  3 13:50:28 2003
+++ Zope3/src/zope/app/services/configure.zcml	Thu Aug  7 11:32:41 2003
@@ -404,7 +404,7 @@
     <require
         permission="zope.ManageServices"
         attributes="bound unbound subscribe unsubscribe subscribeOnBind
-                    unsubscribedFrom subscribedTo" />
+                    unsubscribedFrom subscribedTo unregisterMissingObjects" />
     </content>
 
 <!-- Old simple auth service --> <include file="auth.zcml" />


=== Zope3/src/zope/app/services/hub.py 1.19 => 1.20 ===
--- Zope3/src/zope/app/services/hub.py:1.19	Sun Jul 13 03:18:23 2003
+++ Zope3/src/zope/app/services/hub.py	Thu Aug  7 11:32:41 2003
@@ -122,7 +122,10 @@
         obj = self.__object
         if obj is None:
             adapter = getAdapter(self.hub, ITraverser)
-            obj = self.__object = adapter.traverse(self.location)
+            try:
+                obj = self.__object = adapter.traverse(self.location)
+            except NotFoundError:
+                pass
         return obj
 
     object = property(__getObject)
@@ -269,6 +272,7 @@
         '''See interface IObjectHub'''
         path = wrapped_self.getPath(hubid)
         adapter = getAdapter(wrapped_self, ITraverser)
+        wrapped_self._verifyPath(path, adapter)
         return adapter.traverse(path)
     getObject = ContextMethod(getObject)
 
@@ -359,7 +363,7 @@
         """See interface IHubEventChannel"""
         traverser = getAdapter(wrapped_self, ITraverser)
         for path, hubId in wrapped_self.iterRegistrations():
-            yield (path, hubId, traverser.traverse(path))
+            yield (path, hubId, wrapped_self._safeTraverse(path, traverser))
     iterObjectRegistrations = ContextMethod(iterObjectRegistrations)
 
     ############################################################
@@ -373,6 +377,36 @@
             index = randid()
         self._v_nextid = index + 1
         return index
+
+
+    def _verifyPath(wrapped_self, path, traverser=None):
+        if traverser is None:
+            traverser = getAdapter(wrapped_self, ITraverser)
+        try:
+            traverser.traverse(path)
+        except NotFoundError, e:
+            wrapped_self.unregister(path)
+            raise e
+    _verifyPath = ContextMethod(_verifyPath)
+
+
+    def _safeTraverse(self, path, traverser):
+        try:
+            return traverser.traverse(path)
+        except NotFoundError:
+            return None
+
+    def unregisterMissingObjects(wrapped_self):
+        # XXX temporary method for clearing missing objects - remove when
+        # proper unregistration mechanisms are added.
+        missing = []
+        for object in wrapped_self.iterObjectRegistrations():
+            if object[2] is None:
+                missing.append(object[0])
+        for path in missing:
+            wrapped_self.unregister(path)
+        return len(missing)
+    unregisterMissingObjects = ContextMethod(unregisterMissingObjects)
 
 
 """A simple-minded registration object.




More information about the Zope3-Checkins mailing list