public WindowedStreamConsumer([NotNull] WindowedStreamConsumerSettings <T, TKey> settings, [CanBeNull] ILog log)
            : base(settings, log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = (log ?? LogProvider.Get()).ForContext <WindowedStreamConsumer <T, TKey> >();
            tracer        = settings.Tracer ?? TracerProvider.Get();

            windows = new Dictionary <TKey, Windows <T, TKey> >();

            var applicationMetricContext = settings.ApplicationMetricContext ?? new DevNullMetricContext();

            eventLagMetric = applicationMetricContext.CreateHistogram("eventLag", new HistogramConfig {
                Buckets = HistogramHelper.CreateDefaultBuckets(), Unit = WellKnownUnits.Milliseconds
            });

            var instanceMetricContext = settings.InstanceMetricContext ?? new DevNullMetricContext();

            stateMetric = instanceMetricContext.CreateIntegerGauge("state", "type");

            var settingsOnBatchEnd = settings.OnBatchEnd;

            settings.OnBatchEnd = c =>
            {
                FlushWindows();
                Task.Run(() => settings.LeftCoordinatesStorage.AdvanceAsync(leftCoordinates));
                settingsOnBatchEnd?.Invoke(c);
            };

            var settingsOnEvent = settings.OnEvent;

            settings.OnEvent = (e, c) =>
            {
                AddEvent(e, c);
                settingsOnEvent?.Invoke(e, c);
            };

            var settingsOnRestart = settings.OnRestart;

            settings.OnRestart = c =>
            {
                Restart(c).GetAwaiter().GetResult();
                settingsOnRestart?.Invoke(c);
            };

            var settingsOnStop = settings.OnStop;

            settings.OnStop = c =>
            {
                Stop(c).GetAwaiter().GetResult();
                settingsOnStop?.Invoke(c);
            };
        }
Ejemplo n.º 2
0
        public WindowedStreamConsumer([NotNull] WindowedStreamConsumerSettings <T, TKey> settings, [CanBeNull] ILog log)
            : base(settings, log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = (log ?? LogProvider.Get()).ForContext <WindowedStreamConsumer <T, TKey> >();
            tracer        = settings.Tracer ?? TracerProvider.Get();

            windows = new Dictionary <TKey, Windows <T, TKey> >();

            var settingsOnBatchEnd = settings.OnBatchEnd;

            settings.OnBatchEnd = c =>
            {
                FlushWindows();
                settings.LeftCoordinatesStorage.AdvanceAsync(leftCoordinates);
                settingsOnBatchEnd?.Invoke(c);
            };

            var settingsOnEvent = settings.OnEvent;

            settings.OnEvent = (e, c) =>
            {
                AddEvent(e, c);
                settingsOnEvent?.Invoke(e, c);
            };

            var settingsOnRestart = settings.OnRestart;

            settings.OnRestart = c =>
            {
                Restart(c).GetAwaiter().GetResult();
                settingsOnRestart?.Invoke(c);
            };

            var metricContext = settings.MetricContext ?? new DevNullMetricContext();

            stateMetric = metricContext.CreateIntegerGauge("state", "type");
        }