Example #1
0
 def eSendOnReqRep(self, sTopic, sMsg):
     assert sMsg.startswith(sTopic), \
            "eSendOnReqRep: sMsg.startswith(sTopic) failed" + sMsg +" " +sTopic
     if sTopic not in lKNOWN_TOPICS:
         sRetval = "eSendOnReqRep: eSendOnReqRep unhandled topic: " + sTopics + " " + sMess
         vError(sRetval)
         return sRetval
     assert self.oReqRepSocket, "eSendOnReqRep: oReqRepSocket is null"
     try:
         sRetval = self.oReqRepSocket.send(sMsg)
     except zmq.ZMQError as e:
         # iError = zmq.zmq_errno()
         iError = e.errno
         if iError == zmq.EAGAIN:
             time.sleep(1.0)
             sRetval = ""
         else:
             sRetval = zmq.strerror(iError)
             vWarn("eSendOnReqRep: ZMQError: %d %s" % (
                 iError,
                 sRetval,
             ))
             sys.stdout.flush()
     except Exception as e:
         vError("eSendOnReqRep: Failed: " + str(e))
         sys.stdout.flush()
         sRetval = str(e)
     return sRetval
Example #2
0
    def eReturnOnSpeaker(self, sType, sMess, sOrigin):
        """
        """
        if sType not in lKNOWN_TOPICS:
            sRetval = "eReturnOnSpeaker: oSpeakerChannel unhandled topic " + sMess
            vError(sRetval)
            return sRetval

        assert sOrigin, "eReturnOnSpeaker: oSpeakerChannel empty sOrigin"
        lOrigin = sOrigin.split("|")
        assert lOrigin, "eReturnOnSpeaker: oSpeakerChannel empty lOrigin"
        # 'json' was in here
        assert lOrigin[0] in ['eval', 'cmd', 'exec'], \
            "eReturnOnSpeaker: oSpeakerChannel not cmd " +sOrigin
        # This message is a reply in a cmd
        sMark = lOrigin[3]
        assert sMark, "eReturnOnSpeaker: lOrigin[3] is null: " + repr(lOrigin)
        lMess = sMess.split("|")
        assert lMess[0] == 'retval', \
            "eReturnOnSpeaker: lMess[0] should be retval: " +repr(lMess)
        # these now should be equal
        lMess[3] = sMark
        # Replace the mark in the reply with the mark in the cmd
        sMess = '|'.join(lMess)

        return self.eSendOnSpeaker(sType, sMess)
Example #3
0
 def sRecvOnSubPub(self, iFlags=zmq.NOBLOCK):
     if self.oSubPubSocket is None:
         # was self.eBindListener()
         # needs lTopics: self.eConnectToSubPub(lTopics)
         pass
     assert self.oSubPubSocket, "sRecvOnSubPub: oSubPubSocket is null"
     try:
         sRetval = self.oSubPubSocket.recv(flags=iFlags)
     except zmq.ZMQError as e:
         # zmq4: iError = zmq.zmq_errno()
         iError = e.errno
         if iError == zmq.EAGAIN:
             #? This should only occur if iFlags are zmq.NOBLOCK
             time.sleep(1.0)
         else:
             vWarn("sRecvOnSubPub: ZMQError in Recv listener: %d %s" % (
                 iError,
                 zmq.strerror(iError),
             ))
             sys.stdout.flush()
         sRetval = ""
     except Exception as e:
         vError("sRecvOnSubPub: Failed Recv listener: " + str(e))
         sys.stdout.flush()
         sRetval = ""
     return sRetval
Example #4
0
 def eSendOnReqRep(self, sTopic, sMsg):
     assert sMsg.startswith(sTopic), \
            "eSendOnReqRep: sMsg.startswith(sTopic) failed" + sMsg +" " +sTopic
     if sTopic not in lKNOWN_TOPICS:
         sRetval = "eSendOnReqRep: eSendOnReqRep unhandled topic: " +sTopics +" " +sMess
         vError(sRetval)
         return sRetval
     assert self.oReqRepSocket, "eSendOnReqRep: oReqRepSocket is null"
     try:
         sRetval = self.oReqRepSocket.send(sMsg)
     except zmq.ZMQError as e:
         # iError = zmq.zmq_errno()
         iError = e.errno
         if iError == zmq.EAGAIN:
             time.sleep(1.0)
             sRetval = ""
         else:
             sRetval = zmq.strerror(iError)
             vWarn("eSendOnReqRep: ZMQError: %d %s" % (
                 iError, sRetval,))
             sys.stdout.flush()
     except Exception as e:
         vError("eSendOnReqRep: Failed: " +str(e))
         sys.stdout.flush()
         sRetval = str(e)
     return sRetval
