diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-03-05 07:34:27 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-03-05 20:56:55 +0900 |
commit | d8625d4f8fc59a41650c0088a160fb490ef389b1 (patch) | |
tree | a599dbf5d5a3e799fd858615a6a5bc131419d772 | |
parent | 99755c21232bbc61a73c3cc2845ef91f2028d6ff (diff) |
Add request/reply event support to support communication between apps
What most of applications need to do is:
1) register a handler to catch a specific event
2) The handler does multiple asynchronous tasks (query dbs, configures
switches, etc).
2) can be implemented in an asynchronous way, that is sending multiple
requests at the same time. However, I don't think most of developers
need to do or want to do. The API to handle multiple asynchrnous tasks
in a synchronous way is more handy.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/base/app_manager.py | 10 | ||||
-rw-r--r-- | ryu/controller/event.py | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index d977b409..f20b87cc 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -62,6 +62,7 @@ class RyuApp(object): self.observers = {} self.threads = [] self.events = Queue() + self.replies = Queue() self.threads.append(gevent.spawn(self._event_loop)) def register_handler(self, ev_cls, handler): @@ -84,6 +85,15 @@ class RyuApp(object): return observers + def send_reply(self, rep): + SERVICE_BRICKS[rep.dst].replies.put(rep) + + def send_request(self, req): + req.src = self.name + self.send_event(req.dst, req) + # going to sleep for the reply + return self.replies.get() + def _event_loop(self): while True: ev = self.events.get() diff --git a/ryu/controller/event.py b/ryu/controller/event.py index 59740f51..4d583d9d 100644 --- a/ryu/controller/event.py +++ b/ryu/controller/event.py @@ -18,3 +18,15 @@ class EventBase(object): # Nothing yet pass + + +class EventRequestBase(EventBase): + def __init__(self, dst): + super(EventRequestBase, self).__init__() + self.dst = dst + + +class EventReplyBase(EventBase): + def __init__(self, dst): + super(EventReplyBase, self).__init__() + self.dst = dst |