示例#1
0
        public StreamConsumer(StreamImpl <T> stream, string streamProviderName, IStreamProviderRuntime providerUtilities, IStreamPubSub pubSub, bool isRewindable)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (providerUtilities == null)
            {
                throw new ArgumentNullException("providerUtilities");
            }
            if (pubSub == null)
            {
                throw new ArgumentNullException("pubSub");
            }

            logger                  = TraceLogger.GetLogger(string.Format("StreamConsumer<{0}>-{1}", typeof(T).Name, stream), TraceLogger.LoggerType.Runtime);
            this.stream             = stream;
            this.streamProviderName = streamProviderName;
            providerRuntime         = providerUtilities;
            this.pubSub             = pubSub;
            IsRewindable            = isRewindable;
            myExtension             = null;
            myGrainReference        = null;
            bindExtLock             = new AsyncLock();
        }
示例#2
0
        private async Task BindExtensionLazy()
        {
            if (myExtension == null)
            {
                using (await bindExtLock.LockAsync())
                {
                    if (myExtension == null)
                    {
                        if (logger.IsVerbose)
                        {
                            logger.Verbose("BindExtensionLazy - Binding local extension to stream runtime={0}", providerRuntime);
                        }
                        var tup = await providerRuntime.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>(
                            () => new StreamConsumerExtension(providerRuntime));

                        myExtension      = tup.Item1;
                        myGrainReference = tup.Item2;
                        if (logger.IsVerbose)
                        {
                            logger.Verbose("BindExtensionLazy - Connected Extension={0} GrainRef={1}", myExtension, myGrainReference);
                        }
                    }
                }
            }
        }
示例#3
0
        public StreamConsumer(StreamImpl <T> stream, string streamProviderName, IStreamProviderRuntime runtime, IStreamPubSub pubSub, ILogger logger, bool isRewindable)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (pubSub == null)
            {
                throw new ArgumentNullException(nameof(pubSub));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.logger             = logger;
            this.stream             = stream;
            this.streamProviderName = streamProviderName;
            this.providerRuntime    = runtime;
            this.pubSub             = pubSub;
            this.IsRewindable       = isRewindable;
            this.myExtension        = null;
            this.myGrainReference   = null;
            this.bindExtLock        = new AsyncLock();
        }
示例#4
0
        public async Task Cleanup()
        {
            if (logger.IsVerbose)
            {
                logger.Verbose("Cleanup() called");
            }
            if (myExtension == null)
            {
                return;
            }

            var allHandles = myExtension.GetAllStreamHandles <T>();
            var tasks      = new List <Task>();

            foreach (var handle in allHandles)
            {
                myExtension.RemoveObserver(handle.SubscriptionId);
                tasks.Add(pubSub.UnregisterConsumer(handle.SubscriptionId, stream.StreamId, streamProviderName));
            }
            try
            {
                await Task.WhenAll(tasks);
            } catch (Exception exc)
            {
                logger.Warn((int)ErrorCode.StreamProvider_ConsumerFailedToUnregister,
                            "Ignoring unhandled exception during PubSub.UnregisterConsumer", exc);
            }
            myExtension = null;
        }
示例#5
0
        public async Task Cleanup()
        {
            _ = RequestContextExtensions.SuppressCurrentCallChainFlow();

            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug("Cleanup() called");
            }
            if (myExtension == null)
            {
                return;
            }

            var allHandles = myExtension.GetAllStreamHandles <T>();
            var tasks      = new List <Task>();

            foreach (var handle in allHandles)
            {
                myExtension.RemoveObserver(handle.SubscriptionId);
                tasks.Add(pubSub.UnregisterConsumer(handle.SubscriptionId, stream.InternalStreamId));
            }
            try
            {
                await Task.WhenAll(tasks);
            } catch (Exception exc)
            {
                logger.LogWarning(
                    (int)ErrorCode.StreamProvider_ConsumerFailedToUnregister,
                    exc,
                    "Ignoring unhandled exception during PubSub.UnregisterConsumer");
            }
            myExtension = null;
        }