Ejemplo n.º 1
0
    def inreq(self, msg):
        corruuid = msg.correlationId
        dataindex = msg.header['dataindex']

        if dataindex == "pubdata":
            newmsg = d6message.d6msg(key=msg.replyTo,
                                     replyTo=self.name,
                                     correlationId=msg.correlationId,
                                     type="rep",
                                     dataindex=dataindex,
                                     body=dataobj.dataObject(self.pubdata))
            self.send(newmsg)

        elif dataindex == "subdata":
            newmsg = d6message.d6msg(key=msg.replyTo,
                                     replyTo=self.name,
                                     correlationId=msg.correlationId,
                                     type="rep",
                                     dataindex=dataindex,
                                     body=dataobj.dataObject(self.subdata))
            self.send(newmsg)

        elif dataindex in self.pubdata:
            reply = d6message.d6msg(replyTo=self.name,
                                    type="rep",
                                    body=self.pubdata[dataindex].get(),
                                    srcmsg=msg)
            self.send(reply)

        elif hasattr(self, 'reqhandler'):
            self.pubdata[dataindex] = dataobj.pubData(dataindex, msg.body)
            self.pubdata[dataindex].requesters[msg.replyTo] = corruuid
            self.reqhandler(msg)
Ejemplo n.º 2
0
    def inpubrep(self, msg):
        self.log_debug("received PUBREP msg: %s", msg)
        corruuid = msg.correlationId
        sender = msg.replyTo

        if corruuid in self.subdata:
            callback = self.subdata[corruuid].callback

            if msg.type == 'pub':
                if callback:
                    scrubbed = callback(msg)
                    if scrubbed:
                        self.subdata[corruuid].update(
                            sender, dataobj.dataObject(scrubbed))

            elif msg.type == 'rep':
                if callback:
                    scrubbed = callback(msg)
                    if scrubbed:
                        self.subdata[corruuid].update(
                            sender, dataobj.dataObject(scrubbed))

#             if corruuid not in self.scheduuids:
#                 del self.subdata[corruuid]

        else:
            self.unsubscribe(corrId=corruuid)
Ejemplo n.º 3
0
    def inpubrep(self, msg):
        # self.log_debug("received PUBREP msg: %s", msg)
        corruuid = msg.correlationId
        sender = msg.replyTo

        if corruuid in self.subdata:
            callback = self.subdata[corruuid].callback

            if msg.type == "pub":
                if callback:
                    scrubbed = callback(msg)
                    if scrubbed:
                        self.subdata[corruuid].update(sender, dataobj.dataObject(scrubbed))

            elif msg.type == "rep":
                if callback:
                    scrubbed = callback(msg)
                    if scrubbed:
                        self.subdata[corruuid].update(sender, dataobj.dataObject(scrubbed))

        #             if corruuid not in self.scheduuids:
        #                 del self.subdata[corruuid]

        else:
            self.unsubscribe(corrId=corruuid)
Ejemplo n.º 4
0
    def inreq(self, msg):
        corruuid = msg.correlationId
        dataindex = msg.header["dataindex"]

        if dataindex == "pubdata":
            newmsg = d6message.d6msg(
                key=msg.replyTo,
                replyTo=self.name,
                correlationId=msg.correlationId,
                type="rep",
                dataindex=dataindex,
                body=dataobj.dataObject(self.pubdata),
            )
            self.send(newmsg)

        elif dataindex == "subdata":
            newmsg = d6message.d6msg(
                key=msg.replyTo,
                replyTo=self.name,
                correlationId=msg.correlationId,
                type="rep",
                dataindex=dataindex,
                body=dataobj.dataObject(self.subdata),
            )
            self.send(newmsg)

        elif hasattr(self, "reqhandler"):
            self.pubdata[dataindex] = dataobj.pubData(dataindex, msg.body)
            self.pubdata[dataindex].requesters[msg.replyTo] = corruuid
            self.reqhandler(msg)

        else:
            self.log_exception("Received a request but have no handler: %s", msg)
