Esempio n. 1
0
        /// <summary>
        /// This method find the index update generator of a given index
        /// identified by the indexed grain interface type and the name of the index
        /// </summary>
        /// <typeparam name="T">type of the indexed grain interface</typeparam>
        /// <param name="gf">the grain factory instance</param>
        /// <param name="indexName">>the name of the index</param>
        /// <returns>the index update generator of the index</returns>
        internal static IIndexUpdateGenerator GetIndexUpdateGenerator <T>(this IGrainFactory gf, string indexName) where T : IIndexableGrain
        {
            Tuple <object, object, object> output;

            if (!(IndexHandler.GetIndexes <T>()).TryGetValue(indexName, out output))
            {
                throw new Exception(string.Format("Index \"{0}\" does not exist on {1}.", indexName, typeof(T)));
            }
            return((IIndexUpdateGenerator)output.Item3);
        }
Esempio n. 2
0
 private IDictionary <string, Tuple <object, object, object> > InitIndexes()
 {
     __indexes = IndexHandler.GetIndexes(_iGrainType);
     foreach (var idxInfo in __indexes.Values)
     {
         if (idxInfo.Item1 is TotalIndex)
         {
             _hasAnyTotalIndex = true;
             return(__indexes);
         }
     }
     return(__indexes);
 }
Esempio n. 3
0
        private bool InitHasAnyTotalIndex()
        {
            var indexes = IndexHandler.GetIndexes(_iGrainType);

            foreach (var idxInfo in indexes.Values)
            {
                if (idxInfo.Item1 is TotalIndex)
                {
                    __hasAnyTotalIndex = 1;
                    return(true);
                }
            }
            __hasAnyTotalIndex = -1;
            return(false);
        }
        /// <summary>
        /// Upon activation, the list of index update generators
        /// is retrieved from the index handler. It is cached in
        /// this grain for use in creating before-images, and also
        /// for later calls to UpdateIndexes.
        ///
        /// Then, the before-images are created and stored in memory.
        /// </summary>
        public override Task OnActivateAsync()
        {
            if (logger.IsVerbose)
            {
                logger.Verbose("Activating indexable grain {0} of type {1} in silo {2}.", Orleans.GrainExtensions.GetGrainId(this), GetIIndexableGrainTypes()[0], RuntimeAddress);
            }
            //load indexes
            _iUpdateGens = IndexHandler.GetIndexes(GetIIndexableGrainTypes()[0]);

            //initialized _isThereAnyUniqueIndex field
            InitUniqueIndexCheck();

            //Initialize before images
            _beforeImages = new Dictionary <string, object>().AsImmutable <IDictionary <string, object> >();
            AddMissingBeforeImages();

            //insert the current grain to the active indexes defined on this grain
            //and at the same time call OnActivateAsync of the base class
            return(Task.WhenAll(InsertIntoActiveIndexes(), base.OnActivateAsync()));
        }
Esempio n. 5
0
 /// <summary>
 /// Gets an IndexInterface<K,V> given its name
 /// </summary>
 /// <typeparam name="K">key type of the index</typeparam>
 /// <typeparam name="V">value type of the index, which is
 /// the grain being indexed</typeparam>
 /// <param name="indexName">the name of the index, which
 /// is the identifier of the index</param>
 /// <returns>the IndexInterface<K,V> with the specified name</returns>
 public static IndexInterface <K, V> GetIndex <K, V>(this IGrainFactory gf, string indexName) where V : IIndexableGrain
 {
     return(IndexHandler.GetIndex <K, V>(indexName));
 }
Esempio n. 6
0
 /// <summary>
 /// Gets an IndexInterface given its name and grain interface type
 /// </summary>
 /// <param name="indexName">the name of the index, which
 /// is the identifier of the index<</param>
 /// <param name="iGrainType">the grain interface type
 /// that is being indexed</param>
 /// <returns>the IndexInterface with the specified name on the
 /// given grain interface type</returns>
 internal static IndexInterface GetIndex(this IGrainFactory gf, string indexName, Type iGrainType)
 {
     return(IndexHandler.GetIndex(iGrainType, indexName));
 }