Esempio n. 1
0
        static void Main(string[] args)
        {
            string lName = "";
            string lPort = "";

            if (args.Length > 0)
            {
                lName = args.FirstOrDefault(t => t.StartsWith("-n:"));
                lPort = args.FirstOrDefault(t => t.StartsWith("-p:"));
            }
            if (!string.IsNullOrEmpty(lName))
            {
                lName = lName.Replace("-n:", "");
            }
            else
            {
                lName = "ARnActorServer";
            }

            if (!String.IsNullOrEmpty(lPort))
            {
                lPort = lPort.Replace("-p:", "");
            }
            else
            {
                lPort = "80";
            }

            ActorServer.Start(lName, int.Parse(lPort), new HostRelayActor());
            IActor fMain = new ActorMain();

            // new actActionReceiver().ConsoleWrite("Welcome in an action world");

            //var Input = new SDRInput("Machine") ;
            //var Region = new HTMRegion(Input);

            string s = string.Empty;

            do
            {
                s = Console.ReadLine();
                if (!string.IsNullOrEmpty(s))
                {
                    switch (s)
                    {
                    case "Many": { fMillion = new actMillion(); break; }

                    case "SendMany": { fMillion.Send(); break; }

                    case "quit": break;

                    case "Col":
                    {
                        var fLauncher = new TestLauncherActor();
                        fLauncher.SendAction(() =>
                            {
                                var collect = new CollectionActor <string>();
                                for (int i = 0; i < 100; i++)
                                {
                                    collect.Add(string.Format("Test {0}", i));
                                }
                                if (collect.Count() != 100)
                                {
                                    throw new Exception("failed");
                                }
                                // try to enum
                                var enumerable = collect.ToList();
                                if (enumerable.Count != 100)
                                {
                                    throw new ActorException("failed");
                                }
                                // try a query
                                var query = from col in collect
                                            where col.Contains('1')
                                            select col;
                                if (query.Count() != 19)
                                {
                                    throw new ActorException("failed");
                                }
                                fLauncher.Finish();
                            });
                        fLauncher.Wait();
                        break;
                    }

                    case "Ring":
                    {
                        new RingActor(10000, 10000);         // 30 sec
                        break;
                    }

                    case "Rings":
                    {
                        Console.Write("Enter ring size : ");
                        var rs = Console.ReadLine();
                        Console.Write("Enter cycle : ");
                        var cy = Console.ReadLine();
                        int.TryParse(rs, out int r);
                        int.TryParse(cy, out int y);
                        new RingActor(y, r);         // 30 sec
                        break;
                    }

                    case "Clients":
                    {
                        var    start   = DateTime.UtcNow.Ticks;
                        IActor aServer = new EchoServerActor();
                        for (int i = 0; i < 1000; i++)
                        {
                            EchoClientActor aClient = new EchoClientActor();        // new actEchoClient(aServer);
                                                                                    // DirectoryRequest.SendRegister("client + " + i.ToString(), aClient);
                            aClient.Connect("EchoServer");
                            aClient.SendMessage("client-" + i.ToString());
                            // aClient.Disconnect();
                        }
                        var end = DateTime.UtcNow.Ticks;
                        Console.WriteLine("All client allocated {0}", (double)(end - start) / 10000.0);
                        break;
                    }

                    case "Download":
                    {
                        Console.WriteLine("trying Download");
                        IActor down = new ActorDownloadTest();
                        break;
                    }

                    //case "Brain":
                    //    {
                    //        Console.Write("Enter word : ");
                    //        var s2 = Console.ReadLine();
                    //        Input.SetData(s2);
                    //        Region.Run();
                    //        Region.Print();
                    //        break;
                    //    }
                    //case "Learn":
                    //    {
                    //        Input.SetData("Hello world ! ") ;
                    //        for (int i = 0; i < 100; i++)
                    //        {
                    //            Region.Run();
                    //            Region.Print();
                    //        }
                    //        break;
                    //    }
                    case "Pricing":
                    {
                        new ActorScheduler();
                        break;
                    }

                    case "ParserTest":
                    {
                        new EchoActor(new ParserTest(), "");
                        break;
                    }

                    default:
                    {
                        new EchoActor(new ActorAdminServer(), s);
                        break;
                    }
                    }
                }
            } while (s != "quit");
        }
