Ejemplo n.º 1
0
Archivo: hive.py Proyecto: gergia/xudd
    def __init__(self, hive_id=None, loop=None):
        # id of the hive
        self.hive_id = hive_id or self.gen_actor_id()

        hive_proxy = self.gen_proxy()
        super(Hive, self).__init__(
            id= join_id(self.hive_id, self.hive_id),
            hive=hive_proxy)
        hive_proxy.associate_with_actor(self)

        # Which actors this hive is managing
        self._actor_registry = {}

        # Note: can we just trust the user to set the right policy?
        self.loop = loop or asyncio.get_event_loop()

        # Objects related to generating unique ids for messages
        self.message_uuid = base64_uuid4()
        self.message_counter = count()

        # Ambassador registry (for inter-hive-communication)
        self._ambassadors = {}

        # Extend message routing
        self.message_routing.update(
            {"register_ambassador": self.register_ambassador,
             "unregister_ambassador": self.unregister_ambassador,
             "create_actor": self.create_actor_handler})

        # Register ourselves on... ourselves ;)
        self.register_actor(self)
Ejemplo n.º 2
0
    def __init__(self, hive_id=None, loop=None):
        # id of the hive
        self.hive_id = hive_id or self.gen_actor_id()

        hive_proxy = self.gen_proxy()
        super(Hive, self).__init__(
            id=join_id("hive", self.hive_id),
            hive=hive_proxy)
        hive_proxy.associate_with_actor(self)

        # Which actors this hive is managing
        self._actor_registry = {}

        # Note: can we just trust the user to set the right policy?
        self.loop = loop or asyncio.get_event_loop()

        # Objects related to generating unique ids for messages
        self.message_uuid = base64_uuid4()
        self.message_counter = count()

        # Ambassador registry (for inter-hive-communication)
        self._ambassadors = {}

        # Extend message routing
        self.message_routing.update(
            {"register_ambassador": self.register_ambassador,
             "unregister_ambassador": self.unregister_ambassador,
             "create_actor": self.create_actor_handler})

        # Register ourselves on... ourselves ;)
        self.register_actor(self)
Ejemplo n.º 3
0
    def setup(self, message):
        # Spawn the remote hive
        self.remote_hive_id = base64_uuid4()
        self.send_queue = Queue()
        self.receive_queue = Queue()
        self.multiproces_hive_proc = Process(
            target=spawn_multiprocess_hive,
            args=(
                self.remote_hive_id,
                # The opposite of our send and receive queue!
                self.send_queue,
                self.receive_queue))
        self.multiproces_hive_proc.start()

        # Declare ourselves the ambassador for this hive
        self.send_message(
            to=join_id("hive", self.hive.hive_id),
            directive="register_ambassador",
            body={
                "hive_id": self.remote_hive_id})

        # Set up the message-checking loop
        self.send_message(
            to=self.id,
            directive="check_message_loop")

        # Tell the child hive to connect back to us
        yield self.wait_on_message(
            to=join_id("hive", self.remote_hive_id),
            directive="connect_back",
            body={"parent_hive_id": self.hive.hive_id})
Ejemplo n.º 4
0
    def setup(self, message):
        # Spawn the remote hive
        self.remote_hive_id = base64_uuid4()
        self.send_queue = Queue()
        self.receive_queue = Queue()
        self.multiproces_hive_proc = Process(
            target=spawn_multiprocess_hive,
            args=(
                self.remote_hive_id,
                # The opposite of our send and receive queue!
                self.send_queue,
                self.receive_queue))
        self.multiproces_hive_proc.start()

        # Declare ourselves the ambassador for this hive
        self.send_message(to=join_id("hive", self.hive.hive_id),
                          directive="register_ambassador",
                          body={"hive_id": self.remote_hive_id})

        # Set up the message-checking loop
        self.send_message(to=self.id, directive="check_message_loop")

        # Tell the child hive to connect back to us
        yield self.wait_on_message(to=join_id("hive", self.remote_hive_id),
                                   directive="connect_back",
                                   body={"parent_hive_id": self.hive.hive_id})
Ejemplo n.º 5
0
Archivo: hive.py Proyecto: cwebber/xudd
    def __init__(self, actor_messages_per_cycle=15):
        super(Hive, self).__init__()

        self._actor_registry = {}

        # Actor queue
        self._actor_queue = deque()
        self._actors_in_queue = set()

        # This is actions for ourself to take, such as checking if an
        # actor should be re-queued, and queueing messages to an actor
        self.hive_action_queue = deque()

        self.should_stop = False

        # Objects related to generating unique ids for messages
        self.message_uuid = base64_uuid4()

        self.message_counter = count()

        # Maximum number of messags
        self.actor_messages_per_cycle = actor_messages_per_cycle
Ejemplo n.º 6
0
 def gen_actor_id(self):
     """
     Generate an actor id.
     """
     return base64_uuid4()
Ejemplo n.º 7
0
def test_base64_unicode():
    assert tools.base64_uuid4() == u"BY84g5NtSWCroZZOux9FhA"
Ejemplo n.º 8
0
def test_base64_unicode():
    assert tools.base64_uuid4() == u"BY84g5NtSWCroZZOux9FhA"
Ejemplo n.º 9
0
Archivo: hive.py Proyecto: gergia/xudd
 def gen_actor_id(self):
     """
     Generate an actor id.
     """
     return base64_uuid4()