示例#1
0
        public void SendMessageToActor()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; wait.Set(); });

            ActorSystem system = new ActorSystem();
            var         server = new TcpServer("localhost", 3000, system);

            var result = system.ActorOf(actor, "myactor");
            var path   = result.Path.ToString();

            server.Start();

            var client = new System.Net.Sockets.TcpClient();

            client.Connect("localhost", 3000);
            var channel = new OutputChannel(new System.IO.BinaryWriter(client.GetStream()));

            channel.Write(path);
            channel.Write(1);

            wait.WaitOne();

            Assert.AreEqual(1, total);

            client.Close();
            server.Stop();
            system.Shutdown();
        }
示例#2
0
        public void SendMessagesToActor()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; if (total >= 6)
                                                 {
                                                     wait.Set();
                                                 }
                                          });

            ActorSystem system = new ActorSystem();
            var         server = new TcpServer("localhost", 3003, system);

            var result = system.ActorOf(actor, "myactor");
            var path   = result.Path.ToString();

            server.Start();

            var client = new TcpClient("localhost", 3003);

            client.Start();
            client.Tell(path, 1);
            client.Tell(path, 2);
            client.Tell(path, 3);

            wait.WaitOne();

            Assert.AreEqual(6, total);

            client.Stop();
            server.Stop();
            system.Shutdown();
        }
示例#3
0
        public void SendMessagesToRemoteActor()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; if (total >= 6)
                                                 {
                                                     wait.Set();
                                                 }
                                          });

            ActorSystem remotesystem = new ActorSystem();
            var         server       = new TcpServer("localhost", 3005, remotesystem);

            var result = remotesystem.ActorOf(actor, "myactor");
            var path   = result.Path.ToString();

            server.Start();

            var system    = new ActorSystem();
            var remoteref = system.ActorSelect("aktores.tcp://sys@localhost:3005/myactor");

            remoteref.Tell(1);
            remoteref.Tell(2);
            remoteref.Tell(3);

            wait.WaitOne();

            Assert.AreEqual(6, total);

            system.Shutdown();
            server.Stop();
            remotesystem.Shutdown();
        }
示例#4
0
        public void SendMessageToActor()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; wait.Set(); });

            ActorSystem system = new ActorSystem();
            var         client = new InProcessClient(system);

            var result = system.ActorOf(actor, "myactor");
            var path   = result.Path.ToString();

            client.Tell(path, 1);

            wait.WaitOne();

            Assert.AreEqual(1, total);
            system.Shutdown();
        }
示例#5
0
        public void CreateRouterAndSendMessageToActor()
        {
            ActorSystem system = new ActorSystem();

            int             total    = 0;
            EventWaitHandle wait     = new AutoResetEvent(false);
            Actor           actor    = new LambdaActor(c => { total += (int)c; wait.Set(); });
            var             actorref = system.ActorOf(actor, "myactor");

            var router = new RouterActor();

            router.Register(actorref);
            var routerref = system.ActorOf(router, "myrouter");

            routerref.Tell(3);

            Assert.IsTrue(wait.WaitOne(1000));
            Assert.AreEqual(3, total);

            system.Shutdown();
        }
示例#6
0
        public void CreateRouterAndSendMessageToActors()
        {
            ActorSystem system = new ActorSystem();

            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            var router    = new RouterActor();
            var routerref = system.ActorOf(router, "myrouter");

            for (int k = 0; k < 100; k++)
            {
                Actor actor = new LambdaActor(c =>
                {
                    lock (system)
                    {
                        total += (int)c;
                    }

                    if (total >= 10)
                    {
                        wait.Set();
                    }
                });

                var actorref = system.ActorOf(actor);
                router.Register(actorref);
            }

            routerref.Tell(1);
            routerref.Tell(2);
            routerref.Tell(3);
            routerref.Tell(4);

            Assert.IsTrue(wait.WaitOne(1000));
            Assert.AreEqual(10, total);

            system.Shutdown();
        }