summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-15 20:37:05 +0000
committerGerrit Code Review <review@openstack.org>2013-01-15 20:37:05 +0000
commit5ed83aa0797033847fd2f757ce78b3931ce4fcea (patch)
tree5dc400802021ffaae0fb32e6119a781005ba3bed /openstack/common
parent4d38326ef45b0b5301794e00e5fd4c788ccc7fc6 (diff)
parent4a6ef49850336bc8a99f0b93feee0307f0383b1f (diff)
downloadoslo-5ed83aa0797033847fd2f757ce78b3931ce4fcea.tar.gz
oslo-5ed83aa0797033847fd2f757ce78b3931ce4fcea.tar.xz
oslo-5ed83aa0797033847fd2f757ce78b3931ce4fcea.zip
Merge "Rework zmq setup and cleanup"
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/rpc/impl_zmq.py44
1 files changed, 18 insertions, 26 deletions
diff --git a/openstack/common/rpc/impl_zmq.py b/openstack/common/rpc/impl_zmq.py
index 3a88f9f..b3c83ef 100644
--- a/openstack/common/rpc/impl_zmq.py
+++ b/openstack/common/rpc/impl_zmq.py
@@ -76,9 +76,9 @@ zmq_opts = [
]
-# These globals are defined in register_opts(conf),
-# a mandatory initialization call
-CONF = None
+CONF = cfg.CONF
+CONF.register_opts(zmq_opts)
+
ZMQ_CTX = None # ZeroMQ Context, must be global.
matchmaker = None # memoized matchmaker object
@@ -113,7 +113,7 @@ class ZmqSocket(object):
"""
def __init__(self, addr, zmq_type, bind=True, subscribe=None):
- self.sock = ZMQ_CTX.socket(zmq_type)
+ self.sock = _get_ctxt().socket(zmq_type)
self.addr = addr
self.type = zmq_type
self.subscriptions = []
@@ -689,7 +689,7 @@ def _multi_send(method, context, topic, msg, timeout=None, serialize=True,
conf = CONF
LOG.debug(_("%(msg)s") % {'msg': ' '.join(map(pformat, (topic, msg)))})
- queues = matchmaker.queues(topic)
+ queues = _get_matchmaker().queues(topic)
LOG.debug(_("Sending message(s) to: %s"), queues)
# Don't stack if we have no matchmaker results
@@ -757,32 +757,26 @@ def notify(conf, context, topic, msg, **kwargs):
def cleanup():
"""Clean up resources in use by implementation."""
global ZMQ_CTX
- global matchmaker
- matchmaker = None
- ZMQ_CTX.term()
+ if ZMQ_CTX:
+ ZMQ_CTX.term()
ZMQ_CTX = None
+ global matchmaker
+ matchmaker = None
-def register_opts(conf):
- """Registration of options for this driver."""
- #NOTE(ewindisch): ZMQ_CTX and matchmaker
- # are initialized here as this is as good
- # an initialization method as any.
- # We memoize through these globals
+def _get_ctxt():
global ZMQ_CTX
- global matchmaker
- global CONF
-
- if not CONF:
- conf.register_opts(zmq_opts)
- CONF = conf
- # Don't re-set, if this method is called twice.
if not ZMQ_CTX:
- ZMQ_CTX = zmq.Context(conf.rpc_zmq_contexts)
+ ZMQ_CTX = zmq.Context(CONF.rpc_zmq_contexts)
+ return ZMQ_CTX
+
+
+def _get_matchmaker():
+ global matchmaker
if not matchmaker:
# rpc_zmq_matchmaker should be set to a 'module.Class'
- mm_path = conf.rpc_zmq_matchmaker.split('.')
+ mm_path = CONF.rpc_zmq_matchmaker.split('.')
mm_module = '.'.join(mm_path[:-1])
mm_class = mm_path[-1]
@@ -795,6 +789,4 @@ def register_opts(conf):
mm_impl = importutils.import_module(mm_module)
mm_constructor = getattr(mm_impl, mm_class)
matchmaker = mm_constructor()
-
-
-register_opts(cfg.CONF)
+ return matchmaker