fix bidirectional event confusion

EventRequestBase has EventReplyBase

Signed-off-by: Satoshi Kobayashi <satoshi-k@stratosphere.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Satoshi Kobayashi 2014-01-23 16:05:48 +09:00 committed by FUJITA Tomonori
parent f1506fd0ba
commit c9325a22c0
4 changed files with 10 additions and 10 deletions

View File

@ -180,11 +180,12 @@ and block until receiving a reply.
Returns the received reply.
The argument should be an instance of EventRequestBase.
send_reply(self, rep)
reply_to_request(self, req, rep)
`````````````````````
Send a reply for a synchronous request sent by send_request.
The argument should be an instance of EventReplyBase.
The first argument should be an instance of EventRequestBase.
The second argument should be an instance of EventReplyBase.
send_event(self, name, ev)
``````````````````````````

View File

@ -67,7 +67,6 @@ class RyuApp(object):
self.observers = {} # ev_cls -> observer-name -> states:set
self.threads = []
self.events = hub.Queue(128)
self.replies = hub.Queue()
self.logger = logging.getLogger(self.name)
# prevent accidental creation of instances of this class outside RyuApp
@ -121,16 +120,13 @@ class RyuApp(object):
return observers
def send_reply(self, rep):
assert isinstance(rep, EventReplyBase)
SERVICE_BRICKS[rep.dst].replies.put(rep)
def send_request(self, req):
assert isinstance(req, EventRequestBase)
req.sync = True
req.reply_q = hub.Queue()
self.send_event(req.dst, req)
# going to sleep for the reply
return self.replies.get()
return req.reply_q.get()
def _event_loop(self):
while self.is_active or not self.events.empty():
@ -160,9 +156,11 @@ class RyuApp(object):
self.send_event(observer, ev, state)
def reply_to_request(self, req, rep):
assert isinstance(req, EventRequestBase)
assert isinstance(rep, EventReplyBase)
rep.dst = req.src
if req.sync:
self.send_reply(rep)
req.reply_q.put(rep)
else:
self.send_event(rep.dst, rep)

View File

@ -26,6 +26,7 @@ class EventRequestBase(EventBase):
self.dst = None # app.name of provide the event.
self.src = None
self.sync = False
self.reply_q = None
class EventReplyBase(EventBase):

View File

@ -174,7 +174,7 @@ class EventVRRPConfigRequest(event.EventRequestBase):
class EventVRRPConfigReply(event.EventReplyBase):
def __init__(self, instance_name, interface, config):
# dst = None. dst is filled by app_base.RyuApp.send_reply()
# dst = None. dst is filled by app_base.RyuApp#reply_to_request()
super(EventVRRPConfigReply, self).__init__(None)
self.instance_name = instance_name # None means failure
self.interface = interface