summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2012-02-24 14:37:31 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-03-01 09:06:38 +0900
commitd650102e515c620c84c1bebe81df1b19e4c8b07a (patch)
treef0f80b6cb0878d2b668736257e64137d8b812609
parent6b2e6521a33d693200360d70d2a03e48eceb4dfe (diff)
dispatcher: use TrackInstances and kill some WeakValueDictionary
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/app/event_dumper.py2
-rw-r--r--ryu/controller/dispatcher.py20
2 files changed, 4 insertions, 18 deletions
diff --git a/ryu/app/event_dumper.py b/ryu/app/event_dumper.py
index e881c5fd..ca6b5fd5 100644
--- a/ryu/app/event_dumper.py
+++ b/ryu/app/event_dumper.py
@@ -32,7 +32,7 @@ class EventDumper(object):
def __init__(self, *_args, **_kwargs):
# EventDispatcher can be created and cloned before us.
# So register it explicitly
- for ev_q in dispatcher.EventQueue.event_queues.values():
+ for ev_q in dispatcher.EventQueue.all_instances():
if ev_q == dispatcher.QUEUE_EV_Q:
continue
LOG.info('%s: registering q %s dispatcher %s',
diff --git a/ryu/controller/dispatcher.py b/ryu/controller/dispatcher.py
index 8fa5bde8..b42d2877 100644
--- a/ryu/controller/dispatcher.py
+++ b/ryu/controller/dispatcher.py
@@ -18,6 +18,7 @@ import weakref
from gevent.queue import Queue
+from ryu.lib.track_instances import TrackInstances
from . import event
LOG = logging.getLogger('ryu.controller.dispatcher')
@@ -30,13 +31,7 @@ LOG = logging.getLogger('ryu.controller.dispatcher')
# wvd.values() ws: iterator
-class EventQueue(object):
- # WeakValueDictionary: 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.WeakValueDictionary()
-
+class EventQueue(TrackInstances):
# weakref: break circular reference
# self._ev_q_weakref == weakref.ref(self)
_ev_q_weakref = None
@@ -62,7 +57,6 @@ class EventQueue(object):
self.ev_q = Queue()
self.aux = aux # for EventQueueCreate event
- self.event_queues[id(self)] = self
self._queue_q_ev(EventQueueCreate(self, True))
def __del__(self):
@@ -107,13 +101,7 @@ class EventQueue(object):
self.dispatcher(ev)
-class EventDispatcher(object):
- # WeakValueDictionary: 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.WeakValueDictionary()
-
+class EventDispatcher(TrackInstances):
def __init__(self, name):
# WeakValueDictionary: In order to let child to go away.
# We are interested only in alive children.
@@ -122,8 +110,6 @@ class EventDispatcher(object):
self.events = {}
self.all_handlers = []
- self.event_dispatchers[id(self)] = self
-
def clone(self):
cloned = EventDispatcher(self.name)
for ev_cls, h in self.events.items():