Now, direct method calling is used for app-to-app communication, via _CONTEXTS parameters. This patch is more loose coupling way than direct way.
Signed-off-by: YAMADA Hideki <[email protected]> --- ryu/base/app_manager.py | 29 +++++++++++++++++++++++++++++ ryu/controller/event.py | 17 +++++++++++++++++ 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index 1a2567e..922130a 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -24,6 +24,7 @@ from gevent.queue import Queue from ryu import utils from ryu.controller.handler import register_instance from ryu.controller.controller import Datapath +from ryu.controller.event import EventRequestBase, EventReplyBase LOG = logging.getLogger('ryu.base.app_manager') @@ -62,6 +63,7 @@ class RyuApp(object): self.observers = {} self.threads = [] self.events = Queue() + self.replys = Queue() self.threads.append(gevent.spawn(self._event_loop)) def register_handler(self, ev_cls, handler): @@ -82,6 +84,10 @@ class RyuApp(object): def _event_loop(self): while True: ev = self.events.get() + + if isinstance(ev, EventReplyBase): + self.replys.put(ev) + handlers = self.get_handlers(ev) for handler in handlers: handler(ev) @@ -102,6 +108,29 @@ class RyuApp(object): for observer in self.get_observers(ev): self.send_event(observer, ev) + def send_request(self, dst, ev): + assert isinstance(ev, EventRequestBase) + ev.src = self.name + self.send_event(dst, ev) + + def send_reply(self, request, ev): + assert isinstance(request, EventRequestBase) + assert isinstance(ev, EventReplyBase) + ev.src = self.name + ev.xid = request.xid + self.send_event(request.src, ev) + + def recv_reply(self, xid): + # waiting for reply + while True: + reply = self.replys.get() # blocking when empty + if reply.xid == xid: + #LOG.debug('receive reply(xid=%s)', reply.xid) + return reply + else: + #LOG.debug('put off reply(xid=%s)', reply.xid) + self.replys.put(reply) + def close(self): """ teardown method. diff --git a/ryu/controller/event.py b/ryu/controller/event.py index 59740f5..72fc091 100644 --- a/ryu/controller/event.py +++ b/ryu/controller/event.py @@ -18,3 +18,20 @@ class EventBase(object): # Nothing yet pass + + +class EventRequestBase(EventBase): + def __init__(self): + # src is brick name of event source + # This will be set by RyuApp.send_request() + self.src = None + self.xid = id(self) + + +class EventReplyBase(EventBase): + def __init__(self): + # src is brick name of event source + # This will be set by RyuApp.send_reply() + self.src = None + # xid = request.id, will be set by RyuApp.sent_reply() + self.xid = None -- 1.7.1 ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
