Пример #1
0
 public async Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     ISet<PubSubSubscriptionState> explicitRes = await explicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer);
     ISet<PubSubSubscriptionState> implicitRes = await implicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer);
     explicitRes.UnionWith(implicitRes);
     return explicitRes;
 }
Пример #2
0
        public async Task UnregisterProducer(StreamId streamId, IStreamProducerExtension streamProducer)
        {
            counterProducersRemoved.Increment();
            try
            {
                int numRemoved = State.Producers.RemoveWhere(s => s.Equals(streamId, streamProducer));
                LogPubSubCounts("UnregisterProducer {0} NumRemoved={1}", streamProducer, numRemoved);

                if (numRemoved > 0)
                {
                    Task updateStorageTask = State.Producers.Count == 0 && State.Consumers.Count == 0
                        ? ClearStateAsync() //State contains no producers or consumers, remove it from storage
                        : WriteStateAsync();
                    await updateStorageTask;
                }
                counterProducersTotal.DecrementBy(numRemoved);
            }
            catch (Exception exc)
            {
                logger.Error(ErrorCode.Stream_UnegisterProducerFailed,
                             $"Failed to unregister a stream producer.  Stream: {streamId}, Producer: {streamProducer}", exc);
                // Corrupted state, deactivate grain.
                DeactivateOnIdle();
                throw;
            }
            if (State.Producers.Count == 0 && State.Consumers.Count == 0)
            {
                DeactivateOnIdle(); // No producers or consumers left now, so flag ourselves to expedite Deactivation
            }
        }
        private async Task RegisterAsStreamProducer(StreamId streamId, StreamSequenceToken streamStartToken)
        {
            try
            {
                if (pubSub == null)
                {
                    throw new NullReferenceException("Found pubSub reference not set up correctly in RetreaveNewStream");
                }

                IStreamProducerExtension       meAsStreamProducer = this.AsReference <IStreamProducerExtension>();
                ISet <PubSubSubscriptionState> streamData         = await pubSub.RegisterProducer(streamId, streamProviderName, meAsStreamProducer);

                if (logger.IsVerbose)
                {
                    logger.Verbose(ErrorCode.PersistentStreamPullingAgent_16, "Got back {0} Subscribers for stream {1}.", streamData.Count, streamId);
                }

                var addSubscriptionTasks = new List <Task>(streamData.Count);
                foreach (PubSubSubscriptionState item in streamData)
                {
                    addSubscriptionTasks.Add(AddSubscriber_Impl(item.SubscriptionId, item.Stream, item.Consumer, streamStartToken, item.Filter));
                }
                await Task.WhenAll(addSubscriptionTasks);
            }
            catch (Exception exc)
            {
                // RegisterAsStreamProducer is fired with .Ignore so we should log if anything goes wrong, because there is no one to catch the exception
                logger.Error(ErrorCode.PersistentStreamPullingAgent_17, "Ignored RegisterAsStreamProducer Error", exc);
                throw;
            }
        }
Пример #4
0
 /// accept and notify only Active producers.
 private static bool IsActiveProducer(IStreamProducerExtension producer)
 {
     var grainRef = producer.AsReference();
     if (grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget)
         return RuntimeClient.Current.GetSiloStatus(grainRef.SystemTargetSilo).Equals(SiloStatus.Active);
     
     return true;
 }
Пример #5
0
        private static bool IsDeadProducer(IStreamProducerExtension producer)
        {
            var grainRef = producer as GrainReference;

            if (grainRef != null && grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget)
            {
                return(RuntimeClient.Current.GetSiloStatus(grainRef.SystemTargetSilo).Equals(SiloStatus.Dead));
            }

            return(false);
        }
Пример #6
0
        /// accept and notify only Active producers.
        private bool IsActiveProducer(IStreamProducerExtension producer)
        {
            var grainRef = producer as GrainReference;

            if (grainRef != null && grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget)
            {
                return(siloStatusOracle.GetApproximateSiloStatus(grainRef.SystemTargetSilo) == SiloStatus.Active);
            }

            return(true);
        }
Пример #7
0
        /// accept and notify only Active producers.
        private static bool IsActiveProducer(IStreamProducerExtension producer)
        {
            var grainRef = producer as GrainReference;

            if (grainRef != null && grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget)
            {
                return(RuntimeClient.Current.GetSiloStatus(grainRef.SystemTargetSilo) == SiloStatus.Active);
            }

            return(true);
        }
