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>
This commit is contained in:
Isaku Yamahata 2012-01-31 16:45:01 +09:00 committed by FUJITA Tomonori
parent d6d7c9d6d2
commit 4dd1118b7d
3 changed files with 24 additions and 3 deletions

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

@ -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 = []

@ -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')