On Fri, 22 Feb 2013 19:14:19 +0900
YAMADA Hideki <[email protected]> wrote:

> 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(-)

As we discussed off-line, let's do in the simpler way.

=
>From 31c1449b18cf8c31f8cd9526d9f84645645c0e4e Mon Sep 17 00:00:00 2001
From: FUJITA Tomonori <[email protected]>
Date: Mon, 4 Mar 2013 14:02:07 -0800
Subject: [PATCH] Add request/reply event support

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 <[email protected]>
---
 ryu/base/app_manager.py | 10 ++++++++++
 ryu/controller/event.py | 12 ++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index d977b40..f20b87c 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 59740f5..4d583d9 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
-- 
1.7.12.4 (Apple Git-37)



------------------------------------------------------------------------------
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

Reply via email to