Пример #8
0
 public bool Equals(InternalStreamId streamId, IStreamProducerExtension streamProducer)
 {
     if (Stream == default)
     {
         return(false);
     }
     if (ReferenceEquals(null, Producer))
     {
         return(false);
     }
     return(Stream.Equals(streamId) && Producer.Equals(streamProducer));
 }
Пример #9
0
 public bool Equals(StreamId streamId, IStreamProducerExtension streamProducer)
 {
     if (ReferenceEquals(null, Stream))
     {
         return(false);
     }
     if (ReferenceEquals(null, Producer))
     {
         return(false);
     }
     return(Stream.Equals(streamId) && Producer.Equals(streamProducer));
 }
Пример #10
0
        public async Task UnregisterProducer(StreamId streamId, IStreamProducerExtension streamProducer)
        {
            int numRemoved = State.Producers.RemoveWhere(s => s.Equals(streamId, streamProducer));
            counterProducersRemoved.Increment();
            counterProducersTotal.DecrementBy(numRemoved);
            LogPubSubCounts("UnregisterProducer {0} NumRemoved={1}", streamProducer, numRemoved);

            if (numRemoved > 0)
                await State.WriteStateAsync();
            
            if (State.Producers.Count == 0 && State.Consumers.Count == 0)
                DeactivateOnIdle(); // No producers or consumers left now, so flag ourselves to expedite Deactivation
        }
Пример #11
0
        private async Task <ISet <PubSubSubscriptionState> > RegisterProducer()
        {
            var tup = await providerRuntime.BindExtension <SimpleMessageStreamProducerExtension, IStreamProducerExtension>(
                () => new SimpleMessageStreamProducerExtension(providerRuntime, fireAndForgetDelivery));

            myExtension      = tup.Item1;
            myGrainReference = tup.Item2;

            myExtension.AddStream(stream.StreamId);

            // Notify streamRendezvous about new stream streamProducer. Retreave the list of RemoteSubscribers.
            return(await pubSub.RegisterProducer(stream.StreamId, streamProviderName, myGrainReference));
        }
Пример #12
0
        public Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
        {
            ISet<PubSubSubscriptionState> result = new HashSet<PubSubSubscriptionState>();
            if (String.IsNullOrWhiteSpace(streamId.Namespace)) return Task.FromResult(result);

            IDictionary<Guid, IStreamConsumerExtension> implicitSubscriptions = implicitTable.GetImplicitSubscribers(streamId);
            foreach (var kvp in implicitSubscriptions)
            {
                GuidId subscriptionId = GuidId.GetGuidId(kvp.Key);
                result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value));
            }
            return Task.FromResult(result);
        }
Пример #13
0
        async Task<ISet<PubSubSubscriptionState>> IStreamPubSub.RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
        {
            var matches = new PubSubSubscriptionState[0];

            if (ShouldMatch(streamProvider))
            {
                matches = (from StreamPubSubMatch m in matcher(new StreamIdentity(streamId))
                           let subId = GuidId.GetNewGuidId()
                           select new PubSubSubscriptionState(subId, streamId, new PushExtension(m), null))
                          .ToArray();
            }

            var registered = await registry.RegisterProducer(streamId, streamProvider, streamProducer);
            registered.UnionWith(matches);

            return registered;
        }
Пример #14
0
        private async Task RegisterAsStreamProducer(InternalStreamId streamId, StreamSequenceToken streamStartToken)
        {
            try
            {
                if (pubSub == null)
                {
                    throw new NullReferenceException("Found pubSub reference not set up correctly in RetrieveNewStream");
                }

                IStreamProducerExtension       meAsStreamProducer = this.AsReference <IStreamProducerExtension>();
                ISet <PubSubSubscriptionState> streamData         = null;
                await AsyncExecutorWithRetries.ExecuteWithRetries(
                    async i => { streamData =
                                     await PubsubRegisterProducer(pubSub, streamId, meAsStreamProducer, logger); },
                    AsyncExecutorWithRetries.INFINITE_RETRIES,
                    (exception, i) => !IsShutdown,
                    Constants.INFINITE_TIMESPAN,
                    DeliveryBackoffProvider);


                if (logger.IsEnabled(LogLevel.Debug))
                {
                    logger.LogDebug(
                        (int)ErrorCode.PersistentStreamPullingAgent_16,
                        "Got back {Count} subscribers for stream {StreamId}.",
                        streamData.Count,
                        streamId);
                }

                var addSubscriptionTasks = new List <Task>(streamData.Count);
                foreach (PubSubSubscriptionState item in streamData)
                {
                    addSubscriptionTasks.Add(AddSubscriber_Impl(item.SubscriptionId, item.Stream, item.Consumer, item.FilterData, streamStartToken));
                }
                await Task.WhenAll(addSubscriptionTasks);
            }
            catch (Exception exc)
            {
                // RegisterAsStreamProducer is fired with .Ignore so we should log if anything goes wrong, because there is no one to catch the exception
                logger.LogError((int)ErrorCode.PersistentStreamPullingAgent_17, exc, "Ignored RegisterAsStreamProducer error");
                throw;
            }
        }
