// Check if belief is newer than current belief of matching type and id, if so, // replace old belief with b. public void addBeliefToDataManager(Belief b, int sourceId) { lock (dataManagerLock) { SortedDictionary <int, Belief> tempTypeDict = getBeliefsFor(b.getTypeKey()); if (tempTypeDict != null) { Belief oldBelief; if (!getBeliefsFor(b.getTypeKey()).TryGetValue(b.getId(), out oldBelief) || oldBelief.getBeliefTime() < b.getBeliefTime()) { getBeliefsFor(b.getTypeKey())[b.getId()] = b; } } else { getBeliefsFor(b.getTypeKey())[b.getId()] = b; } /* * Do not update actors in this function * SortedDictionary<int, bool> sourceDistanceDictionary; * if (actorDistanceDictionary.TryGetValue(sourceId, out sourceDistanceDictionary)) * { * foreach (KeyValuePair<int, bool> entry in sourceDistanceDictionary) * { * SoaActor destActor = soaActorDictionary[entry.Key]; * if (entry.Value) * { * destActor.addBelief(b, sourceId); * } * } * }*/ } }
public bool Commit(Belief belief) { lock (this) { CacheKey key = new CacheKey(belief.getTypeKey(), belief.getId()); CachedBelief oldCache = null; if (beliefCache.TryGetValue(key, out oldCache)) { BeliefMerger merger = new BeliefMerger(); Belief merged = merger.merge(oldCache.GetBelief(), belief); if (merged == oldCache.GetBelief()) { return(false); } belief = merged; } byte[] serialized = serializer.serializeBelief(belief); Hash hash = hashFunction.generateHash(serialized); CachedBelief cached = new CachedBelief(belief, serialized, hash); beliefCache[key] = cached; currentState = RegenerateState(); return(true); } }
public void synchronizeBelief(Belief belief) { IEnumerable <CachedBelief> changedBeliefs = repo.Diff(remoteState); foreach (CachedBelief cached in changedBeliefs) { if (cached.GetBelief().getTypeKey() == belief.getTypeKey() && cached.GetBelief().getId() == belief.getId()) { protocol.post(cached); break; } } }