Esempio n. 1
0
    def __init__(self, wrk=None, message=None):
        self.logger = mylog.logstart("tracker_log")

        self.fifo_send = collections.deque()
        self.fifo_recv = collections.deque()

        self.ctx = zmq.Context.instance()
        self.loop = ioloop.IOLoop.instance()

        self.current = None  # most up to date timestamp from camera
        self.routerConnect()
        self.brokerSubscribe()
        self.cameraCreate("camera server")
        self.ctrackerStart()

        if message and wrk:
            message[-2] = self.camera_port
            self.logger.debug("respond to broker, being tracker, from worker sock (: %s" % message)
            wrk.send_multipart(message)  # notify router that role has change
Esempio n. 2
0
    def __init__(self):
        self.logger = mylog.logstart("worker_log")

        self.ctx = zmq.Context.instance()
        self.loop = ioloop.IOLoop.instance()

        brk_sock = self.ctx.socket(zmq.REQ)
        brk_sock.connect("tcp://127.0.0.1:4444")
        self.brk = zmqstream.ZMQStream(brk_sock, self.loop)
        self.brk.on_recv(self.brokerRecv)
        self.brk.on_send(self.brokerSend)

        rtr_sock = self.ctx.socket(zmq.REQ)
        rtr_sock.setsockopt(zmq.IDENTITY, sys.argv[1])
        rtr_sock.connect("tcp://127.0.0.1:9999")
        self.rtr = zmqstream.ZMQStream(rtr_sock, self.loop)
        self.rtr.on_recv(self.routerRecv)
        self.rtr.on_send(self.routerSend)
        self.rtr.send("ready")
        self.loop.start()
Esempio n. 3
0
    def __init__(self):
        self.logger = mylog.logstart('broker_log')
        
	gui_sock = ctx.socket(zmq.REP)
	gui_sock.bind('tcp://*:2222')
	self.gui = zmqstream.ZMQStream(gui_sock, loop)
        self.gui.on_recv(self.guiRecv)
        self.gui.on_send(self.guiSend)

	icm_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
	icm_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
	icm_sock.setblocking(0)
	icm_sock.bind(('', 3333))
	icm_sock.listen(128)
	callback = functools.partial(self.cameraConnect, icm_sock)
	loop.add_handler(icm_sock.fileno(), callback, loop.READ)

	wrk_sock = ctx.socket(zmq.REP)
	wrk_sock.bind('tcp://*:4444')
	self.wrk = zmqstream.ZMQStream(wrk_sock, loop)
        self.wrk.on_recv(self.workerRecv)
        self.wrk.on_send(self.workerSend)
Esempio n. 4
0
    def __init__(self):
        logger = mylog.logstart('router_log')         
         
        ctx = zmq.Context()
        wrk_sock = ctx.socket(zmq.XREP)
        wrk_sock.bind('tcp://127.0.0.1:9999')
        
        trk_sock = ctx.socket(zmq.XREP)
        trk_sock.bind('tcp://127.0.0.1:7777')
        
        available_workers = 0
        workers = []  #avaiable worker's addresses

        poller = zmq.Poller()
        
        poller.register(trk_sock, zmq.POLLIN)
        poller.register(wrk_sock, zmq.POLLIN)

        while True:
            active_socks = dict(poller.poll())

            if wrk_sock in active_socks and active_socks[wrk_sock] == zmq.POLLIN:

               wrk_addr = wrk_sock.recv()
               logger.debug('worker address: %s' % wrk_addr)
               workers.append(wrk_addr)
               available_workers += 1
               logger.debug('workers: %s' % available_workers)

               empty = wrk_sock.recv()
               assert empty == ''
               trk_addr = wrk_sock.recv()
               logger.debug('trk_addr: %s' % trk_addr)

               if trk_addr != 'ready':
                   empty = wrk_sock.recv()
                   assert empty == ''
                   reply = wrk_sock.recv(copy=False)
                   logger.debug('reply: %s' % reply)
                   
                   command = wrk_sock.recv()
                   if command == 'finish':
                       logger.debug('finish worker: %s' % wrk_addr)
                       workers.pop()
                       available_workers -= 1
                   
                   trk_sock.send_multipart([trk_addr, '', wrk_addr, '', reply])

            if available_workers > 0:

                logger.debug('workers are available - polling trackers')
                if trk_sock in active_socks and active_socks[trk_sock] == zmq.POLLIN:
                    logger.debug('activity on trackers')                
	            trk_addr = trk_sock.recv()
                    #logger.debug('trk_addr: %s' % trk_addr)                
	    
  	            empty = trk_sock.recv()
                    #logger.debug('empty?: %s' % empty)                
	            assert empty == ''
  	            request = trk_sock.recv(copy=False)
	            logger.debug('request: %s' % request)
                    image = trk_sock.recv(copy=False)

	            available_workers -= 1 

	            wrk_addr = workers.pop()
	            wrk_sock.send_multipart([wrk_addr, '', trk_addr, '', request, image])  
Esempio n. 5
0
        logger.debug('connection with tracker established')
        self.timestamp = (i for i in xrange(1000))
        t = task.LoopingCall(self.photoReceived)
        t.start(1)
    
    def photoReceived(self):
        try:
            photo='%s\r\n' % str(self.timestamp.next())    
            logger.debug('send photo to tracker %s ' % photo)
            self.transport.write(photo)
        except:
            self.transport.loseConnection()

    def lineReceived(self, data):
        logger.debug(data)

    def connectionLost(self, *args):
        logger.debug('connection lost')

class ICMFactory(protocol.ClientFactory):
    protocol = ICMtoBroker

def newConnection(addr, port, protocol):
    factory = ICMFactory()
    factory.protocol = protocol
    reactor.connectTCP(addr, port, factory)

logger = mylog.logstart('icm_camera')
newConnection('127.0.0.1', 3333, ICMtoBroker)
reactor.run()