WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] xsnode.py:

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] xsnode.py:
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Fri, 17 Jun 2005 18:18:44 +0000
Delivery-date: Sat, 18 Jun 2005 01:03:01 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1713.1.27, 2005/06/17 19:18:44+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        xsnode.py:
          Updated watches/event code from Mike Wray.
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 xsnode.py |   72 +++++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 48 insertions(+), 24 deletions(-)


diff -Nru a/tools/python/xen/xend/xenstore/xsnode.py 
b/tools/python/xen/xend/xenstore/xsnode.py
--- a/tools/python/xen/xend/xenstore/xsnode.py  2005-06-17 21:04:06 -04:00
+++ b/tools/python/xen/xend/xenstore/xsnode.py  2005-06-17 21:04:06 -04:00
@@ -46,12 +46,12 @@
             watcher.delSubs(self)
         return watcher
 
-    def notify(self, path, val):
+    def notify(self, token, path, val):
         try:
-            self.fn(self, path, val)
-        except SystemExitException:
+            self.fn(self, token, path, val)
+        except SystemExit:
             raise
-        except:
+        except Exception, ex:
             pass
 
 class Watcher:
@@ -71,6 +71,9 @@
     def getPath(self):
         return self.path
 
+    def getToken(self):
+        return self.path
+
     def addSubs(self, subs):
         self.subscriptions.append(subs)
         self.watch()
@@ -83,14 +86,15 @@
     def watch(self):
         if self.xs: return
         self.xs = xs.open()
-        self.xs.watch(self.path)
+        self.xs.watch(path=self.getPath(), token=self.getToken())
 
     def unwatch(self):
         if self.xs:
-            try:
-                self.xs.unwatch(self.path)
-            except Exception, ex:
-                print 'Watcher>unwatch>', ex
+## Possibly crashes xenstored.
+##            try:
+##                self.xs.unwatch(path=self.getPath(), token=self.getToken())
+##            except Exception, ex:
+##                print 'Watcher>unwatch>', ex
             try:
                 self.xs.close()
             except Exception, ex:
@@ -102,17 +106,22 @@
 
     def getNotification(self):
         p = self.xs.read_watch()
-        self.xs.acknowledge_watch()
+        self.xs.acknowledge_watch(p[1])
         return p
 
     def notify(self):
         try:
-            p = self.getNotification()
-            v = self.xs.read(p)
-            for s in subscriptions:
-                s.notify(p, v)
+            (path, token) = self.getNotification()
+            if path.endswith("@eid"):
+                pass
+            else:
+                val = self.xs.read(path)
+                for subs in self.subscriptions:
+                    subs.notify(token, path, val)
+        except SystemExit:
+            raise
         except Exception, ex:
-            print 'Notify exception:', ex
+            raise
 
 class EventWatcher(Watcher):
 
@@ -126,6 +135,9 @@
     def getEvent(self):
         return self.event
 
+    def getToken(self):
+        return self.event
+
 class XenStore:
 
     xs = None
@@ -145,8 +157,10 @@
                     self.xs = xs.open()
                     ex = None
                     break
+                except SystemExit:
+                    raise
                 except Exception, ex:
-                    print >>sys.stderr, "Exception connecting to xsdaemon:", ex
+                    print >>sys.stderr, "Exception connecting to xenstored:", 
ex
                     print >>sys.stderr, "Trying again..."
                     time.sleep(1)
             else:
@@ -241,7 +255,10 @@
 
     def write(self, path, data, create=True, excl=False):
         self.mkdirs(path)
-        self.getxs().write(path, data, create=create, excl=excl)
+        try:
+            self.getxs().write(path, data, create=create, excl=excl)
+        except Exception, ex:
+            raise
 
     def begin(self, path):
         self.getxs().transaction_start(path)
@@ -261,7 +278,10 @@
         del self.subscriptions[s.sid]
         watcher = s.unwatch()
         if watcher and not watcher.watching():
-            del self.watchers[path]
+            try:
+                del self.watchers[watcher.getPath()]
+            except:
+                pass
 
     def subscribe(self, event, fn):
         path = getEventPath(event)
@@ -280,13 +300,10 @@
             self.mkdirs(eventPath)
             eid = 1
             if self.exists(eidPath):
-                data = self.read(eidPath)
-                print 'sendEvent>', 'data=', data, type(data)
                 try:
                     eid = int(self.read(eidPath))
                     eid += 1
                 except Exception, ex:
-                    print 'sendEvent>', ex
                     pass
             self.write(eidPath, str(eid))
             self.write(os.path.join(eventPath, str(eid)), data)
@@ -346,6 +363,15 @@
         xenstore = XenStore()
         return xenstore
 
+def sendEvent(event, val):
+    getXenStore.sendEvent(event, val)
+
+def subscribe(event, fn):
+    return getXenStore().subscribe(event, fn)
+
+def unsubscribe(sid):
+    getXenStore().unsubscribe(sid)
+
 class XenNode:
 
     def __init__(self, path="/", create=True):
@@ -389,9 +415,7 @@
             return None
 
     def setData(self, data, path=""):
-        path = self.relPath(path)
-        #print 'XenNode>setData>', 'path=', path, 'data=', data
-        return self.store.write(path, data)
+        return self.store.write(self.relPath(path), data)
 
     def getLock(self):
         return None

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>