public void updateTO(TOUpdate msg) { lock (_receivedTOLock) { if (receivedMsgTOupdate.ContainsKey(msg.topic)) { if (!receivedMsgTOupdate[msg.topic].Contains(msg.seqnum)) receivedMsgTOupdate[msg.topic].Add(msg.seqnum); else return; } else { receivedMsgTOupdate.Add(msg.topic, new HashSet<int>()); receivedMsgTOupdate[msg.topic].Add(msg.seqnum); } } int en = getEventnum(); log(en, string.Format("[TOUpdate] {0}", msg)); //Propagate msg to childs lock (_childSites) { foreach (var childsite in _childSites) { log(en, string.Format("[TOUpdate] sent to {0}", childsite)); foreach (var broker in childsite.brokers) { new updateTODelegate(broker.updateTO).BeginInvoke(msg, null, null); } } } ////////////////// lock (_TOUpdatesLock) { _TOUpdates.Add(msg); _TOUpdates = _TOUpdates.OrderBy(m => m.seqnum).ToList(); var x = _TOUpdates.Select(m => string.Format("({0},{1})", m.topic, m.seqnum)); log(en, string.Format("[TOUpdate] TOSeqnum:{0} TOUpdate:{1}", _TOSeqnum, string.Join(",", x))); while (_TOUpdates.Count != 0 && _TOSeqnum == _TOUpdates[0].seqnum) { if (_topicSubscribers.Keys.Any(t => equivalentTopic(msg.topic, t))) { log(en, string.Format("[TOUpdate] saved update")); lock (_TOWaitingLock) { _TOWaiting.Add(msg); } } else { log(en, string.Format("[TOUpdate] discarded update because not interested in topic")); } _TOSeqnum++; _TOUpdates.RemoveAt(0); } x = _TOUpdates.Select(m => string.Format("({0},{1})", m.topic, m.seqnum)); log(en, string.Format("[TOUpdate] TOUpdate:{0}", string.Join(",", x))); } TODeliver(en); }
public void updateNetwork(int en, string topic, int seqnum) { var update = new TOUpdate() { originSite = _site, topic = topic, seqnum = seqnum }; log(en, string.Format("[updateNetwork] Sending {0}", update)); updateTO(update); //new updateTODelegate(this.updateTO).BeginInvoke(update, null, null); }