Inheritance: NFIActorMng
示例#1
0
        public static NFIActorMng Intance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                    {
                        _instance = new NFCActorMng();
                    }
                }
            }

            return(_instance);
        }
示例#2
0
        public static NFIActorMng Intance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                    {
                        _instance = new NFCActorMng();
                    }
                }
            }

            return _instance;
        }
示例#3
0
            public void Handler(NFIActorMessage xMessage)
            {
                ++i;

                //Console.WriteLine("handler11 ThreadID: " + Thread.CurrentThread.ManagedThreadId + " " + i);

                switch (xMessage.eType)
                {
                case NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_INIT:
                    Init();
                    break;

                case NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_AFTER_INIT:
                    AfterInit();
                    break;

                case NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_EXCUTE:
                    Execute();
                    break;

                case NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_BEFORE_SHUT:
                    BeforeShut();
                    break;

                case NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_SHUT:
                    Shut();
                    break;

                case NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_TEST_MSG:
                {
                    NFIActorMessage xMsgData = new NFIActorMessage();
                    xMsgData.data = "test1";
                    //xMsgData.bAsync = false;
                    xMsgData.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_DATA_MSG;

                    // Console.WriteLine("handler11 ThreadID: " + Thread.CurrentThread.ManagedThreadId + " " + xMsgData.data);

                    NFCActorMng.Intance().SendMsg(xMessage.nFromActor, xMessage.nMasterActor, xMsgData);

                    // Console.WriteLine("handler11 ThreadID: " + Thread.CurrentThread.ManagedThreadId + " " + xMsgData.data);
                }
                break;

                default:
                    break;
                }
            }
示例#4
0
        static void Main()
        {
            TestHandler1 xTestHandler1 = new TestHandler1();
            TestHandler2 xTestHandler2 = new TestHandler2();

            Console.WriteLine("start run... ThreadID: " + Thread.CurrentThread.ManagedThreadId);

            NFGUID xID1 = NFCActorMng.Intance().CreateActor(xTestHandler1.Handler);
            NFGUID xID2 = NFCActorMng.Intance().CreateActor(xTestHandler2.Handler);

            NFIActorMessage xMsgData = new NFIActorMessage();

            xMsgData.data = "test";
            //xMsgData.bAsync = false;//控制为同步消息还是异步消息
            xMsgData.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_TEST_MSG;

            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;

            NFCActorMng.Intance().SendMsg(xID1, xID2, xMsgData);


            for (int i = 0; i < 100000; ++i)
            {
                NFIActorMessage xMsg = new NFIActorMessage();
                xMsg.data = "test";
                //xMsg.bAsync = false;//控制为同步消息还是异步消息
                xMsg.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_TEST_MSG;

                TestHandler1 xTest1 = new TestHandler1();
                TestHandler2 xTest2 = new TestHandler2();

                NFGUID x1 = NFCActorMng.Intance().CreateActor(xTest1.Handler);
                NFGUID x2 = NFCActorMng.Intance().CreateActor(xTest2.Handler);

                NFCActorMng.Intance().SendMsg(x1, x2, xMsg);
            }

            Console.WriteLine("start loop... ThreadID: " + Thread.CurrentThread.ManagedThreadId);


            while (true)
            {
                Thread.Sleep(1);

                System.TimeSpan ts = System.DateTime.Now - currentTime;
                if (ts.TotalMilliseconds > 10000)
                {
                    int nCount = TestHandler1.i + TestHandler2.i;
                    Console.WriteLine("Count : " + nCount);

                    break;
                }
            }

            while (true)
            {
                Thread.Sleep(1);
            }

            NFCActorMng.Intance().ReleaseAllActor();
        }