Ejemplo n.º 5
0
    def inreq(self, msg):
        corruuid = msg.correlationId
        dataindex = msg.header['dataindex']

        if dataindex == "pubdata":
            newmsg = d6message.d6msg(key=msg.replyTo,
                                     replyTo=self.name,
                                     correlationId=msg.correlationId,
                                     type="rep",
                                     dataindex=dataindex,
                                     body=dataobj.dataObject(self.pubdata))
            self.send(newmsg)

        elif dataindex == "subdata":
            newmsg = d6message.d6msg(key=msg.replyTo,
                                     replyTo=self.name,
                                     correlationId=msg.correlationId,
                                     type="rep",
                                     dataindex=dataindex,
                                     body=dataobj.dataObject(self.subdata))
            self.send(newmsg)

        elif dataindex in self.pubdata:
            reply = d6message.d6msg(replyTo=self.name,
                                    type="rep",
                                    body=self.pubdata[dataindex].get(),
                                    srcmsg=msg)
            self.send(reply)

        elif hasattr(self, 'reqhandler'):
            self.pubdata[dataindex] = dataobj.pubData(dataindex, msg.body)
            self.pubdata[dataindex].requesters[msg.replyTo] = corruuid
            self.reqhandler(msg)
Ejemplo n.º 6
0
    def reply(self, dataindex, newdata="", delete=True):
        for requester in self.pubdata[dataindex].requesters:

            msg = d6message.d6msg(
                key=requester,
                replyTo=self.name,
                correlationId=self.pubdata[dataindex].requesters[requester],
                type="rep",
                dataindex=self.pubdata[dataindex].dataindex)

            if newdata:
                msg.body = dataobj.dataObject(newdata)
            else:
                msg.body = self.pubdata[dataindex].get()
            self.log_debug("REPLY body: %s", msg.body)

            self.send(msg)

        if delete:

            del self.pubdata[dataindex]
Ejemplo n.º 7
0
    def reply(self, dataindex, newdata="", delete=True):
        for requester in self.pubdata[dataindex].requesters:

            msg = d6message.d6msg(key=requester,
                                  replyTo=self.name,
                                  correlationId=self.pubdata[dataindex]
                                  .requesters[requester],
                                  type="rep",
                                  dataindex=self.pubdata[dataindex].dataindex)

            if newdata:
                msg.body = dataobj.dataObject(newdata)
            else:
                msg.body = self.pubdata[dataindex].get()
            # self.log_debug("REPLY body: %s", msg.body)

            self.send(msg)

        if delete:

            del self.pubdata[dataindex]
Ejemplo n.º 8
0
    def push(self, dataindex, key="", type=None):
        """Send data for DATAINDEX and KEY to subscribers/requesters."""
        self.log_debug(
            "pushing dataindex %s to subscribers %s "
            "and requesters %s ", dataindex,
            self.pubdata[dataindex].subscribers,
            self.pubdata[dataindex].requesters)

        # bail out if there are no requesters/subscribers
        if (len(self.pubdata[dataindex].requesters) == 0
                and len(self.pubdata[dataindex].subscribers) == 0):
            self.log_debug("no requesters/subscribers; not sending")
            return

        # give prepush hook chance to morph data
        if self.reserved_dataindex(dataindex):
            data = self.pubdata[dataindex].get()
            # bail out if no data to send
            if data is None:
                return
        else:
            # .get() returns dataObject
            data = self.prepush_processor(self.pubdata[dataindex].get().data,
                                          dataindex,
                                          type=type)
            # bail out if prepush hook said there's no data
            if data is None:
                return
            data = dataobj.dataObject(data)

        # send to subscribers/requestors
        if self.pubdata[dataindex].subscribers:

            if key:
                msg = d6message.d6msg(
                    key=key,
                    replyTo=self.name,
                    correlationId=self.pubdata[dataindex].subscribers[key]
                    ['correlationId'],
                    type="pub",
                    dataindex=dataindex,
                    body=data)
                self.send(msg)
            else:
                subscribers = self.pubdata[dataindex].getsubscribers()
                for subscriber in subscribers:

                    if subscribers[subscriber]['type'] == "push":
                        corId = subscribers[subscriber]['correlationId']
                        msg = d6message.d6msg(key=subscriber,
                                              replyTo=self.name,
                                              correlationId=corId,
                                              type="pub",
                                              dataindex=dataindex,
                                              body=data)

                        self.send(msg)

        if self.pubdata[dataindex].requesters:
            if key:
                msg = d6message.d6msg(
                    key=key,
                    replyTo=self.name,
                    correlationId=self.pubdata[dataindex].requesters[key],
                    type="rep",
                    dataindex=dataindex,
                    body=self.pubdata[dataindex].get())
                self.send(msg)
                del self.pubdata[dataindex].requesters[key]
            else:
                for requester in self.pubdata[dataindex].requesters.keys():
                    corId = self.pubdata[dataindex].requesters[requester]
                    msg = d6message.d6msg(key=requester,
                                          replyTo=self.name,
                                          correlationId=corId,
                                          type="rep",
                                          dataindex=dataindex,
                                          body=self.pubdata[dataindex].get())
                    self.send(msg)
                    del self.pubdata[dataindex].requesters[requester]