Example #5
0
 def sRecvOnReqRep(self, iFlag=zmq.NOBLOCK):
     assert self.oReqRepSocket, "sRecvOnReqRep: oReqRepSocket is null"
     try:
         sRetval = self.oReqRepSocket.recv(flags=iFlag)
     except zmq.ZMQError as e:
         # iError = zmq.zmq_errno()
         iError = e.errno
         if iError == zmq.EAGAIN:
             time.sleep(1.0)
         else:
             vWarn("sRecvOnReqRep: ZMQError in Recv listener: %d %s" % (
                 iError, zmq.strerror(iError),))
             sys.stdout.flush()
         sRetval = ""
     except Exception as e:
         vError("sRecvOnReqRep: Failed Recv listener: " +str(e))
         sys.stdout.flush()
         sRetval = ""
     return sRetval
Example #6
0
 def sRecvOnReqRep(self, iFlag=zmq.NOBLOCK):
     assert self.oReqRepSocket, "sRecvOnReqRep: oReqRepSocket is null"
     try:
         sRetval = self.oReqRepSocket.recv(flags=iFlag)
     except zmq.ZMQError as e:
         # iError = zmq.zmq_errno()
         iError = e.errno
         if iError == zmq.EAGAIN:
             time.sleep(1.0)
         else:
             vWarn("sRecvOnReqRep: ZMQError in Recv listener: %d %s" % (
                 iError,
                 zmq.strerror(iError),
             ))
             sys.stdout.flush()
         sRetval = ""
     except Exception as e:
         vError("sRecvOnReqRep: Failed Recv listener: " + str(e))
         sys.stdout.flush()
         sRetval = ""
     return sRetval
Example #7
0
    def eSendOnSpeaker(self, sType, sMess):
        if sType not in lKNOWN_TOPICS:
            sRetval = "eSendOnSpeaker: oSpeakerChannel unhandled topic " + sMess
            vError(sRetval)
            return sRetval
        if self.oSpeakerChannel is None:
            self.eBindBlockingSpeaker()

        assert self.oSpeakerChannel, "eSendOnSpeaker: oSpeakerChannel is null"
        assert self.oConnection, "eSendOnSpeaker: oConnection is null"

        # we will break the sChartId up into dots from the underscores
        # That way the end consumer can look at the feed selectively
        sPublishingKey = sType + '.' + self.sChartId.replace('_', '.')

        self.oSpeakerChannel.basic_publish(exchange=self.sExchangeName,
                                           routing_key=sPublishingKey,
                                           body=sMess,
                                           mandatory=False,
                                           immediate=False,
                                           properties=self.oProperties)
        vDebug("eSendOnSpeaker: sent " + sMess)
        return ""
Example #8
0
 def sRecvOnSubPub(self, iFlags=zmq.NOBLOCK):
     if self.oSubPubSocket is None:
         # was self.eBindListener()
         # needs lTopics: self.eConnectToSubPub(lTopics)
         pass
     assert self.oSubPubSocket, "sRecvOnSubPub: oSubPubSocket is null"
     try:
         sRetval = self.oSubPubSocket.recv(flags=iFlags)
     except zmq.ZMQError as e:
         # zmq4: iError = zmq.zmq_errno()
         iError = e.errno
         if iError == zmq.EAGAIN:
             #? This should only occur if iFlags are zmq.NOBLOCK
             time.sleep(1.0)
         else:
             vWarn("sRecvOnSubPub: ZMQError in Recv listener: %d %s" % (
                 iError, zmq.strerror(iError),))
             sys.stdout.flush()
         sRetval = ""
     except Exception as e:
         vError("sRecvOnSubPub: Failed Recv listener: " +str(e))
         sys.stdout.flush()
         sRetval = ""
     return sRetval