Esempio n. 1
0
        internal object?GetSubscriptionState(MeterListener listener)
        {
            LinkedListNode <ListenerSubscription>?current = _subscriptions.First;

            while (current is not null)
            {
                if (object.ReferenceEquals(listener, current.Value.Listener))
                {
                    return(current.Value.State);
                }
                current = current.Next;
            }

            return(null);
        }
Esempio n. 2
0
        internal override void Observe(MeterListener listener)
        {
            object?state = GetSubscriptionState(listener);

            IEnumerable <Measurement <T> > measurements = Observe();

            if (measurements is null)
            {
                return;
            }

            foreach (Measurement <T> measurement in measurements)
            {
                listener.NotifyMeasurement(this, measurement.Value, measurement.Tags, state);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Publish is activating the instrument to start recording measurements and to allow listeners to start listening to such measurements.
        /// </summary>
        protected void Publish()
        {
            List <MeterListener>?allListeners = null;

            lock (Instrument.SyncObject)
            {
                if (Meter.Disposed || !Meter.AddInstrument(this))
                {
                    return;
                }

                allListeners = MeterListener.GetAllListeners();
            }

            if (allListeners is not null)
            {
                foreach (MeterListener listener in allListeners)
                {
                    listener.InstrumentPublished?.Invoke(this, listener);
                }
            }
        }
Esempio n. 4
0
        // Called from MeterListener.Start
        internal static void NotifyListenerWithAllPublishedInstruments(MeterListener listener)
        {
            Action <Instrument, MeterListener>?instrumentPublished = listener.InstrumentPublished;

            if (instrumentPublished is null)
            {
                return;
            }

            LinkedListNode <Meter>?current = s_allMeters.First;

            while (current is not null)
            {
                LinkedListNode <Instrument>?currentInstrument = current.Value._instruments?.First;
                while (currentInstrument is not null)
                {
                    instrumentPublished.Invoke(currentInstrument.Value, listener);
                    currentInstrument = currentInstrument.Next;
                }
                current = current.Next;
            }
        }
Esempio n. 5
0
 internal virtual void Observe(MeterListener listener)
 {
     Debug.Assert(false);
     throw new InvalidOperationException();
 }
Esempio n. 6
0
 // Called from MeterListener.DisableMeasurementEvents
 internal object?DisableMeasurements(MeterListener listener) => _subscriptions.Remove(new ListenerSubscription(listener), (s1, s2) => object.ReferenceEquals(s1.Listener, s2.Listener)).State;
Esempio n. 7
0
 /// <summary>
 /// Publish is activating the instrument to start recording measurements and to allow listeners to start listening to such measurements.
 /// </summary>
 protected void Publish()
 {
     Meter.AddInstrument(this);
     MeterListener.NotifyForPublishedInstrument(this);
 }