Esempio n. 2
0
        private void DoBehavior(string msg)
        {
            Console.WriteLine("Serv Start");
            var start = DateTime.UtcNow.Ticks;

            collect = new CollectionActor <string>();
            var list = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                collect.Add(i.ToString(CultureInfo.InvariantCulture));
                list.Add(i.ToString(CultureInfo.InvariantCulture));
            }

            foreach (var item in collect)
            {
                Console.WriteLine("Collect " + item);
            }

            var actForeach = new BaseActor(new ForEachBehavior <string>());

            actForeach.SendMessage <IEnumerable <string>, Action <String> >(list,
                                                                            t => Console.WriteLine("list " + t));


            Console.WriteLine("Should have work");

            var linkedlist = new LinkedListActor <string>();

            for (int i = 0; i < 100; i++)
            {
                linkedlist.SendMessage(LinkedListOperation.Add, i.ToString());
            }

            new EchoActor <Tuple <LinkedListOperation, string> >(linkedlist, Tuple.Create(LinkedListOperation.First, "5"));

            new RingActor(1000, 1000); // 10 sec

            new LinkedListActor <string>();

            IActor aServer = new EchoServerActor();

            clientList = new List <IActor>();
            for (int i = 0; i < 100; i++)
            {
                EchoClientActor aClient = new EchoClientActor();// new actEchoClient(aServer);
                // DirectoryRequest.SendRegister("client + " + i.ToString(), aClient);
                aClient.Connect("EchoServer");
                aClient.SendMessage("client-" + i.ToString(CultureInfo.InvariantCulture));
                clientList.Add(aClient);
                // aClient.Disconnect();
            }
            var end = DateTime.UtcNow.Ticks;

            Console.WriteLine("All client allocated {0}", (double)(end - start) / 10000.0);

            // basic redirection
            IActor target = new BaseActor(new Behavior <string>(t => { Console.WriteLine(t); }));
            IActor middle = new BaseActor(new Behavior <string>(t => { t = t + " augmenté"; }));

            middle.SendMessage("Bonjour");


            // dynamic use DLR to handle the send / dispatch business ...
            dynamic test = new ExpandoObject();
            dynamic dyn  = new DynamicActor(test);

            test.PrintSomething = (Action <string>)((t) => Console.WriteLine(t));
            dyn.PrintSomething("Got it !");
        }
Esempio n. 3
0
        private void DoBehavior(string msg)
        {
            Console.WriteLine(ServerStart);
            long start = DateTime.UtcNow.Ticks;

            _collect = new CollectionActor <string>();
            List <string> list = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                _collect.Add(i.ToString(CultureInfo.InvariantCulture));
                list.Add(i.ToString(CultureInfo.InvariantCulture));
            }

            foreach (string item in _collect)
            {
                Console.WriteLine("Collect " + item);
            }

            BaseActor actForeach = new BaseActor(new ForEachBehavior <string>());

            actForeach.SendMessage <IEnumerable <string>, Action <String> >(list,
                                                                            t => Console.WriteLine("list " + t));

            Console.WriteLine("Should have work");

            LinkedListActor <string> linkedlist = new LinkedListActor <string>();

            for (int i = 0; i < 100; i++)
            {
                linkedlist.SendMessage(LinkedListOperation.Add, i.ToString());
            }

            new EchoActor <Tuple <LinkedListOperation, string> >(linkedlist, Tuple.Create(LinkedListOperation.First, "5"));

            new RingActor(1000, 1000); // 10 sec

            new LinkedListActor <string>();

            IActor aServer = new EchoServerActor();

            _clientList = new List <IActor>();
            for (int i = 0; i < 100; i++)
            {
                EchoClientActor aClient = new EchoClientActor();// new actEchoClient(aServer);
                // DirectoryRequest.SendRegister("client + " + i.ToString(), aClient);
                aClient.Connect("EchoServer");
                aClient.SendMessage("client-" + i.ToString(CultureInfo.InvariantCulture));
                _clientList.Add(aClient);
                // aClient.Disconnect();
            }
            long end = DateTime.UtcNow.Ticks;

            Console.WriteLine("All client allocated {0}", (end - start) / 10000.0);

            // basic redirection
            IActor target = new BaseActor(new Behavior <string>(t => Console.WriteLine(t)));
            IActor middle = new BaseActor(new Behavior <string>(t => t += " augmenté"));

            middle.SendMessage("Bonjour");
        }