Пример #1
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, dataObject(scrubbed))

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

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

        else:
            self.unsubscribe(corrId=corruuid)
Пример #2
0
    def inreq(self, msg):
        corruuid = msg.correlationId
        dataindex = msg.header['dataindex']

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

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

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

        elif hasattr(self, 'reqhandler'):
            self.pubdata[dataindex] = pubData(dataindex, msg.body)
            self.pubdata[dataindex].requesters[msg.replyTo] = corruuid
            self.reqhandler(msg)
Пример #3
0
    def reply(self, dataindex, newdata="", delete=True):
        for requester in self.pubdata[dataindex].requesters:

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

            if newdata:
                msg.body = 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]
Пример #4
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 = dataObject(data)

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

            if key:
                msg = 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":

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

                        self.send(msg)

        if self.pubdata[dataindex].requesters:
            if key:
                msg = 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():
                    msg = d6msg(key=requester,
                                replyTo=self.name,
                                correlationId=self.pubdata[dataindex]
                                .requesters[requester],
                                type="rep",
                                dataindex=dataindex,
                                body=self.pubdata[dataindex].get())
                    self.send(msg)
                    del self.pubdata[dataindex].requesters[requester]