Ejemplo n.º 1
0
 def _receiveContainer(self, socket):
     msg = None
     rx = MESSAGE.Container()
     try:
         msg = socket.recv_multipart()[-1]
         rx.ParseFromString(msg)
     except Exception as e:
         PathLog.error("%s exception: %s" % (service.name, e))
         PathLog.error("    msg = '%s'" % msg)
     else:
         # ignore all ping messages for now
         if rx.type != TYPES.MT_PING:
             return rx
     return None
Ejemplo n.º 2
0
    def _update(self):
        with self.lock:
            poll = True
            updateServices = True
            # if there is at least one service connected check if there are any messages to process
            while poll:
                # As it turns out the poller most often returns a single pair so we want to call it
                # in a loop to get all pending updates.
                poll = dict(self.Poller.poll(0))
                for socket in poll:
                    msg = None
                    rx = MESSAGE.Container()
                    try:
                        msg = socket.recv_multipart()[-1]
                        rx.ParseFromString(msg)
                    except Exception as e:
                        PathLog.error("%s exception: %s" % (service.name, e))
                        PathLog.error("    msg = '%s'" % msg)
                    else:
                        # ignore all ping messages for now
                        if rx.type != TYPES.MT_PING:
                            #PathLog.debug(rx)
                            processed = False
                            if updateServices:
                                self._updateServicesLocked()
                                updateServices = False
                            for service in self.service.values():
                                if service and service.socket == socket:
                                    service.process(rx)
                                    processed = True
                                    break
                            if not processed:
                                PathLog.debug("unconnected socket? %s" %
                                              socket)

            if (time.monotonic() - self.lastPing) > 0.5:
                if updateServices:
                    self._updateServicesLocked()
                if self.needUpdateJob:
                    self.updateJob()
                for service in self.service.values():
                    if service:
                        service.ping()
                self.lastPing = time.monotonic()
Ejemplo n.º 3
0
 def __init__(self, command):
     self.msg = MESSAGE.Container()
     self.msg.type = command
     self.state = MKCommandStatus.Created