Ejemplo n.º 9
0
    def push(self, dataindex, key="", type=None):
        """Send data for DATAINDEX and KEY to subscribers/requesters."""
        self.log_debug(
            "pushing dataindex %s to subscribers %s " "and requesters %s ",
            dataindex,
            self.pubdata[dataindex].subscribers,
            self.pubdata[dataindex].requesters,
        )

        # bail out if there are no requesters/subscribers
        if len(self.pubdata[dataindex].requesters) == 0 and len(self.pubdata[dataindex].subscribers) == 0:
            self.log_debug("no requesters/subscribers; not sending")
            return

        # give prepush hook chance to morph data
        if self.reserved_dataindex(dataindex):
            data = self.pubdata[dataindex].get()
            # bail out if no data to send
            if data is None:
                return
        else:
            # .get() returns dataObject
            data = self.prepush_processor(self.pubdata[dataindex].get().data, dataindex, type=type)
            # bail out if prepush hook said there's no data
            if data is None:
                return
            data = dataobj.dataObject(data)

        # send to subscribers/requestors
        if self.pubdata[dataindex].subscribers:

            if key:
                msg = d6message.d6msg(
                    key=key,
                    replyTo=self.name,
                    correlationId=self.pubdata[dataindex].subscribers[key]["correlationId"],
                    type="pub",
                    dataindex=dataindex,
                    body=data,
                )
                self.send(msg)
            else:
                subscribers = self.pubdata[dataindex].getsubscribers()
                for subscriber in subscribers:

                    if subscribers[subscriber]["type"] == "push":
                        corId = subscribers[subscriber]["correlationId"]
                        msg = d6message.d6msg(
                            key=subscriber,
                            replyTo=self.name,
                            correlationId=corId,
                            type="pub",
                            dataindex=dataindex,
                            body=data,
                        )

                        self.send(msg)

        if self.pubdata[dataindex].requesters:
            if key:
                msg = d6message.d6msg(
                    key=key,
                    replyTo=self.name,
                    correlationId=self.pubdata[dataindex].requesters[key],
                    type="rep",
                    dataindex=dataindex,
                    body=self.pubdata[dataindex].get(),
                )
                self.send(msg)
                del self.pubdata[dataindex].requesters[key]
            else:
                for requester in self.pubdata[dataindex].requesters.keys():
                    corId = self.pubdata[dataindex].requesters[requester]
                    msg = d6message.d6msg(
                        key=requester,
                        replyTo=self.name,
                        correlationId=corId,
                        type="rep",
                        dataindex=dataindex,
                        body=self.pubdata[dataindex].get(),
                    )
                    self.send(msg)
                    del self.pubdata[dataindex].requesters[requester]