Ejemplo n.º 1
0
 def test_broadcast_sends_message_to_all_actors_of_given_class_name(self):
     ActorRegistry.broadcast({'command': 'foo'}, target_class='AnActor')
     for actor_ref in ActorRegistry.get_by_class(self.AnActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} in received_messages)
     for actor_ref in ActorRegistry.get_by_class(self.BeeActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} not in received_messages)
Ejemplo n.º 2
0
 def test_broadcast_sends_message_to_all_actors_of_given_class_name(self):
     ActorRegistry.broadcast({'command': 'foo'}, target_class='AnActor')
     for actor_ref in ActorRegistry.get_by_class(self.AnActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} in received_messages)
     for actor_ref in ActorRegistry.get_by_class(self.BeeActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} not in received_messages)
Ejemplo n.º 3
0
    def tell(self, message, safe=False):
        """
        Send message to actor without waiting for any response.

        Will generally not block, but if the underlying queue is full it will
        block until a free slot is available.

        :param message: message to send
        :type message: picklable dict

        :raise: :exc:`pykka.ActorDeadError` if actor is not available
        :return: nothing
        """
        if not self.is_alive():
            if safe:
                ActorRegistry.broadcast(DeadMessage(self, message), DeadMessageBox)
            else:
                raise ActorDeadError('%s not found' % self)
        self.actor_inbox.put(message)
Ejemplo n.º 4
0
    def tell(self, message, safe=False):
        """
        Send message to actor without waiting for any response.

        Will generally not block, but if the underlying queue is full it will
        block until a free slot is available.

        :param message: message to send
        :type message: picklable dict

        :raise: :exc:`pykka.ActorDeadError` if actor is not available
        :return: nothing
        """
        if not self.is_alive():
            if safe:
                ActorRegistry.broadcast(DeadMessage(self, message),
                                        DeadMessageBox)
            else:
                raise ActorDeadError('%s not found' % self)
        self.actor_inbox.put(message)
Ejemplo n.º 5
0
 def test_broadcast_sends_message_to_all_actors_if_no_target(self):
     ActorRegistry.broadcast({'command': 'foo'})
     for actor_ref in ActorRegistry.get_all():
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} in received_messages)
Ejemplo n.º 6
0
 def test_broadcast_sends_message_to_all_actors_if_no_target(self):
     ActorRegistry.broadcast({'command': 'foo'})
     for actor_ref in ActorRegistry.get_all():
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} in received_messages)