/// <summary> /// 注销消息 /// </summary> /// <param name="_name"></param> /// <param name="_delegate"></param> public void Unregister(string _name, NoticeDelegate _delegate) { if (m_noticesList.ContainsKey(_name)) { m_noticesList[_name] -= _delegate; if (m_noticesList[_name] == null) { m_noticesList.Remove(_name); } } }
public GroupNoticeInfo GetGroupNotice(UUID noticeID, NoticeDelegate d) { object notice = null; bool firstCall = false; string cacheKey = "notice-" + noticeID.ToString(); //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0}", cacheKey); while (true) { lock (m_Cache) { if (m_Cache.TryGetValue(cacheKey, out notice)) { return((GroupNoticeInfo)notice); } // not cached if (!m_ActiveRequests.ContainsKey(cacheKey)) { m_ActiveRequests.Add(cacheKey, true); firstCall = true; } } if (firstCall) { try { GroupNoticeInfo _notice = d(); lock (m_Cache) { m_Cache.AddOrUpdate(cacheKey, _notice, GROUPS_CACHE_TIMEOUT); return(_notice); } } finally { lock (m_Cache) { m_ActiveRequests.Remove(cacheKey); } } } else { Thread.Sleep(50); } } }
/// <summary> /// 注册消息 /// </summary> /// <param name="_name"></param> /// <param name="_delegate"></param> public void Register(string _name, NoticeDelegate _delegate) { if (m_noticesList == null || _delegate == null) { return; } if (m_noticesList.ContainsKey(_name) && (m_noticesList[_name] != null)) { m_noticesList[_name] += _delegate; } else { NoticeDelegate method = null; method += _delegate; m_noticesList[_name] = method; } }
public GroupNoticeInfo GetGroupNotice(UUID noticeID, NoticeDelegate d) { object notice = null; bool firstCall = false; string cacheKey = "notice-" + noticeID.ToString(); //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0}", cacheKey); while (true) { lock (m_Cache) { if (m_Cache.TryGetValue(cacheKey, out notice)) { return (GroupNoticeInfo)notice; } // not cached if (!m_ActiveRequests.ContainsKey(cacheKey)) { m_ActiveRequests.Add(cacheKey, true); firstCall = true; } } if (firstCall) { try { GroupNoticeInfo _notice = d(); lock (m_Cache) { m_Cache.AddOrUpdate(cacheKey, _notice, GROUPS_CACHE_TIMEOUT); return _notice; } } finally { m_ActiveRequests.Remove(cacheKey); } } else Thread.Sleep(50); } }