ia64/xen-unstable

changeset 1728:52fa3846c70b

bitkeeper revision 1.1059 (40ee955eIGZ9Xw5VHoV1rdIQidW4Ow)

Handle response messages in any order.
author mjw@wray-m-3.hpl.hp.com
date Fri Jul 09 12:53:50 2004 +0000 (2004-07-09)
parents ea24a5b766a2
children 3e4c28963eba
files tools/python/xen/xend/server/controller.py
line diff
     1.1 --- a/tools/python/xen/xend/server/controller.py	Fri Jul 09 12:53:22 2004 +0000
     1.2 +++ b/tools/python/xen/xend/server/controller.py	Fri Jul 09 12:53:50 2004 +0000
     1.3 @@ -11,11 +11,6 @@ from messages import msgTypeName, printM
     1.4  
     1.5  DEBUG = 0
     1.6  
     1.7 -class OutOfOrderError(RuntimeError):
     1.8 -    """Error reported when a response message arrives out of order.
     1.9 -    """
    1.10 -    pass
    1.11 -
    1.12  class Responder:
    1.13      """Handler for a response to a message with a specified id.
    1.14      """
    1.15 @@ -82,7 +77,7 @@ class CtrlMsgRcvr:
    1.16          self.dom = None
    1.17          self.channel = None
    1.18          self.idx = None
    1.19 -        self.responders = []
    1.20 +        self.responders = {}
    1.21          self.timeout = 10
    1.22  
    1.23      def setTimeout(self, timeout):
    1.24 @@ -140,10 +135,7 @@ class CtrlMsgRcvr:
    1.25      def addResponder(self, mid, deferred):
    1.26          """Add a responder for a message id.
    1.27          The I{deferred} is called with callback(msg) when a response
    1.28 -        with message id I{mid} arrives. Responses are expected
    1.29 -        to arrive in order of message id. When a response arrives,
    1.30 -        waiting responders for messages with lower id have errback
    1.31 -        called with an OutOfOrder error.
    1.32 +        with message id I{mid} arrives.
    1.33  
    1.34          Responders have a timeout set and I{deferred} will error
    1.35          on expiry.
    1.36 @@ -155,10 +147,10 @@ class CtrlMsgRcvr:
    1.37          @return: responder
    1.38          @rtype:  Responder
    1.39          """
    1.40 +        resp = Responder(mid, deferred)
    1.41 +        self.responders[resp.mid] = resp
    1.42          if self.timeout > 0:
    1.43              deferred.setTimeout(self.timeout)
    1.44 -        resp = Responder(mid, deferred)
    1.45 -        self.responders.append(resp)
    1.46          return resp
    1.47  
    1.48      def callResponders(self, msg):
    1.49 @@ -174,18 +166,15 @@ class CtrlMsgRcvr:
    1.50          hdr = msg.get_header()
    1.51          mid = hdr['id']
    1.52          handled = 0
    1.53 -        while self.responders:
    1.54 -            resp = self.responders[0]
    1.55 -            if resp.mid > mid:
    1.56 -                break
    1.57 -            self.responders.pop()
    1.58 -            if resp.mid < mid:
    1.59 -                print 'callResponders> Out of order:', resp.mid, mid
    1.60 -                resp.error(OutOfOrderError())
    1.61 -            else:
    1.62 -                handled = 1
    1.63 -                resp.responseReceived(msg)
    1.64 -                break
    1.65 +        resp = self.responders.get(mid)
    1.66 +        if resp:
    1.67 +            handled = 1
    1.68 +            resp.responseReceived(msg)
    1.69 +            del self.responders[mid]
    1.70 +        # Clean up called responders.
    1.71 +        for resp in self.responders.values():
    1.72 +            if resp.deferred.called:
    1.73 +                del self.responders[resp.mid]
    1.74          return handled
    1.75  
    1.76      def lostChannel(self):