summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2012-01-31 16:45:01 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-02-01 08:55:35 +0900
commit4dd1118b7df7fa4c0b729d1fcf24f18284af6c6f (patch)
treefc7569aaa8e3410e190c2bd0cfd1a39ed442224a
parentd6d7c9d6d2dd319c772b08fab39b94c6a068be53 (diff)
dispatcher: pass name to EventQueue and track all instances
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/controller/controller.py3
-rw-r--r--ryu/controller/dispatcher.py23
-rw-r--r--ryu/controller/handler.py1
3 files changed, 24 insertions, 3 deletions
diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index eb33dba2..27f07be7 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -80,7 +80,8 @@ class Datapath(object):
self.recv_q = Queue()
self.send_q = Queue()
- self.ev_q = dispatcher.EventQueue(handler.handshake_dispatcher)
+ self.ev_q = dispatcher.EventQueue(handler.QUEUE_NAME_OFP_MSG,
+ handler.handshake_dispatcher)
self.version_sent = None
self.version_recv = None
diff --git a/ryu/controller/dispatcher.py b/ryu/controller/dispatcher.py
index d8ede934..1768a136 100644
--- a/ryu/controller/dispatcher.py
+++ b/ryu/controller/dispatcher.py
@@ -12,16 +12,27 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
import copy
import logging
+import weakref
+
from gevent.queue import Queue
+
LOG = logging.getLogger('ryu.controller.dispatcher')
class EventQueue(object):
- def __init__(self, dispatcher):
+ # WeakSet: This set is populated by __init__().
+ # So need to use weak reference in order to make instances
+ # freeable by avoiding refrence count.
+ # Otherwise, instances can't be freed.
+ event_queues = weakref.WeakSet()
+
+ def __init__(self, name, dispatcher):
+ self.event_queues.add(self)
+
+ self.name = name
self.dispatcher = dispatcher
self.is_dispatching = False
self.ev_q = Queue()
@@ -58,7 +69,15 @@ class EventQueue(object):
class EventDispatcher(object):
+ # WeakSet: This set is populated by __init__().
+ # So need to use weak reference in order to make instances
+ # freeable by avoiding refrence count.
+ # Otherwise, instances can't be freed.
+ event_dispatchers = weakref.WeakSet()
+
def __init__(self, name):
+ self.event_dispatchers.add(self)
+
self.name = name
self.events = {}
self.all_handlers = []
diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py
index a56080b4..744af898 100644
--- a/ryu/controller/handler.py
+++ b/ryu/controller/handler.py
@@ -24,6 +24,7 @@ from ryu.lib.mac import haddr_to_bin
LOG = logging.getLogger('ryu.controller.handler')
+QUEUE_NAME_OFP_MSG = 'ofp_msg'
handshake_dispatcher = dispatcher.EventDispatcher('handshake')
config_dispatcher = dispatcher.EventDispatcher('config')
main_dispatcher = dispatcher.EventDispatcher('main')