Forwarding device for the plugins.

Dont't subscribe to all drivers if there is no running plugins.

Change-Id: Ia65eb4e7df2015038883e77ab20eae37f04e2f97
This commit is contained in:
François Rossigneux 2013-06-13 13:54:57 +02:00
parent c474fe79d3
commit 8171e22445
2 changed files with 17 additions and 7 deletions

View File

@ -17,6 +17,7 @@
import sys
import signal
import thread
from oslo.config import cfg
@ -29,7 +30,7 @@ if __name__ == "__main__":
default_config_files=['/etc/kwapi/drivers.conf'])
log.setup('kwapi')
driver_manager.start_zmq_server()
thread.start_new_thread(driver_manager.start_zmq_server, ())
driver_manager.load_all_drivers()
driver_manager.check_drivers_alive()

View File

@ -110,12 +110,21 @@ def start_zmq_server():
"""Forwards probe values to the probes_endpoint."""
context = zmq.Context.instance()
context.set(zmq.MAX_SOCKETS, 100000)
frontend = context.socket(zmq.SUB)
frontend.bind('inproc://drivers')
frontend.setsockopt(zmq.SUBSCRIBE, '')
backend = context.socket(zmq.PUB)
backend.bind(cfg.CONF.probes_endpoint)
thread.start_new_thread(zmq.device, (zmq.FORWARDER, frontend, backend))
frontend = context.socket(zmq.XPUB)
frontend.bind(cfg.CONF.probes_endpoint)
backend = context.socket(zmq.XSUB)
backend.bind('inproc://drivers')
poll = zmq.Poller()
poll.register(frontend, zmq.POLLIN)
poll.register(backend, zmq.POLLIN)
while True:
items = dict(poll.poll(1000))
if items.get(backend) == zmq.POLLIN:
msg = backend.recv_multipart()
frontend.send_multipart(msg)
elif items.get(frontend) == zmq.POLLIN:
msg = frontend.recv()
backend.send(msg)
def signal_handler(signum, frame):