How to use the pelita.messaging.actor_of function in pelita

To help you get started, we’ve selected a few pelita examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ASPP / pelita / test / test_actor.py View on Github external
def test_raise_no_trap_exit(self):
        collectingActor1 = actor_of(CollectingActor)
        collectingActor1.trap_exit = False
        collectingActor1.start()

        collectingActor2 = actor_of(CollectingActor)
        collectingActor2.trap_exit = False
        collectingActor2.start()

        collectingActor3 = actor_of(CollectingActor)
        collectingActor3.trap_exit = True
        collectingActor3.start()

        collectingActor4 = actor_of(CollectingActor)
        collectingActor4.trap_exit = True
        collectingActor4.start()

        raisingActor = actor_of(RaisingActor)
        raisingActor.link(collectingActor1)
        collectingActor1.link(collectingActor2)
        collectingActor2.link(collectingActor3)
        collectingActor3.link(collectingActor4)

        raisingActor.start()
        raisingActor.notify("Msg")
github ASPP / pelita / test / test_actor.py View on Github external
def test_unhandled(self):
        actor = actor_of(Dispatcher)
        actor.start()

        res = actor.query("unhandled")
        self.assertEqual(type(res.get()), str)

        actor.stop()
github ASPP / pelita / test / test_actor.py View on Github external
def test_remote(self):
        remote = RemoteConnection().start_listener("localhost", 0)
        remote.register("main-actor", actor_of(MultiplyingActor))
        remote.start_all()

        # port is dynamic
        port = remote.listener.socket.port

        client1 = RemoteConnection().actor_for("main-actor", "localhost", port)
        res = client1.query("mult", [1, 2, 3, 4])
        self.assertEqual(res.get(timeout=3), 24)

        # check, that I can use another client
        client2 = RemoteConnection().actor_for("main-actor", "localhost", port)
        res = client2.query("mult", [4, 4, 4])
        self.assertEqual(res.get(timeout=3), 64)

        # check, that the first still works
        res = client1.query("mult", [2, 2, 4])
github ASPP / pelita / test / test_actor.py View on Github external
def test_docstring_request(self):
        actor = actor_of(Dispatcher)
        actor.start()

        res = actor.query("?get_docstring")
        self.assertEqual(res.get(), " This method has no content but a docstring. ")

        actor.stop()
github ASPP / pelita / test / test_actor.py View on Github external
def test_simply_reply(self):
        actor_ref = actor_of(MultiplyingActor)
        actor_ref.start()

        res = actor_ref.query("mult", [1, 2, 3, 4])
        self.assertEqual(res.get(timeout=3), 24)
        actor_ref.stop()
        #assert False
github ASPP / pelita / pelita / actors.py View on Github external
def __init__(self, team_name):
        self.team_name = team_name

        self.actor_ref = actor_of(_ClientActor)
        self.actor_ref._actor.thread.daemon = True # TODO remove this line
        self.actor_ref.start()
github ASPP / pelita / pelita / actors.py View on Github external
def __init__(self, viewer):
        self.actor_ref = actor_of(_ViewerActor)
        self.actor_ref._actor.thread.daemon = True # TODO remove this line
        self.actor_ref.start()
        self._set_viewer(viewer)
github ASPP / pelita / pelita / simplesetup.py View on Github external
def _startup(self):
        """ Instantiates the ServerActor and initialises a new game.
        """
        self.server = actor_of(ServerActor, "pelita-main")

        if self.port is not None:
            if not self.silent:
                print "Starting remote connection on %s:%s" % (self.host, self.port)
            self.remote = RemoteConnection().start_listener(host=self.host, port=self.port)
            self.remote.register("pelita-main", self.server)
            self.remote.start_all()
        else:
            if not self.silent:
                print "Starting actor '%s'" % "pelita-main"
            self.server.start()

        # Begin code for automatic closing the server when a game has run
        # TODO: this is bit of a hack and should be done by linking
        # the actors/remote connection.
github ASPP / pelita / demo / messaging / demo_ping_pong.py View on Github external
import logging
#logging.basicConfig()

remote = True
if remote:

    remote = RemoteConnection().start_listener("localhost", 0)
    remote.register("ping", actor_of(Ping))
    remote.start_all()

    port = remote.listener.socket.port

    ping = RemoteConnection().actor_for("ping", "localhost", port)
else:
    ping = actor_of(Ping)
    ping.start()

pong = actor_of(Pong)
pong.start()

ping.notify("connect", [pong.uuid])
ping.notify("Start")

pong.join()

if remote:
    remote.stop()
else:
    ping.stop()

pong.stop()