Пример #15
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return(TaskDone.Done);
 }
Пример #16
0
        public Task <ISet <PubSubSubscriptionState> > RegisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer)
        {
            var streamRendezvous = GetRendezvousGrain(streamId);

            return(streamRendezvous.RegisterProducer(streamId, streamProducer));
        }
Пример #17
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return(IsImplicitSubscriber(streamProducer, streamId) ? TaskDone.Done :
            explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer));
 }
Пример #18
0
 // This constructor has to be public for JSonSerialization to work!
 // Implement ISerializable if changing it to non-public
 public PubSubPublisherState(StreamId streamId, IStreamProducerExtension streamProducer)
 {
     Stream   = streamId;
     Producer = streamProducer;
 }
Пример #19
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return(Task.CompletedTask);
 }
Пример #20
0
 Task IStreamPubSub.UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return(registry.UnregisterProducer(streamId, streamProvider, streamProducer));
 }
Пример #21
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return(explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer));
 }
        private static async Task <ISet <PubSubSubscriptionState> > PubsubRegisterProducer(IStreamPubSub pubSub, InternalStreamId streamId,
                                                                                           IStreamProducerExtension meAsStreamProducer, ILogger logger)
        {
            try
            {
                var streamData = await pubSub.RegisterProducer(streamId, meAsStreamProducer);

                return(streamData);
            }
            catch (Exception e)
            {
                logger.Error(ErrorCode.PersistentStreamPullingAgent_17, $"RegisterAsStreamProducer failed due to {e}", e);
                throw;
            }
        }
Пример #23
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer);
 }
Пример #24
0
 public Task UnregisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer)
 {
     return(explicitPubSub.UnregisterProducer(streamId, streamProducer));
 }
Пример #25
0
 public Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     var streamRendezvous = GetRendezvousGrain(streamId);
     return streamRendezvous.RegisterProducer(streamId, streamProducer);
 }
Пример #26
0
 public async Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, IStreamProducerExtension streamProducer)
 {
     if (!IsActiveProducer(streamProducer))
         throw new ArgumentException(String.Format("Trying to register non active IStreamProducerExtension: {0}", streamProducer.ToString()), "streamProducer");
     
     RemoveDeadProducers();
     
     var publisherState = new PubSubPublisherState(streamId, streamProducer);
     State.Producers.Add(publisherState);
     counterProducersAdded.Increment();
     counterProducersTotal.Increment();
     LogPubSubCounts("RegisterProducer {0}", streamProducer);
     await State.WriteStateAsync();
     return State.Consumers;
 }
Пример #27
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     var streamRendezvous = GetRendezvousGrain(streamId);
     return streamRendezvous.UnregisterProducer(streamId, streamProducer);
 }
Пример #28
0
        public Task UnregisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer)
        {
            var streamRendezvous = GetRendezvousGrain(streamId);

            return(streamRendezvous.UnregisterProducer(streamId, streamProducer));
        }
Пример #29
0
        public async Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
        {
            ISet<PubSubSubscriptionState> result = await explicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer);
            if (String.IsNullOrWhiteSpace(streamId.Namespace)) return result;

            IDictionary<Guid,IStreamConsumerExtension> implicitSubscriptions = implicitPubSub.GetImplicitSubscribers(streamId);
            foreach (var kvp in implicitSubscriptions)
            {
                GuidId subscriptionId = GuidId.GetGuidId(kvp.Key);
                // we ignore duplicate entries-- there's no way a programmer could prevent the duplicate entry from being added if we threw an exception to communicate the problem. 
                result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value, null, null));
            }
            return result;
        }
