コード例 #1
0
        public bool Merge(GrainId grain, IGrainInfo other)
        {
            bool modified = false;

            foreach (var pair in other.Instances)
            {
                if (Instances.ContainsKey(pair.Key))
                {
                    continue;
                }

                Instances[pair.Key] = new ActivationInfo(pair.Value.SiloAddress);
                modified            = true;
            }

            if (modified)
            {
                VersionTag = rand.Next();
            }

            if (SingleInstance && (Instances.Count > 0))
            {
                // Grain is supposed to be in single activation mode, but we have two activations!!
                // Eventually we should somehow delegate handling this to the silo, but for now, we'll arbitrarily pick one value.
                var orderedActivations = Instances.OrderBy(pair => pair.Key);
                var activationToKeep   = orderedActivations.First();
                var activationsToDrop  = orderedActivations.Skip(1);
                Instances.Clear();
                Instances.Add(activationToKeep.Key, activationToKeep.Value);
                var list = new List <ActivationAddress>(1);
                foreach (var activation in activationsToDrop.Select(keyValuePair => ActivationAddress.GetAddress(keyValuePair.Value.SiloAddress, grain, keyValuePair.Key)))
                {
                    list.Add(activation);
                    CatalogFactory.GetSystemTarget(Constants.CatalogId, activation.Silo).
                    DeleteActivations(list).Ignore();

                    list.Clear();
                }
                return(true);
            }
            return(false);
        }