public override NFIDENTID CreateActor(NFIActor.Handler handler) { NFIDENTID xID = new NFIDENTID(0, ++mnActorIndex); NFIActor xActor = new NFCActor(xID, this); //添加仍旧有问题,foreach中万一有其他线程添加 bool bRet = mxActorDic.TryAdd(xID, xActor); if (bRet) { if (null != handler) { RegisterHandler(xID, handler); NFIActorMessage xMessage = new NFIActorMessage(); xMessage.bAsync = false;//同步消息 xMessage.bReturn = false;//无需返回 xMessage.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_INIT; SendMsg(xActor.GetAddress(), null, xMessage); xMessage.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_AFTER_INIT; SendMsg(xActor.GetAddress(), null, xMessage); } return xID; } return null; }
public NFCRecord(NFIDENTID self, string strRecordName, int nRow, NFIDataList varData) { mSelf = self; mnRow = nRow; mstrRecordName = strRecordName; mVarRecordType = new NFCDataList(varData); }
public bool Parse(string strData, out NFIDENTID id) { NFIDENTID xId = new NFIDENTID(); id = xId; string[] strList = strData.Split('-'); if (strList.Count() != 2) { return false; } Int64 nHead = 0; if (!Int64.TryParse(strList[0], out nHead)) { return false; } Int64 nData = 0; if (!Int64.TryParse(strList[1], out nData)) { return false; } id.nHead64 = nHead; id.nData64 = nData; return true; }
public NFCHeartBeat(NFIDENTID self, string strHeartBeatName, float fTime, NFIDataList valueList) { mSelf = self; mstrHeartBeatName = strHeartBeatName; mfTime = fTime; mfOldTime = fTime; mArgValueList = valueList; }
public NFCObject(NFIDENTID self, int nContainerID, int nGroupID, string strClassName, string strConfigIndex) { mSelf = self; mstrClassName = strClassName; mstrConfigIndex = strConfigIndex; mnContainerID = nContainerID; mnGroupID = nGroupID; Init(); }
public override bool SendMsg(NFIDENTID address, NFIDENTID from, NFIActorMessage xMessage) { if (null == address || null == xMessage) { return false; ; } NFIActor xActor = GetActor(address); if (null != xActor) { return xActor.PushMessages(from, xMessage); } return false; }
public override bool PushMessages(NFIDENTID from, NFIActorMessage xMessage) { xMessage.nMasterActor = mxID; xMessage.nFromActor = from; if (null != mxMessageHandler) { xMessage.xMasterHandler = new ConcurrentQueue<NFIActor.Handler>(mxMessageHandler); } if (!xMessage.bAsync) { //同步消息,也不用排队,就等吧 ProcessMessageSyns(xMessage); } else { //异步消息,需要new新的msg,否则担心masteractor还需使用它 NFIActorMessage xMsg = new NFIActorMessage(xMessage); mxMessageQueue.Enqueue(xMsg); NFIScheduler xScheduler = mxActorMng.GetScheduler(); if(null != xScheduler) { xScheduler.AddToScheduler(mxID); } } return true; }
public NFCPropertyManager(NFIDENTID self) { mSelf = self; mhtProperty = new Hashtable(); }
public NFCProperty( NFIDENTID self, string strPropertyName, NFIDataList varData) { mSelf = self; msPropertyName = strPropertyName; mVarProperty = new NFCDataList(varData); }
public abstract void AddToScheduler(NFIDENTID xID);
public abstract bool ReleaseActor(NFIDENTID xID);
public abstract NFIActor GetActor(NFIDENTID xID);
public NFCActor(NFIDENTID xID, NFIActorMng xActorMng) { mxID = xID; mxActorMng = xActorMng; }
public NFCEvent(NFIDENTID self, int nEventID, NFIDataList valueList) { mSelf = self; mnEventID = nEventID; mArgValueList = valueList; }
public override bool SetRecordObject(string strRecordName, int nRow, int nCol, NFIDENTID obj) { NFIRecord record = mRecordManager.GetRecord(strRecordName); if (null != record) { record.SetObject(nRow, nCol, obj); return true; } return false; }
public override bool SetPropertyObject(string strPropertyName, NFIDENTID obj) { NFIProperty property = mPropertyManager.GetProperty(strPropertyName); if (null == property) { NFIDataList valueList = new NFCDataList(); valueList.AddObject(new NFIDENTID()); property = mPropertyManager.AddProperty(strPropertyName, valueList); } property.SetObject(obj); return true; }
public NFCEventModule(NFIDENTID self) { mSelf = self; mhtEvent = new Dictionary<int, NFIEvent>(); }
public override int FindObject(int nCol, NFIDENTID value) { foreach (int i in mhtRecordVec.Keys) { NFIDataList valueList = (NFIDataList)mhtRecordVec[i]; if (valueList.ObjectVal(nCol) == value) { return i; } } return -1; }
public NFIDENTID(NFIDENTID id) { nHead64 = id.nHead64; nData64 = id.nData64; }
public override bool SetObject(int nRow, int nCol, NFIDENTID value) { if(nRow >= 0 && nRow < mnRow) { if (!mhtRecordVec.ContainsKey(nRow)) { AddRow(nRow); } NFIDataList valueList = (NFIDataList)mhtRecordVec[nRow]; if (valueList.GetType(nCol) == NFIDataList.VARIANT_TYPE.VTYPE_OBJECT) { if (valueList.ObjectVal(nCol) != value) { NFCDataList oldValue = new NFCDataList(); oldValue.AddObject(valueList.ObjectVal(nCol)); valueList.SetObject(nCol, value); NFCDataList newValue = new NFCDataList(); newValue.AddObject(valueList.ObjectVal(nCol)); if (null != doHandleDel) { doHandleDel(mSelf, mstrRecordName, eRecordOptype.Updata, nRow, nCol, oldValue, newValue); } } } return true; } return false; }
public abstract bool SetRecordObject(string strRecordName, int nRow, int nCol, NFIDENTID obj);
public abstract bool RegisterHandler(NFIDENTID xID, NFIActor.Handler handler);
public abstract bool SetPropertyObject(string strPropertyName, NFIDENTID obj);
public abstract bool SendMsg(NFIDENTID address, NFIDENTID from, NFIActorMessage xMessage);
public override NFIActor GetActor(NFIDENTID xID) { if (null == xID) { return null; } NFIActor xActor = null; if (mxActorDic.TryGetValue(xID, out xActor)) { return xActor; } return null; }
public override bool SetObject(NFIDENTID value) { if (mVarProperty.ObjectVal(0) != value) { NFCDataList oldValue = new NFCDataList(mVarProperty); mVarProperty.SetObject(0, value); NFCDataList newValue = new NFCDataList(mVarProperty); if (null != doHandleDel) { doHandleDel(mSelf, msPropertyName, oldValue, newValue); } } return true; }
public override bool RegisterHandler(NFIDENTID xID, NFIActor.Handler handler) { if (null == xID || null == handler) { return false; } NFIActor xActor = GetActor(xID); if (null != xActor) { xActor.RegisterHandler(handler); return true; } return false; }
public virtual void SetSelf(NFIDENTID xID) { mxID = xID; }
public override bool ReleaseActor(NFIDENTID xID) { if (null == xID) { return false; ; } NFIActor xActor = null; if (mxActorDic.TryRemove(xID, out xActor)) { ReleaseActor(xActor); } return true; }
public NFCHeartBeatManager(NFIDENTID self) { mSelf = self; mhtHeartBeat = new Dictionary<string, NFIHeartBeat>(); }
static void Main() { TestHandler1 xTestHandler1 = new TestHandler1(); TestHandler2 xTestHandler2 = new TestHandler2(); Console.WriteLine("start run... ThreadID: " + Thread.CurrentThread.ManagedThreadId); NFIDENTID xID1 = NFCActorMng.Intance().CreateActor(xTestHandler1.Handler); NFIDENTID 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(); NFIDENTID x1 = NFCActorMng.Intance().CreateActor(xTest1.Handler); NFIDENTID 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(); }