Пример #30
0
 public Task UnregisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer)
 {
     return(Task.CompletedTask);
 }
Пример #31
0
 // This constructor has to be public for JSonSerialization to work!
 // Implement ISerializable if changing it to non-public
 public PubSubPublisherState(StreamId streamId, IStreamProducerExtension streamProducer)
 {
     Stream            = streamId;
     producerReference = streamProducer as GrainReference;
 }
Пример #32
0
        public Task <ISet <PubSubSubscriptionState> > RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
        {
            ISet <PubSubSubscriptionState> result = new HashSet <PubSubSubscriptionState>();

            if (!ImplicitStreamSubscriberTable.IsImplicitSubscribeEligibleNameSpace(streamId.Namespace))
            {
                return(Task.FromResult(result));
            }

            IDictionary <Guid, IStreamConsumerExtension> implicitSubscriptions = implicitTable.GetImplicitSubscribers(streamId, this.grainFactory);

            foreach (var kvp in implicitSubscriptions)
            {
                GuidId subscriptionId = GuidId.GetGuidId(kvp.Key);
                result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value));
            }
            return(Task.FromResult(result));
        }
Пример #33
0
 Task IStreamPubSub.UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return registry.UnregisterProducer(streamId, streamProvider, streamProducer);
 }
Пример #34
0
        async Task <ISet <PubSubSubscriptionState> > IStreamPubSub.RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
        {
            var matches = new PubSubSubscriptionState[0];

            if (ShouldMatch(streamProvider))
            {
                matches = (from StreamPubSubMatch m in matcher(new StreamIdentity(streamId))
                           let subId = GuidId.GetNewGuidId()
                                       select new PubSubSubscriptionState(subId, streamId, new PushExtension(m), null))
                          .ToArray();
            }

            var registered = await registry.RegisterProducer(streamId, streamProvider, streamProducer);

            registered.UnionWith(matches);

            return(registered);
        }
Пример #35
0
        public async Task <ISet <PubSubSubscriptionState> > RegisterProducer(StreamId streamId, IStreamProducerExtension streamProducer)
        {
            counterProducersAdded.Increment();

            try
            {
                var publisherState = new PubSubPublisherState(streamId, streamProducer);
                State.Producers.Add(publisherState);
                LogPubSubCounts("RegisterProducer {0}", streamProducer);
                await WriteStateAsync();

                counterProducersTotal.Increment();
            }
            catch (Exception exc)
            {
                logger.Error(ErrorCode.Stream_RegisterProducerFailed, $"Failed to register a stream producer.  Stream: {streamId}, Producer: {streamProducer}", exc);
                // Corrupted state, deactivate grain.
                DeactivateOnIdle();
                throw;
            }
            return(State.Consumers.Where(c => !c.IsFaulted).ToSet());
        }
Пример #36
0
        public async Task <ISet <PubSubSubscriptionState> > RegisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer)
        {
            ISet <PubSubSubscriptionState> explicitRes = await explicitPubSub.RegisterProducer(streamId, streamProducer);

            ISet <PubSubSubscriptionState> implicitRes = await implicitPubSub.RegisterProducer(streamId, streamProducer);

            explicitRes.UnionWith(implicitRes);
            return(explicitRes);
        }
Пример #37
0
        public async Task <ISet <PubSubSubscriptionState> > RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
        {
            ISet <PubSubSubscriptionState> result = await explicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer);

            if (String.IsNullOrWhiteSpace(streamId.Namespace))
            {
                return(result);
            }

            IDictionary <Guid, IStreamConsumerExtension> implicitSubscriptions = implicitPubSub.GetImplicitSubscribers(streamId);

            foreach (var kvp in implicitSubscriptions)
            {
                GuidId subscriptionId = GuidId.GetGuidId(kvp.Key);
                // we ignore duplicate entries-- there's no way a programmer could prevent the duplicate entry from being added if we threw an exception to communicate the problem.
                result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value, null, null));
            }
            return(result);
        }
Пример #38
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return TaskDone.Done;
 }
Пример #39
0
 public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer)
 {
     return IsImplicitSubscriber(streamProducer, streamId) ? TaskDone.Done : 
         explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer);
 }