public IGrainMethodInvoker GetInvoker(string genericGrainType = null) { if (String.IsNullOrEmpty(genericGrainType)) { return(invoker ?? (invoker = (IGrainMethodInvoker)Activator.CreateInstance(baseInvokerType))); } lock (cachedGenericInvokersLockObj) { if (cachedGenericInvokers.ContainsKey(genericGrainType)) { return(cachedGenericInvokers[genericGrainType]); } } var typeArgs = TypeUtils.GenericTypeArgs(genericGrainType); var concreteType = baseInvokerType.MakeGenericType(typeArgs); var inv = (IGrainMethodInvoker)Activator.CreateInstance(concreteType); lock (cachedGenericInvokersLockObj) { if (!cachedGenericInvokers.ContainsKey(genericGrainType)) { cachedGenericInvokers[genericGrainType] = inv; } } return(inv); }
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); } }