public GrainTypeManager( ILocalSiloDetails siloDetails, IApplicationPartManager applicationPartManager, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager, MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager, ILogger <GrainTypeManager> logger, IOptions <GrainClassOptions> grainClassOptions) { var localTestMode = siloDetails.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback); this.logger = logger; this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy; this.serializationManager = serializationManager; this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager; grainInterfaceMap = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy); ClusterGrainInterfaceMap = grainInterfaceMap; grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>(); var grainClassFeature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>(); this.grainTypes = CreateGrainTypeMap(grainClassFeature, grainClassOptions.Value); var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>(); this.invokers = CreateInvokerMap(grainInterfaceFeature); this.InitializeInterfaceMap(); }
public GrainTypeManager( ILocalSiloDetails siloDetails, IApplicationPartManager applicationPartManager, PlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager, ILogger <GrainTypeManager> logger, IOptions <GrainClassOptions> grainClassOptions) { this.logger = logger; this.defaultPlacementStrategy = defaultPlacementStrategy; this.serializationManager = serializationManager; grainInterfaceMap = new GrainInterfaceMap(this.defaultPlacementStrategy); ClusterGrainInterfaceMap = grainInterfaceMap; GrainTypeResolver = grainInterfaceMap.GetGrainTypeResolver(); grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>(); var grainClassFeature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>(); this.grainTypes = CreateGrainTypeMap(grainClassFeature, grainClassOptions.Value); var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>(); this.invokers = CreateInvokerMap(grainInterfaceFeature); this.InitializeInterfaceMap(); }
/// <summary> /// Initializes a new instance of the <see cref="RoslynCodeGenerator"/> class. /// </summary> /// <param name="partManager"></param> /// <param name="loggerFactory">The logger factory.</param> public RoslynCodeGenerator(IApplicationPartManager partManager, ILoggerFactory loggerFactory) { var serializerFeature = partManager.CreateAndPopulateFeature <SerializerFeature>(); var grainClassFeature = partManager.CreateAndPopulateFeature <GrainClassFeature>(); var grainInterfaceFeature = partManager.CreateAndPopulateFeature <GrainInterfaceFeature>(); this.knownTypes = GetKnownTypes(); this.serializableTypes = new SerializerGenerationManager(GetExistingSerializers(), loggerFactory); this.logger = loggerFactory.CreateLogger <RoslynCodeGenerator>(); var knownInterfaces = grainInterfaceFeature.Interfaces.Select(i => i.InterfaceType); var knownClasses = grainClassFeature.Classes.Select(c => c.ClassType); this.knownGrainTypes = new HashSet <Type>(knownInterfaces.Concat(knownClasses)); HashSet <string> GetKnownTypes() { var result = new HashSet <string>(); foreach (var kt in serializerFeature.KnownTypes) { result.Add(kt.Type); } foreach (var serializer in serializerFeature.SerializerTypes) { result.Add(RuntimeTypeNameFormatter.Format(serializer.Target)); result.Add(RuntimeTypeNameFormatter.Format(serializer.Serializer)); } foreach (var serializer in serializerFeature.SerializerDelegates) { result.Add(RuntimeTypeNameFormatter.Format(serializer.Target)); } return(result); } HashSet <Type> GetExistingSerializers() { var result = new HashSet <Type>(); foreach (var serializer in serializerFeature.SerializerDelegates) { result.Add(serializer.Target); } foreach (var serializer in serializerFeature.SerializerTypes) { result.Add(serializer.Target); } return(result); } }
private static ImmutableDictionary <GrainType, GrainProperties> CreateGrainManifest( IEnumerable <IGrainPropertiesProvider> grainMetadataProviders, IApplicationPartManager applicationPartManager, GrainTypeResolver grainTypeProvider) { var feature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>(); var propertiesMap = ImmutableDictionary.CreateBuilder <GrainType, GrainProperties>(); foreach (var value in feature.Classes) { var grainClass = value.ClassType; var grainType = grainTypeProvider.GetGrainType(grainClass); var properties = new Dictionary <string, string>(); foreach (var provider in grainMetadataProviders) { provider.Populate(grainClass, grainType, properties); } var result = new GrainProperties(properties.ToImmutableDictionary()); if (propertiesMap.ContainsKey(grainType)) { throw new InvalidOperationException($"An entry with the key {grainType} is already present." + $"\nExisting: {propertiesMap[grainType].ToDetailedString()}\nTrying to add: {result.ToDetailedString()}" + "\nConsider using the [GrainType(\"name\")] attribute to give these classes unique names."); } propertiesMap.Add(grainType, result); } return(propertiesMap.ToImmutable()); }
private static ImmutableDictionary <GrainInterfaceType, GrainInterfaceProperties> CreateInterfaceManifest( IEnumerable <IGrainInterfacePropertiesProvider> propertyProviders, IApplicationPartManager applicationPartManager, GrainInterfaceTypeResolver interfgaceTypeResolver) { var feature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>(); var builder = ImmutableDictionary.CreateBuilder <GrainInterfaceType, GrainInterfaceProperties>(); foreach (var value in feature.Interfaces) { var interfaceType = interfgaceTypeResolver.GetGrainInterfaceType(value.InterfaceType); var properties = new Dictionary <string, string>(); foreach (var provider in propertyProviders) { provider.Populate(value.InterfaceType, interfaceType, properties); } var result = new GrainInterfaceProperties(properties.ToImmutableDictionary()); if (builder.ContainsKey(interfaceType)) { throw new InvalidOperationException($"An entry with the key {interfaceType} is already present." + $"\nExisting: {builder[interfaceType].ToDetailedString()}\nTrying to add: {result.ToDetailedString()}" + "\nConsider using the [GrainInterfaceType(\"name\")] attribute to give these interfaces unique names."); } builder.Add(interfaceType, result); } return(builder.ToImmutable()); }
public TypeMetadataCache(IApplicationPartManager applicationPartManager) { var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>(); foreach (var grain in grainInterfaceFeature.Interfaces) { this.grainToInvokerMapping[grain.InterfaceType] = grain.InvokerType; this.grainToReferenceMapping[grain.InterfaceType] = grain.ReferenceType; } }