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 abstract bool RegisterHandler(NFIDENTID xID, NFIActor.Handler handler);
public abstract NFIDENTID CreateActor(NFIActor.Handler handler);
/////////////////////////////////////////////////////// private bool ReleaseActor(NFIActor xActor) { if (null == xActor) { return false; } NFIActorMessage xMessage = new NFIActorMessage(); xMessage.bAsync = false;//同步消息 xMessage.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_BEFORE_SHUT; xActor.PushMessages(null, xMessage); xMessage.eType = NFIActorMessage.EACTOR_MESSAGE_ID.EACTOR_SHUT; xActor.PushMessages(null, xMessage); 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; }