Beispiel #1
0
    def ch_publish(self, key, message):
        channel, receivers, senders= self.local_channels[key]
        sender, pvalue = message.split(';', 1)
        newmessage = ';'.join((key, pvalue))

        try:
            # This is the linkage part. We send the message to a receiver and
            # send the confirmation of delivery to the sender
            receiver = receivers.pop(0)
            to_receiver = (
                receiver,
                CH_RECEIVED,
                newmessage
            )
            """
            if receiver == self.key:
                self._msgchannel.send(to_receiver)
            else:
                """
            _dstack.send(*to_receiver)

            to_sender = (
                sender,
                CH_DELIVERED,
                key
            )
            #if sender == self.key:
                #self._msgchannel.send(to_sender)
            #else:
            _dstack.send(*to_sender)

        except IndexError:
            #No receivers, block on send
            senders.append((sender, newmessage))
Beispiel #2
0
 def _distribute(self):
     pself = cPickle.dumps(self)
     _dstack.send(
         self.key,
         CH_NEW,
         pself
     )
Beispiel #3
0
 def _distribute(self):
     if self.tasklet:
         cPickled = cPickle.dumps(self.tasklet)
         _dstack.send(
             self.key,
             TASK_NEW, 
             cPickled
         )
         self.tasklet = None
     else:
         raise DStackException("You tried to distribute a proxy")
Beispiel #4
0
    def _distribute_msg(self, msg, *args, **kwargs):
        pargs = cPickle.dumps(args)
        pkwargs = cPickle.dumps(kwargs)
        msg = ';'.join((msg, pargs, pkwargs))

        if node.is_local(self.key):
            node.deliver(self.key, TASK_OP, msg)
        else:
            _dstack.send(
                self.key,
                TASK_OP,
                msg
            )
Beispiel #5
0
 def add_sender(self, ch, value):
     pvalue = cPickle.dumps(value)
     # We join the originating node id to the message so that if it
     # bounces back (ie, we have tasklets subscribed to this channel) we
     # don't deliver the message multiple times. A node can assume that
     # any message that originated at itself has been delivered to all
     # its local subscribers.
     msg = ';'.join((self.key, pvalue))
     _dstack.send(
         ch.key,
         CH_PUBLISH,
         msg
     )
Beispiel #6
0
 def ch_subscribe(self, key, receiver):
     try:
         sender, message = self.local_channels[key][2].pop(0)
         _dstack.send(
             receiver,
             CH_RECEIVED,
             message
         )
         _dstack.send(
             sender,
             CH_DELIVERED,
             key
         )
     except IndexError:
         self.local_channels[key][1].append(receiver)
Beispiel #7
0
 def add_receiver(self, ch):
     _dstack.send(
         ch.key,
         CH_SUBSCRIBE,
         self.key
     )