Beispiel #1
0
 internal CommunicatorObserver(Communicator communicator, ILogger logger)
 {
     AdminFacet   = new MetricsAdmin(communicator, logger);
     _delegate    = communicator.Observer;
     _connections = new ObserverFactoryWithDelegate <ConnectionMetrics, ConnectionObserver,
                                                     IConnectionObserver>(AdminFacet, "Connection");
     _dispatch = new ObserverFactoryWithDelegate <DispatchMetrics, DispatchObserver, IDispatchObserver>(
         AdminFacet, "Dispatch");
     _invocations = new ObserverFactoryWithDelegate <InvocationMetrics, InvocationObserver,
                                                     IInvocationObserver>(AdminFacet, "Invocation");
     _connects = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegate,
                                                  IObserver>(AdminFacet, "ConnectionEstablishment");
     _endpointLookups = new ObserverFactoryWithDelegate <Metrics, ObserverWithDelegate,
                                                         IObserver>(AdminFacet, "EndpointLookup");
     _invocations.RegisterSubMap <ChildInvocationMetrics>("ChildInvocation",
                                                          (obj, metrics) => (obj as InvocationMetrics) !.Children = metrics);
 }
Beispiel #2
0
        internal MetricsMap(string mapPrefix, Communicator communicator, Dictionary <string, ISubMapFactory>?subMaps)
        {
            MetricsAdmin.ValidateProperties(mapPrefix, communicator);
            _properties = communicator.GetProperties(forPrefix: mapPrefix);

            _retain = communicator.GetPropertyAsInt($"{mapPrefix}RetainDetached") ?? 10;
            _accept = ParseRule(communicator, $"{mapPrefix}Accept");
            _reject = ParseRule(communicator, $"{mapPrefix}Reject");
            var groupByAttributes = new List <string>();
            var groupBySeparators = new List <string>();

            string groupBy = communicator.GetProperty($"{mapPrefix}GroupBy") ?? "id";

            if (groupBy.Length > 0)
            {
                string v         = "";
                bool   attribute = char.IsLetter(groupBy[0]) || char.IsDigit(groupBy[0]);
                if (!attribute)
                {
                    groupByAttributes.Add("");
                }

                foreach (char p in groupBy)
                {
                    bool isAlphaNum = char.IsLetter(p) || char.IsDigit(p) || p == '.';
                    if (attribute && !isAlphaNum)
                    {
                        groupByAttributes.Add(v);
                        v         = "" + p;
                        attribute = false;
                    }
                    else if (!attribute && isAlphaNum)
                    {
                        groupBySeparators.Add(v);
                        v         = "" + p;
                        attribute = true;
                    }
                    else
                    {
                        v += p;
                    }
                }

                if (attribute)
                {
                    groupByAttributes.Add(v);
                }
                else
                {
                    groupBySeparators.Add(v);
                }
            }
            _groupByAttributes = groupByAttributes.ToImmutableList();
            _groupBySeparators = groupBySeparators.ToImmutableList();

            if (subMaps != null && subMaps.Count > 0)
            {
                _subMapCloneFactories = new Dictionary <string, ISubMapCloneFactory>();

                var subMapNames          = new List <string>();
                var subMapCloneFactories = new Dictionary <string, ISubMapCloneFactory>();
                foreach ((string key, ISubMapFactory value) in subMaps)
                {
                    subMapNames.Add(key);
                    string subAllMapsPrefix = $"{mapPrefix}Map.";
                    string subMapPrefix     = $"{subAllMapsPrefix}{key}.";
                    if (communicator.GetProperties(forPrefix: subMapPrefix).Count == 0)
                    {
                        if (communicator.GetProperties(forPrefix: subAllMapsPrefix).Count == 0)
                        {
                            subMapPrefix = mapPrefix;
                        }
                        else
                        {
                            continue; // This sub-map isn't configured.
                        }
                    }

                    subMapCloneFactories.Add(key, value.CreateCloneFactory(subMapPrefix, communicator));
                }
                _subMapCloneFactories = subMapCloneFactories.ToImmutableDictionary();
            }
            else
            {
                _subMapCloneFactories = null;
            }
        }