[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Removed the EventServer, replacing the events fired with simple logging



# HG changeset patch
# User emellor@ewan
# Node ID c60036fe7418d52b7cbbec4862933233b87b9660
# Parent  33cd9a7a903b11ac7ff25275952953a0a78a2838
Removed the EventServer, replacing the events fired with simple logging
messages.  This closes bug #281.  Removed references to XendRoot where these
have become unnecessary either through the work above or just through time.

Renamed some parameters in event.py, to mark them as unused.  Fix a call to a
base class constructor there too.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Tue Oct  4 23:11:30 2005
+++ b/tools/python/xen/xend/XendDomain.py       Wed Oct  5 10:43:23 2005
@@ -30,7 +30,6 @@
 
 from xen.xend import XendRoot
 from xen.xend import XendCheckpoint
-from xen.xend import EventServer
 from xen.xend.XendError import XendError
 from xen.xend.XendLogging import log
 from xen.xend.server import relocate
@@ -38,7 +37,6 @@
 
 xc = xen.lowlevel.xc.new()
 xroot = XendRoot.instance()
-eserver = EventServer.instance()
 
 
 __all__ = [ "XendDomain" ]
@@ -329,20 +327,21 @@
  
     def domain_unpause(self, domid):
         """Unpause domain execution."""
-        dominfo = self.domain_lookup(domid)
-        eserver.inject('xend.domain.unpause', [dominfo.getName(),
-                                               dominfo.getDomid()])
-        try:
+        try:
+            dominfo = self.domain_lookup(domid)
+            log.info("Domain %s (%d) unpaused.", dominfo.getName(),
+                     dominfo.getDomid())
             return xc.domain_unpause(dom=dominfo.getDomid())
         except Exception, ex:
             raise XendError(str(ex))
-    
+
+
     def domain_pause(self, domid):
         """Pause domain execution."""
-        dominfo = self.domain_lookup(domid)
-        eserver.inject('xend.domain.pause', [dominfo.getName(),
-                                             dominfo.getDomid()])
-        try:
+        try:
+            dominfo = self.domain_lookup(domid)
+            log.info("Domain %s (%d) paused.", dominfo.getName(),
+                     dominfo.getDomid())
             return xc.domain_pause(dom=dominfo.getDomid())
         except Exception, ex:
             raise XendError(str(ex))
diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/XendRoot.py
--- a/tools/python/xen/xend/XendRoot.py Tue Oct  4 23:11:30 2005
+++ b/tools/python/xen/xend/XendRoot.py Wed Oct  5 10:43:23 2005
@@ -28,14 +28,11 @@
 import os.path
 import sys
 
-import EventServer
 from XendLogging import XendLogging
 from XendError import XendError
 
-# Initial create of the event server.
-eserver = EventServer.instance()
-
 import sxp
+
 
 class XendRoot:
     """Root of the management classes."""
@@ -96,9 +93,7 @@
         self.config = None
         self.logging = None
         self.configure()
-        eserver.subscribe('xend.*', self.event_handler)
-        #eserver.subscribe('xend.domain.created', self.event_handler)
-        #eserver.subscribe('xend.domain.died', self.event_handler)
+
 
     def add_component(self, name, val):
         """Add a xend component.
@@ -117,9 +112,6 @@
         @return: component object (or None)
         """
         return self.components.get(name)
-
-    def start(self):
-        eserver.inject('xend.start', 0)
 
     def _format(self, msg, args):
         if args:
diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py Tue Oct  4 23:11:30 2005
+++ b/tools/python/xen/xend/server/SrvDaemon.py Wed Oct  5 10:43:23 2005
@@ -2,6 +2,7 @@
 ## Xen controller daemon
 ## Copyright (c) 2004, K A Fraser (University of Cambridge)
 ## Copyright (C) 2004, Mike Wray <mike.wray@xxxxxx>
+## Copyright (C) 2005, XenSource Ltd
 ###########################################################
 
 import os
@@ -13,18 +14,12 @@
 import re
 import traceback
 
-from xen.xend import EventServer
 from xen.xend.server import SrvServer
 from xen.xend.XendLogging import log
-from xen.xend import XendRoot
 
 import event
 import relocate
 from params import *
-
-
-eserver = EventServer.instance()
-xroot = XendRoot.instance()
 
 
 class Daemon:
diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/server/SrvRoot.py
--- a/tools/python/xen/xend/server/SrvRoot.py   Tue Oct  4 23:11:30 2005
+++ b/tools/python/xen/xend/server/SrvRoot.py   Wed Oct  5 10:43:23 2005
@@ -13,10 +13,9 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
+# Copyright (C) 2005 XenSource Ltd
 #============================================================================
 
-from xen.xend import XendRoot
-xroot = XendRoot.instance()
 from xen.web.SrvDir import SrvDir
 
 class SrvRoot(SrvDir):
@@ -39,8 +38,6 @@
             self.add(name, klass)
         for (name, klass) in self.subdirs:
             self.get(name)
-        xroot.start()
         
     def __repr__(self):
         return "<SrvRoot %x %s>" %(id(self), self.table.keys())
-
diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/server/event.py
--- a/tools/python/xen/xend/server/event.py     Tue Oct  4 23:11:30 2005
+++ b/tools/python/xen/xend/server/event.py     Wed Oct  5 10:43:23 2005
@@ -24,12 +24,10 @@
 from xen.xend import scheduler
 from xen.xend import sxp
 from xen.xend import PrettyPrint
-from xen.xend import EventServer
 from xen.xend.XendError import XendError
 from xen.xend import XendRoot
 
 
-eserver = EventServer.instance()
 xroot = XendRoot.instance()
 
 
@@ -44,13 +42,7 @@
         self.daemon = daemon
         # Event queue.
         self.queue = []
-        # Subscribed events.
-        self.events = []
         self.parser = sxp.Parser()
-        self.pretty = 0
-
-        # For debugging subscribe to everything and make output pretty.
-        #self.subscribe(['*'])
         self.pretty = 1
 
     def dataReceived(self, data):
@@ -74,7 +66,7 @@
             scheduler.now(self.connectionLost)
 
     def connectionLost(self, reason=None):
-        self.unsubscribe()
+        pass
 
     def send_reply(self, sxpr):
         io = StringIO.StringIO()
@@ -105,16 +97,6 @@
     def send_event(self, val):
         return self.send_reply(['event', val[0], val[1]])
 
-    def unsubscribe(self):
-        for event in self.events:
-            eserver.unsubscribe(event, self.queue_event)
-
-    def subscribe(self, events):
-        self.unsubscribe()
-        for event in events:
-            eserver.subscribe(event, self.queue_event)
-        self.events = events
-
     def queue_event(self, name, v):
         # Despite the name we don't queue the event here.
         # We send it because the transport will queue it.
@@ -132,7 +114,7 @@
         op_method = getattr(self, op_method_name, self.operror)
         return op_method(op_name, req)
 
-    def op_help(self, name, req):
+    def op_help(self, _1, _2):
         def nameop(x):
             if x.startswith('op_'):
                 return x[3:].replace('_', '.')
@@ -142,37 +124,27 @@
         l = [ nameop(k) for k in dir(self) if k.startswith('op_') ]
         return l
 
-    def op_quit(self, name, req):
+    def op_quit(self, _1, _2):
         self.loseConnection()
 
-    def op_exit(self, name, req):
+    def op_exit(self, _1, _2):
         sys.exit(0)
 
-    def op_pretty(self, name, req):
+    def op_pretty(self, _1, _2):
         self.pretty = 1
 
-    def op_info(self, name, req):
+    def op_info(self, _1, _2):
         val = ['info']
         #val += self.daemon.blkifs()
         #val += self.daemon.netifs()
         #val += self.daemon.usbifs()
         return val
 
-    def op_sys_subscribe(self, name, v):
-        # (sys.subscribe event*)
-        # Subscribe to the events:
-        self.subscribe(v[1:])
-
-    def op_sys_inject(self, name, v):
-        # (sys.inject event)
-        event = v[1]
-        eserver.inject(sxp.name(event), event)
-
-    def op_trace(self, name, v):
+    def op_trace(self, _, v):
         mode = (v[1] == 'on')
         self.daemon.tracing(mode)
 
-    def op_log_stderr(self, name, v):
+    def op_log_stderr(self, _, v):
         mode = v[1]
         logging = xroot.get_logging()
         if mode == 'on':
@@ -180,11 +152,11 @@
         else:
             logging.removeLogStderr()
 
-    def op_domain_ls(self, name, v):
+    def op_domain_ls(self, _1, _2):
         xd = xroot.get_component("xen.xend.XendDomain")
         return xd.list_names()
 
-    def op_domain_configure(self, name, v):
+    def op_domain_configure(self, _, v):
         domid = sxp.child_value(v, "dom")
         config = sxp.child_value(v, "config")
         if domid is None:
@@ -194,7 +166,7 @@
         xd = xroot.get_component("xen.xend.XendDomain")
         xd.domain_configure(domid, config)
 
-    def op_domain_unpause(self, name, v):
+    def op_domain_unpause(self, _, v):
         domid = sxp.child_value(v, "dom")
         if domid is None:
             raise XendError("missing domain id")
@@ -206,10 +178,10 @@
     """
 
     def __init__(self, daemon):
-        #protocol.ServerFactory.__init__(self)
+        protocol.ServerFactory.__init__(self)
         self.daemon = daemon
 
-    def buildProtocol(self, addr):
+    def buildProtocol(self, _):
         return EventProtocol(self.daemon)
 
 def listenEvent(daemon):
diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/server/relocate.py
--- a/tools/python/xen/xend/server/relocate.py  Tue Oct  4 23:11:30 2005
+++ b/tools/python/xen/xend/server/relocate.py  Wed Oct  5 10:43:23 2005
@@ -24,13 +24,11 @@
 
 from xen.xend import scheduler
 from xen.xend import sxp
-from xen.xend import EventServer
 from xen.xend.XendError import XendError
 from xen.xend import XendRoot
 from xen.xend.XendLogging import log
 
 
-eserver = EventServer.instance()
 xroot = XendRoot.instance()
 
 
diff -r 33cd9a7a903b -r c60036fe7418 tools/python/xen/xend/EventServer.py
--- a/tools/python/xen/xend/EventServer.py      Tue Oct  4 23:11:30 2005
+++ /dev/null   Wed Oct  5 10:43:23 2005
@@ -1,265 +0,0 @@
-#============================================================================
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of version 2.1 of the GNU Lesser General Public
-# License as published by the Free Software Foundation.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#============================================================================
-# Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
-#============================================================================
-
-"""Simple publish/subscribe event server.
-
-"""
-import string
-from threading import Lock
-
-import scheduler
-
-# subscribe a.b.c h: map a.b.c -> h
-# subscribe a.b.* h: map a.b.* -> h
-# subscribe a.b.? h: map a.b.? -> h
-#
-# for event a.b.c.d:
-#
-# lookup a.b.c.d, call handlers
-#
-# lookup a.b.c.?, call handlers
-#
-# lookup a.b.c.d.*, call handlers
-# lookup a.b.c.*, call handlers
-# lookup a.b.*, call handlers
-# lookup a.*, call handlers
-# lookup *, call handlers
-
-# a.b.c.d = (a b c d)
-# a.b.c.? = (a b c _)
-# a.b.c.* = (a b c . _)
-
-class EventServer:
-
-    DOT = '.'
-    QUERY = '?'
-    DOT_QUERY = DOT + QUERY
-    STAR = '*'
-    DOT_STAR = DOT + STAR
-
-    def __init__(self, run=0):
-        self.handlers = {}
-        self.run = run
-        self.queue = []
-        self.lock = Lock()
-
-    def start(self):
-        """Enable event handling. Sends any queued events.
-        """
-        try:
-            self.lock.acquire()
-            self.run = 1
-            queue = self.queue
-            self.queue = []
-        finally:
-            self.lock.release()
-        for (e,v) in queue:
-            self.inject(e, v)
-
-    def stop(self):
-        """Suspend event handling. Events injected while suspended
-        are queued until we are started again.
-        """
-        try:
-            self.lock.acquire()
-            self.run = 0
-        finally:
-            self.lock.release()
-
-    def subscribe(self, event, handler):
-        """Subscribe to an event. For example 'a.b.c.d'.
-        A subcription like 'a.b.c.?' ending in '?' matches any value
-        for the '?'. A subscription like 'a.b.c.*' ending in '*' matches
-        any event type with the same prefix, 'a.b.c' in this case.
-
-        event  event name
-        handler event handler fn(event, val)
-        """
-        try:
-            self.lock.acquire()
-            hl = self.handlers.get(event)
-            if hl is None:
-                self.handlers[event] = [handler]
-            else:
-                hl.append(handler)
-        finally:
-            self.lock.release()
-
-    def unsubscribe_all(self, event=None):
-        """Unsubscribe all handlers for a given event, or all handlers.
-
-        event  event (optional)
-        """
-        try:
-            self.lock.acquire()
-            if event == None:
-                self.handlers.clear()
-            elif event in self.handlers:
-                del self.handlers[event]
-        finally:
-            self.lock.release()
-        
-    def unsubscribe(self, event, handler):
-        """Unsubscribe a given event and handler.
-
-        event  event
-        handler handler
-        """
-        try:
-            self.lock.acquire()
-            hl = self.handlers.get(event)
-            if hl is None:
-                return
-            if handler in hl:
-                hl.remove(handler)
-        finally:
-            self.lock.release()
-
-    def inject(self, event, val, async=1):
-        """Inject an event. Handlers for it are called if running, otherwise
-        it is queued.
-
-        event  event type
-        val    event value
-        """
-        try:
-            self.lock.acquire()
-            if not self.run:
-                self.queue.append( (event, val) )
-                return
-        finally:
-            self.lock.release()
-            
-        if async:
-            scheduler.now(self.call_handlers, event, val)
-        else:
-            self.call_handlers(event, val)
-
-    def call_handlers(self, event, val):
-        """Internal method to call event handlers.
-        """
-        #print ">event", event, val
-        self.call_event_handlers(event, event, val)
-        self.call_query_handlers(event, val)
-        self.call_star_handlers(event, val)
-
-    def call_event_handlers(self, key, event, val):
-        """Call the handlers for an event.
-        It is safe for handlers to subscribe or unsubscribe.
-
-        key    key for handler list
-        event  event type
-        val    event value
-        """
-        try:
-            self.lock.acquire()
-            hl = self.handlers.get(key)
-            if hl is None:
-                return
-            # Copy the handler list so that handlers can call
-            # subscribe/unsubscribe safely - python list iteration
-            # is not safe against list modification.
-            hl = hl[:]
-        finally:
-            self.lock.release()
-        # Must not hold the lock while calling the handlers.
-        for h in hl:
-            try:
-                h(event, val)
-            except:
-                pass
-        
-    def call_query_handlers(self, event, val):
-        """Call regex handlers for events matching 'event' that end in '?'.
-
-        event  event type
-        val    event value
-        """
-        dot_idx = event.rfind(self.DOT)
-        if dot_idx == -1:
-            self.call_event_handlers(self.QUERY, event, val)
-        else:
-            event_query = event[0:dot_idx] + self.DOT_QUERY
-            self.call_event_handlers(event_query, event, val)
-
-    def call_star_handlers(self, event, val):
-        """Call regex handlers for events matching 'event' that end in '*'.
-
-        event  event type
-        val    event value
-        """
-        etype = string.split(event, self.DOT)
-        for i in range(len(etype), 0, -1):
-            event_star = self.DOT.join(etype[0:i]) + self.DOT_STAR
-            self.call_event_handlers(event_star, event, val)
-        self.call_event_handlers(self.STAR, event, val)       
-
-def instance():
-    global inst
-    try:
-        inst
-    except:
-        inst = EventServer()
-        inst.start()
-    return inst
-
-def main():
-    def sys_star(event, val):
-        print 'sys_star', event, val
-
-    def sys_foo(event, val):
-        print 'sys_foo', event, val
-        s.unsubscribe('sys.foo', sys_foo)
-
-    def sys_foo2(event, val):
-        print 'sys_foo2', event, val
-
-    def sys_bar(event, val):
-        print 'sys_bar', event, val
-
-    def sys_foo_bar(event, val):
-        print 'sys_foo_bar', event, val
-
-    def foo_bar(event, val):
-        print 'foo_bar', event, val
-
-    s = EventServer()
-    s.start()
-    s.subscribe('sys.*', sys_star)
-    s.subscribe('sys.foo', sys_foo)
-    s.subscribe('sys.foo', sys_foo2)
-    s.subscribe('sys.bar', sys_bar)
-    s.subscribe('sys.foo.bar', sys_foo_bar)
-    s.subscribe('foo.bar', foo_bar)
-    s.inject('sys.foo', 'hello')
-    print
-    s.inject('sys.bar', 'hello again')
-    print
-    s.inject('sys.foo.bar', 'hello again')
-    print
-    s.inject('foo.bar', 'hello again')
-    print
-    s.inject('foo', 'hello again')
-    print
-    s.start()
-    s.unsubscribe('sys.*', sys_star)
-    s.unsubscribe_all('sys.*')
-    s.inject('sys.foo', 'hello')
-
-if __name__ == "__main__":
-    main()
-

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.