System.Collections.Generic.IDictionary.ContainsKey(LabelSet)

Here are the examples of the csharp api System.Collections.Generic.IDictionary.ContainsKey(LabelSet) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : CounterMetricSdkBase.cs
with Apache License 2.0
from SteeltoeOSS

internal BoundCounterMetric<T> Bind(LabelSet labelset, bool isShortLived)
        {
            BoundCounterMetricSdkBase<T> boundInstrument;

            lock (_bindUnbindLock)
            {
                if (!_counterBoundInstruments.TryGetValue(labelset, out boundInstrument))
                {
                    var recStatus = isShortLived ? RecordStatus.UpdatePending : RecordStatus.Bound;
                    boundInstrument = CreateMetric(recStatus);
                    _counterBoundInstruments.Add(labelset, boundInstrument);
                }
            }

            switch (boundInstrument.Status)
            {
                case RecordStatus.NoPendingUpdate:
                    boundInstrument.Status = RecordStatus.UpdatePending;
                    break;
                case RecordStatus.CandidateForRemoval:
                {
                    // if boundInstrument is marked for removal, then take the
                    // lock to sync with Unbind() and re-add. As Collect() might have called Unbind().

                    /*
                     * If Unbind gets the lock first, then it'd have removed the record.
                     * But it gets added again by Bind() so no record is lost.
                     * If Bind method gets this lock first, it'd promote record to UpdatePending, so that
                     * Unbind will leave this record untouched.

                     * Additional notes:
                     * This lock is never taken for bound instruments, and they offer the fastest performance.
                     * This lock is only taken for those labelsets which are marked CandidateForRemoval.
                     * It means the the 1st time a labelset is re-encountered after two Collect() has occured,
                     * this lock must be taken. Subsequent usage of this labelset before the next two Collect()
                     * will already have status promoted, and no lock is taken.
                     * In effect, the lock is only taken for those labelsets
                     * which was used once, then not used for two collect(), and then used within the subsequent
                     * Collect().
                     *
                     * Its important to note that, for a brand new LabelSet being encountered for the 1st time, lock is not
                     * taken. Lock is taken only during the 1st re-appearance of a LabelSet after a Collect period.
                     *
                     */

                    lock (_bindUnbindLock)
                    {
                        boundInstrument.Status = RecordStatus.UpdatePending;

                        if (!_counterBoundInstruments.ContainsKey(labelset))
                        {
                            _counterBoundInstruments.Add(labelset, boundInstrument);
                        }
                    }

                    break;
                }
            }

            return boundInstrument;
        }