/// <summary> /// Create a reference to a grain that we expect to support the broadcast channel consumer extension. /// </summary> /// <param name="grainFactory">The grain factory used to get consumer references.</param> /// <param name="channelId">The channel ID to use for the grain ID construction.</param> /// <param name="channelSubscriber">The GrainBindings for the grain to create</param> /// <returns></returns> private IBroadcastChannelConsumerExtension MakeConsumerReference( IGrainFactory grainFactory, InternalChannelId channelId, BroadcastChannelSubscriber channelSubscriber) { var grainId = channelSubscriber.GetGrainId(channelId); return(grainFactory.GetGrain <IBroadcastChannelConsumerExtension>(grainId)); }
private Cache BuildCache(MajorMinorVersion version, ImmutableDictionary <GrainType, GrainBindings> bindings) { var newPredicates = new List <BroadcastChannelSubscriberPredicate>(); foreach (var binding in bindings.Values) { foreach (var grainBinding in binding.Bindings) { if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.BindingTypeKey, out var type) || !string.Equals(type, WellKnownGrainTypeProperties.BroadcastChannelBindingTypeValue, StringComparison.Ordinal)) { continue; } if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.BroadcastChannelBindingPatternKey, out var pattern)) { throw new KeyNotFoundException( $"Channel binding for grain type {binding.GrainType} is missing a \"{WellKnownGrainTypeProperties.BroadcastChannelBindingPatternKey}\" value"); } IChannelNamespacePredicate predicate = null; foreach (var provider in _providers) { if (provider.TryGetPredicate(pattern, out predicate)) { break; } } if (predicate is null) { throw new KeyNotFoundException( $"Could not find an {nameof(IChannelNamespacePredicate)} for the pattern \"{pattern}\"." + $" Ensure that a corresponding {nameof(IChannelNamespacePredicateProvider)} is registered"); } if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.ChannelIdMapperKey, out var mapperName)) { throw new KeyNotFoundException( $"Channel binding for grain type {binding.GrainType} is missing a \"{WellKnownGrainTypeProperties.ChannelIdMapperKey}\" value"); } var channelIdMapper = _serviceProvider.GetServiceByName <IChannelIdMapper>(string.IsNullOrWhiteSpace(mapperName) ? DefaultChannelIdMapper.Name : mapperName); var subscriber = new BroadcastChannelSubscriber(binding, channelIdMapper); newPredicates.Add(new BroadcastChannelSubscriberPredicate(subscriber, predicate)); } } return(new Cache(version, newPredicates)); }
public BroadcastChannelSubscriberPredicate(BroadcastChannelSubscriber subscriber, IChannelNamespacePredicate predicate) { Subscriber = subscriber; Predicate = predicate; }