當前位置: 首頁>>代碼示例>>C#>>正文


C# ActorSystem.CreateActor方法代碼示例

本文整理匯總了C#中ActorSystem.CreateActor方法的典型用法代碼示例。如果您正苦於以下問題:C# ActorSystem.CreateActor方法的具體用法?C# ActorSystem.CreateActor怎麽用?C# ActorSystem.CreateActor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ActorSystem的用法示例。


在下文中一共展示了ActorSystem.CreateActor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SimpleTestAskContX

        public void SimpleTestAskContX()
        {
            bool f = false;

            int res = 0;

            var acts = new ActorSystem();
            var act = acts.CreateActor<SimpleTestActor>();

            var m = new acttestmsg()
            {
                act = () =>
                {

                    return 10;
                },
                msg = "test message"
            };

            Task<int> tsk = null;
            tsk = act.Ask<int>((x) =>
               {
               res = x;
               if (tsk == null) return;
               if (tsk.IsCompleted) return;
               f = true;
               }, m);

            tsk.Wait();

            Assert.IsTrue(f);
            Assert.AreEqual(10, res);
            Assert.AreEqual(10, tsk.Result);
            Console.WriteLine("test complete");
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:35,代碼來源:BasicTests.cs

示例2: PostStopEception

        public void PostStopEception()
        {
            var tl = new TestLogger();

            var actf = new ActorSystem(tl);
            var act = actf.CreateActor<PostStopFaultActor>();

            act.Ask<int>(new Action(() => { throw new Exception(); })).Wait();
            tl.setted = false;
            try
            {
                act.Ask<int>(new stopmsg()).Wait();
            }
            catch { }

            while (!tl.setted)
            {
                Thread.SpinWait(0);
            }

            Assert.AreEqual("ProcPostStopException", tl.mname);
            Assert.IsNotNull(tl.ex);

            Assert.AreEqual(tl.Act, act);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:25,代碼來源:LogTests.cs

示例3: AllActorHasName

 public void AllActorHasName()
 {
     var actf = new ActorSystem();
     var act = actf.CreateActor<SimpleTestActor>();
     Assert.IsTrue(act.Name.Length > 0);
     Console.WriteLine("Created Actor name: {0}", act.Name);
 }
開發者ID:lebaon,項目名稱:AEF,代碼行數:7,代碼來源:NameTests.cs

示例4: ExeptionInExProcEqualsExcalation

        public void ExeptionInExProcEqualsExcalation()
        {
            var actf = new ActorSystem();
            var act1 = actf.CreateActor<ExceptionActor>();

            var tsk1 = act1.Ask<ActorRef>(new createchildactormsg());
            tsk1.Wait();
            var act2 = tsk1.Result;

            var tsk = act1.Ask<int>(new seteh() { eh = () => { throw new Exception(); } });
            tsk.Wait();

            tsk = act2.Ask<int>(new acttestmsg() { act = () => { throw new Exception(); } });
            try { tsk.Wait(); }
            catch { }

            bool f = false;

            tsk = act2.Ask<int>(new getstate());
            try { tsk.Wait(); }
            catch { f = true; }

            Assert.IsTrue(f);

            f = false;

            tsk = act1.Ask<int>(new getstate());
            try { tsk.Wait(); }
            catch { f = true; }

            Assert.IsTrue(f);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:32,代碼來源:ExceptionProcTests.cs

示例5: MsgInStoppedActor

        public void MsgInStoppedActor()
        {
            var tl = new TestLogger();

            var actf = new ActorSystem(tl);
            var act = actf.CreateActor<PostStopFaultActor>();
            try
            {
                act.Ask<int>(new stopmsg()).Wait();
            }
            catch { }

            tl.setted = false;
            act.Ask<int>("fgh", 123);

            while (!tl.setted)
            {
                Thread.SpinWait(0);
            }

            Assert.AreEqual("fgh", tl.args[0]);
            Assert.AreEqual(123, tl.args[1]);
            Assert.AreEqual("ProcMsgInStoppedActor", tl.mname);
            Assert.AreEqual(tl.ReturnType, typeof(int));
            Assert.AreEqual(tl.Act, act);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:26,代碼來源:LogTests.cs

示例6: ExProcStrategyIsRestart

        public void ExProcStrategyIsRestart()
        {
            var actf = new ActorSystem();
            var act1 = actf.CreateActor<ExceptionActor>();

            var tsk1 = act1.Ask<ActorRef>(new createchildactormsg());
            tsk1.Wait();
            var act2 = tsk1.Result;

            var tsk = act1.Ask<int>(new seteh() { eh = () => { return ExceptionDecision.Restart; } });
            tsk.Wait();

            tsk = act2.Ask<int>(new setstate() { x = 37 });
            tsk.Wait();

            tsk = act2.Ask<int>(new acttestmsg() { act = () => { throw new Exception(); } });
            try { tsk.Wait(); }
            catch { }

            bool f = false;

            f = false;

            tsk = act1.Ask<int>(new getstate());
            try { tsk.Wait(); }
            catch { f = true; }

            Assert.IsFalse(f);

            tsk = act2.Ask<int>(new getstate());
            tsk.Wait();

            Assert.AreEqual(0, tsk.Result);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:34,代碼來源:ExceptionProcTests.cs

示例7: ActorFullNameIsIerarhy

        public void ActorFullNameIsIerarhy()
        {
            var actf = new ActorSystem();
            var act = actf.CreateActor<IerarhyTestActor>("myactor");

            var act2 = act.Ask<ActorRef>(new createchildactormsg()).Result;

            Assert.AreEqual("\\user\\myactor\\child", act2.FullName);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:9,代碼來源:NameTests.cs

示例8: AllActorHasParentTest

        public void AllActorHasParentTest()
        {
            var actf = new ActorSystem();
            var act = actf.CreateActor<IerarhyTestActor>();

            var tsk = act.Ask<ActorRef>(new getparentmsg());
            tsk.Wait();

            Assert.IsNotNull(tsk.Result);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:10,代碼來源:ActorIerarhyTests.cs

示例9: BlockedSelfStop

        public void BlockedSelfStop()
        {
            var actf = new ActorSystem();
            var act = actf.CreateActor<PredRestartTestActor>();

            var tsk = act.Ask<int>(new selfstop());
            tsk.Wait();

            tsk = act.Ask<int>(new getstate());
            tsk.Wait();
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:11,代碼來源:ActorIerarhyTests.cs

示例10: ActorDontHaveSlashInName

        public void ActorDontHaveSlashInName()
        {
            bool f = false;
            var actf = new ActorSystem();
            try
            {
                var act = actf.CreateActor<SimpleTestActor>("\\");
            }
            catch { f = true; }

            Assert.IsTrue(f);
            f = false;
            try
            {
                var act = actf.CreateActor<SimpleTestActor>("/");
            }
            catch { f = true; }

            Assert.IsTrue(f);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:20,代碼來源:NameTests.cs

示例11: FindActorByPath

        public void FindActorByPath()
        {
            var actf = new ActorSystem();
            var act = actf.CreateActor<IerarhyTestActor>("myactor");

            var act2 = act.Ask<ActorRef>(new createchildactormsg()).Result;

            var fact = actf.FindActorByPath("\\user\\myactor\\child");

            Assert.NotNull(fact);
            Assert.AreEqual(act2, fact);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:12,代碼來源:NameTests.cs

示例12: PostStopErrTest

        public void PostStopErrTest()
        {
            Exception e = null;
            var acts = new ActorSystem();
            var act = acts.CreateActor<RestartFaultActor>();
            try
            {
                acts.StopActor(act);
            }
            catch (Exception ex) { e = ex; }

            Assert.IsNull(e);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:13,代碼來源:InActorTests.cs

示例13: BlockedSelfRestart

        public void BlockedSelfRestart()
        {
            var actf = new ActorSystem();
            var act = actf.CreateActor<PredRestartTestActor>();
            var tsk = act.Ask<int>(new setstate() { x = 20 });
            tsk.Wait();

             tsk = act.Ask<int>(new selfrestart());
            tsk.Wait();

            tsk = act.Ask<int>(new getstate());
            tsk.Wait();

            Assert.AreEqual(20, tsk.Result);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:15,代碼來源:ActorIerarhyTests.cs

示例14: CreateActorTest

        public void CreateActorTest()
        {
            var acts = new ActorSystem();
            var act = acts.CreateActor<IntoTestActor>();

            var tsk = act.Ask<ActorRef>(new crerateactormsg());
            tsk.Wait();

            Assert.IsNotNull(tsk.Result);
            var act2 = tsk.Result;

            var tsk2 = act2.Ask<int>(new acttestmsg() { msg = "test message", act = () => { return 10; } });
            tsk2.Wait();

            Assert.AreEqual(10, tsk2.Result);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:16,代碼來源:InActorTests.cs

示例15: PostRestartTest

        public void PostRestartTest()
        {
            var acts = new ActorSystem();
            var act = acts.CreateActor<IntoTestActor>();

            var tsk = act.Ask<int>(new statemsg());
            tsk.Wait();

            Assert.AreEqual(10, tsk.Result);

            acts.RestartActor(act);

            tsk = act.Ask<int>(new statemsg());
            tsk.Wait();

            Assert.AreEqual(15, tsk.Result);
        }
開發者ID:lebaon,項目名稱:AEF,代碼行數:17,代碼來源:InActorTests.cs


注:本文中的ActorSystem.CreateActor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。