Exemple #1
0
        public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle)
        {
            await BindExtensionLazy();

            StreamSubscriptionHandleImpl <T> handleImpl = CheckHandleValidity(handle);

            if (logger.IsVerbose)
            {
                logger.Verbose("Unsubscribe StreamSubscriptionHandle={0}", handle);
            }
            bool shouldUnsubscribe = myExtension.RemoveObserver(handle);

            if (!shouldUnsubscribe)
            {
                return;
            }

            if (logger.IsVerbose)
            {
                logger.Verbose("Unsubscribe - Disconnecting from Rendezvous {0} My GrainRef={1}",
                               pubSub, myGrainReference);
            }

            await pubSub.UnregisterConsumer(handleImpl.SubscriptionId, stream.StreamId, streamProviderName);

            handleImpl.Invalidate();
        }
Exemple #2
0
        public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle)
        {
            await BindExtensionLazy();

            if (logger.IsVerbose)
            {
                logger.Verbose("Unsubscribe StreamSubscriptionHandle={0}", handle);
            }
            bool shouldUnsubscribe = myExtension.RemoveObserver(handle);

            if (!shouldUnsubscribe)
            {
                return;
            }

            try
            {
                if (logger.IsVerbose)
                {
                    logger.Verbose("Unsubscribe - Disconnecting from Rendezvous {0} My GrainRef={1}",
                                   pubSub, myGrainReference);
                }

                await pubSub.UnregisterConsumer(stream.StreamId, streamProviderName, myGrainReference);
            }
            finally
            {
                connectedToRendezvous = false;
            }
        }
Exemple #3
0
        private async Task <StreamSubscriptionHandle <T> > SubscribeAsyncImpl(
            IAsyncObserver <T> observer,
            IAsyncBatchObserver <T> batchObserver,
            StreamSequenceToken token,
            string filterData = null)
        {
            if (token != null && !IsRewindable)
            {
                throw new ArgumentNullException("token", "Passing a non-null token to a non-rewindable IAsyncObservable.");
            }
            if (observer is GrainReference)
            {
                throw new ArgumentException("On-behalf subscription via grain references is not supported. Only passing of object references is allowed.", nameof(observer));
            }
            if (batchObserver is GrainReference)
            {
                throw new ArgumentException("On-behalf subscription via grain references is not supported. Only passing of object references is allowed.", nameof(batchObserver));
            }

            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.Debug("Subscribe Token={Token}", token);
            }
            await BindExtensionLazy();

            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.Debug("Subscribe - Connecting to Rendezvous {0} My GrainRef={1} Token={2}",
                             pubSub, myGrainReference, token);
            }

            GuidId subscriptionId = pubSub.CreateSubscriptionId(stream.InternalStreamId, myGrainReference);

            // Optimistic Concurrency:
            // In general, we should first register the subsription with the pubsub (pubSub.RegisterConsumer)
            // and only if it succeeds store it locally (myExtension.SetObserver).
            // Basicaly, those 2 operations should be done as one atomic transaction - either both or none and isolated from concurrent reads.
            // BUT: there is a distributed race here: the first msg may arrive before the call is awaited
            // (since the pubsub notifies the producer that may immideately produce)
            // and will thus not find the subriptionHandle in the extension, basically violating "isolation".
            // Therefore, we employ Optimistic Concurrency Control here to guarantee isolation:
            // we optimisticaly store subscriptionId in the handle first before calling pubSub.RegisterConsumer
            // and undo it in the case of failure.
            // There is no problem with that we call myExtension.SetObserver too early before the handle is registered in pub sub,
            // since this subscriptionId is unique (random Guid) and no one knows it anyway, unless successfully subscribed in the pubsub.
            var subriptionHandle = myExtension.SetObserver(subscriptionId, stream, observer, batchObserver, token, filterData);

            try
            {
                await pubSub.RegisterConsumer(subscriptionId, stream.InternalStreamId, myGrainReference, filterData);

                return(subriptionHandle);
            }
            catch (Exception)
            {
                // Undo the previous call myExtension.SetObserver.
                myExtension.RemoveObserver(subscriptionId);
                throw;
            }
        }
Exemple #4
0
        public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle)
        {
            await BindExtensionLazy();

            StreamSubscriptionHandleImpl <T> handleImpl = CheckHandleValidity(handle);

            if (logger.IsVerbose)
            {
                logger.Verbose("Unsubscribe StreamSubscriptionHandle={0}", handle);
            }

            myExtension.RemoveObserver(handleImpl.SubscriptionId);
            // UnregisterConsumer from pubsub even if does not have this handle localy, to allow UnsubscribeAsync retries.

            if (logger.IsVerbose)
            {
                logger.Verbose("Unsubscribe - Disconnecting from Rendezvous {0} My GrainRef={1}",
                               pubSub, myGrainReference);
            }

            await pubSub.UnregisterConsumer(handleImpl.SubscriptionId, stream.StreamId, streamProviderName);

            handleImpl.Invalidate();
        }