예제 #1
0
        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);
            }
        }
예제 #2
0
        public BeliefType Find <BeliefType>(Belief.Key key, int id) where BeliefType : Belief
        {
            CacheKey     cacheKey = new CacheKey(key, id);
            CachedBelief found    = null;

            beliefCache.TryGetValue(cacheKey, out found);
            if (found != null)
            {
                return(found.GetBelief() as BeliefType);
            }
            return(null);
        }
        public void post(CachedBelief belief)
        {
            if (protocol.getConnection().getRemoteAddress() == null)
            {
                return;
            }

            byte[]     bufferData = serializer.serializeBelief(belief.GetBelief());
            BSPMessage message    = new BSPMessage(protocol.getConnection().getRemoteAddress(),
                                                   BSPMessageType.POST,
                                                   protocol.getAgentID(),
                                                   new NetworkBuffer(bufferData));

            protocol.getConnection().send(message);
        }
예제 #4
0
        public IEnumerable <CachedBelief> Diff(RepositoryState state)
        {
            lock (this)
            {
                RepositoryState        myState  = CurrentState();
                ICollection <CacheKey> diffKeys = myState.Diff(state);

                List <CachedBelief> beliefs = new List <CachedBelief>();
                foreach (CacheKey key in diffKeys)
                {
                    CachedBelief cachedBelief = beliefCache[key];
                    beliefs.Add(cachedBelief);
                }
                return(beliefs);
            }
        }
예제 #5
0
 public void post(CachedBelief belief)
 {
     postHandler.post(belief);
 }
예제 #6
0
 public void addOutgoing(CachedBelief b, int sourceID, int[] targetActorIDs)
 {
     addOutgoing(b.GetBelief(), sourceID, targetActorIDs);
 }