Exemplo n.º 1
0
        private GrainInterfaceData GetOrAddGrainInterfaceData(Type iface, bool isGenericGrainClass)
        {
            var interfaceId = GrainInterfaceUtils.GetGrainInterfaceId(iface);

            // If already exist
            GrainInterfaceData grainInterfaceData;

            if (table.TryGetValue(interfaceId, out grainInterfaceData))
            {
                return(grainInterfaceData);
            }

            // If not create new entry
            var interfaceName = TypeUtils.GetRawClassName(TypeUtils.GetFullName(iface));

            grainInterfaceData = new GrainInterfaceData(interfaceId, iface, interfaceName);
            table[interfaceId] = grainInterfaceData;

            // Add entry to mapping iface string -> data
            var interfaceTypeKey = GetTypeKey(iface, isGenericGrainClass);

            typeToInterfaceData[interfaceTypeKey] = grainInterfaceData;

            // If we are adding a concrete implementation of a generic interface
            // add also the latter to the map: GrainReference and InvokeMethodRequest
            // always use the id of the generic one
            if (iface.IsConstructedGenericType)
            {
                GetOrAddGrainInterfaceData(iface.GetGenericTypeDefinition(), true);
            }

            return(grainInterfaceData);
        }
Exemplo n.º 2
0
        internal GrainTypeData this[string className]
        {
            get
            {
                string msg;

                lock (this)
                {
                    string grainType;

                    if (grainInterfaceMap.TryGetPrimaryImplementation(className, out grainType))
                    {
                        return(grainTypes[grainType]);
                    }
                    if (grainTypes.ContainsKey(className))
                    {
                        return(grainTypes[className]);
                    }

                    if (TypeUtils.IsGenericClass(className))
                    {
                        var templateName = TypeUtils.GetRawClassName(className);
                        if (grainInterfaceMap.TryGetPrimaryImplementation(templateName, out grainType))
                        {
                            templateName = grainType;
                        }

                        if (grainTypes.ContainsKey(templateName))
                        {
                            // Found the generic template class
                            try
                            {
                                // Instantiate the specific type from generic template
                                var    genericGrainTypeData = (GenericGrainTypeData)grainTypes[templateName];
                                Type[] typeArgs             = TypeUtils.GenericTypeArgs(className);
                                var    concreteTypeData     = genericGrainTypeData.MakeGenericType(typeArgs);

                                // Add to lookup tables for next time
                                var grainClassName = concreteTypeData.GrainClass;
                                grainTypes.Add(grainClassName, concreteTypeData);
                                AddToGrainInterfaceToClassMap(concreteTypeData.Type, concreteTypeData.RemoteInterfaceTypes, genericGrainTypeData.IsStatelessWorker);

                                return(concreteTypeData);
                            }
                            catch (Exception ex)
                            {
                                msg = "Cannot instantiate generic class " + className;
                                logger.Error(ErrorCode.Runtime_Error_100092, msg, ex);
                                throw new KeyNotFoundException(msg, ex);
                            }
                        }
                    }
                }

                msg = "Cannot find GrainTypeData for class " + className;
                logger.Error(ErrorCode.Runtime_Error_100093, msg);
                throw new TypeLoadException(msg);
            }
        }
Exemplo n.º 3
0
        private void AddToGrainInterfaceToClassMap(Type grainClass, IEnumerable <Type> grainInterfaces, bool isUnordered)
        {
            var grainClassCompleteName = TypeUtils.GetFullName(grainClass);
            var grainClassTypeCode     = CodeGeneration.GrainInterfaceData.GetGrainClassTypeCode(grainClass);
            var placement = GrainTypeData.GetPlacementStrategy(grainClass);

            foreach (var iface in grainInterfaces)
            {
                var ifaceCompleteName    = TypeUtils.GetFullName(iface);
                var ifaceName            = TypeUtils.GetRawClassName(ifaceCompleteName);
                var isPrimaryImplementor = IsPrimaryImplementor(grainClass, iface);
                var ifaceId = CodeGeneration.GrainInterfaceData.GetGrainInterfaceId(iface);
                grainInterfaceMap.AddEntry(ifaceId, iface, grainClassTypeCode, ifaceName, grainClassCompleteName, grainClass.Assembly.CodeBase,
                                           placement, isPrimaryImplementor);
            }

            if (isUnordered)
            {
                grainInterfaceMap.AddToUnorderedList(grainClassTypeCode);
            }
        }
Exemplo n.º 4
0
        private void AddToGrainInterfaceToClassMap(Type grainClass, IEnumerable <Type> grainInterfaces, bool isUnordered)
        {
            var grainTypeInfo          = grainClass.GetTypeInfo();
            var grainClassCompleteName = TypeUtils.GetFullName(grainTypeInfo);
            var isGenericGrainClass    = grainTypeInfo.ContainsGenericParameters;
            var grainClassTypeCode     = GrainInterfaceUtils.GetGrainClassTypeCode(grainClass);
            var placement            = GrainTypeData.GetPlacementStrategy(grainClass, this.defaultPlacementStrategy);
            var registrationStrategy = GrainTypeData.GetMultiClusterRegistrationStrategy(grainClass);

            foreach (var iface in grainInterfaces)
            {
                var ifaceCompleteName    = TypeUtils.GetFullName(iface);
                var ifaceName            = TypeUtils.GetRawClassName(ifaceCompleteName);
                var isPrimaryImplementor = IsPrimaryImplementor(grainClass, iface);
                var ifaceId = GrainInterfaceUtils.GetGrainInterfaceId(iface);
                grainInterfaceMap.AddEntry(ifaceId, iface, grainClassTypeCode, ifaceName, grainClassCompleteName,
                                           grainTypeInfo.Assembly.CodeBase, isGenericGrainClass, placement, registrationStrategy, isPrimaryImplementor);
            }

            if (isUnordered)
            {
                grainInterfaceMap.AddToUnorderedList(grainClassTypeCode);
            }
        }