Beispiel #1
0
 /// <summary> Initializes this node to contain the upper half of nodes from the given node (and removes them from the given one). </summary>
 public void CopyHalf(RoutingNode node)
 {
     _count       = node._count / 2;
     node._count -= _count;
     Array.Copy(_keys, 0, node._keys, node._count, _count);
     Array.Copy(_nodes, 0, node._nodes, node._count, _count);
 }
Beispiel #2
0
        public RouterTile(
            DrawingElement drawing,
            RoutingNode router,
            DashboardConfiguration.NodeConfiguration nodeConfiguration,
            TrafficIndicatorConfiguration trafficIndicatorConfiguration)
            : base(
                drawing,
                nodeConfiguration?.Title ?? "Router",
                "router",
                router.Offline,
                2,
                router.Name)
        {
            _drawing = drawing;
            _router  = router;
            _trafficIndicatorThresholds = trafficIndicatorConfiguration.Thresholds;

            LinkUrl = "/ui/node?name=" + router.Name;

            var details = new List <string>();

            if (router.Outputs != null)
            {
                _outputDrawings = router.Outputs
                                  .Select(o => new RouterOutputDrawing(drawing, o, o.RouteTo, null, router.Offline || o.Disabled))
                                  .ToArray();

                foreach (var outputDrawing in _outputDrawings)
                {
                    AddChild(outputDrawing);
                }
            }

            AddDetails(details, null, router.Offline ? "disabled" : string.Empty);
        }
Beispiel #3
0
        private Node SplitNode(Node child)
        {
            DataNode childDataNode = child as DataNode;

            if (childDataNode != null)
            {
                // Prepare new node
                DataNode newDataNode = AcquireDataNode();
                newDataNode._prior = childDataNode;
                newDataNode._next  = childDataNode._next;
                newDataNode.CopyHalf(childDataNode);

                // Update child node
                if (childDataNode._next != null)
                {
                    childDataNode._next._prior = newDataNode;
                }
                childDataNode._next = newDataNode;

                return(newDataNode);
            }
            else
            {
                RoutingNode newRoutingNode = AcquireRoutingNode();
                newRoutingNode.CopyHalf((RoutingNode)child);
                return(newRoutingNode);
            }
        }
Beispiel #4
0
            public override void PrependTo(Node node)
            {
                RoutingNode target = node as RoutingNode;

                for (int i = 0; i < _count; i++)
                {
                    target.InsertNode(_keys[i], _nodes[i], i);
                }
            }
Beispiel #5
0
            public override void AppendTo(Node node, int count)
            {
                RoutingNode target = node as RoutingNode;

                for (int i = 0; i < count; i++)
                {
                    target.InsertNode(_keys[i], _nodes[i], target._count);
                }
                Array.Copy(_keys, count, _keys, 0, _count - count);
                Array.Copy(_nodes, count, _nodes, 0, _count - count);
                _count -= count;
            }
Beispiel #6
0
        private void RelinquishRoutingNode(RoutingNode node)
        {
                        #if (DEBUG)
            _routingNodeCount--;
                        #endif

            if (_freeRoutingNodeCount == _freeRoutingNodes.Length)
            {
                RoutingNode[] newValue = new RoutingNode[_freeRoutingNodes.Length + (_freeRoutingNodes.Length / 2)];
                Array.Copy(_freeRoutingNodes, 0, newValue, 0, _freeRoutingNodes.Length);
                _freeRoutingNodes = newValue;
            }
            _freeRoutingNodes[_freeRoutingNodeCount] = node;
            _freeRoutingNodeCount++;
        }
Beispiel #7
0
 private void ConfigureRouterNodes(NodeGraphConfiguration configuration, List <INode> nodes)
 {
     if (configuration.RouterNodes != null)
     {
         foreach (var routerNodeConfiguration in configuration.RouterNodes)
         {
             var node = new RoutingNode(_expressionParser)
             {
                 Name     = routerNodeConfiguration.Name,
                 Disabled = routerNodeConfiguration.Disabled,
                 Outputs  = routerNodeConfiguration.Outputs
             };
             routerNodeConfiguration.Node = node;
             nodes.Add(node);
         }
     }
 }
Beispiel #8
0
        public bool Delete(IComparable key)
        {
            bool result = _root.Delete(key, this);

            if (result)
            {
                RoutingNode routingRoot = _root as RoutingNode;
                if ((routingRoot != null) && (routingRoot._count == 1))
                {
                    // Collapse the tree if there is only one node in the root (routing node)
                    _root = routingRoot._nodes[0];
                    RelinquishRoutingNode(routingRoot);

                                        #if (DEBUG)
                    _height--;
                                        #endif
                }
                _count--;
            }
            return(result);
        }
Beispiel #9
0
        public void Insert(IComparable key, object data)
        {
            for (;;)
            {
                if (!_root.Insert(key, data, this))
                {
                    RoutingNode newRoot  = AcquireRoutingNode();
                    Node        newChild = SplitNode(_root);
                    newRoot.InsertNode(_root._keys[0], _root, 0);
                    newRoot.InsertNode(newChild._keys[0], newChild, 1);
                    _root = newRoot;

                                        #if (DEBUG)
                    _height++;
                                        #endif

                    continue;
                }
                break;
            }
            _count++;
        }
Beispiel #10
0
        public RouterStats(
            DrawingElement drawing,
            RoutingNode router,
            DashboardConfiguration dashboardConfiguration)
            : base(drawing)
        {
            var nodeConfiguration = FindNodeConfiguration(dashboardConfiguration, router.Name);

            var topSection         = AddSection();
            var methodsSection     = AddSection();
            var statusCodesSection = AddSection();

            topSection.AddChild(new RouterTile(drawing, router, nodeConfiguration, dashboardConfiguration.TrafficIndicator));

            var requestRateData = new Tuple <string, float> [router.OutputNodes.Length];

            for (var i = 0; i < router.OutputNodes.Length; i++)
            {
                var nodeName  = router.OutputNodes[i].Name;
                var nodeTitle = FindNodeTitle(dashboardConfiguration, nodeName);

                requestRateData[i] = new Tuple <string, float>(
                    nodeTitle,
                    (float)router.OutputNodes[i].TrafficAnalytics.RequestsPerMinute);
            }

            topSection.AddChild(CreatePieChart("Request Rate", "/min", requestRateData, TotalHandling.Sum, "rate_piechart"));

            var requestTimeData = new Tuple <string, float> [router.OutputNodes.Length];

            for (var i = 0; i < router.OutputNodes.Length; i++)
            {
                var nodeName  = router.OutputNodes[i].Name;
                var nodeTitle = FindNodeTitle(dashboardConfiguration, nodeName);

                requestTimeData[i] = new Tuple <string, float>(
                    nodeTitle,
                    (float)router.OutputNodes[i].TrafficAnalytics.RequestTime.TotalMilliseconds);
            }

            topSection.AddChild(CreatePieChart("Request Time", "ms", requestTimeData, TotalHandling.Maximum, "time_piechart"));

            for (var i = 0; i < router.OutputNodes.Length; i++)
            {
                var nodeName  = router.OutputNodes[i].Name;
                var nodeTitle = FindNodeTitle(dashboardConfiguration, nodeName);

                var methodsPerMinute     = router.OutputNodes[i].TrafficAnalytics.MethodsPerMinute;
                var statusCodesPerMinute = router.OutputNodes[i].TrafficAnalytics.StatusCodesPerMinute;

                Tuple <string, float>[] methodData;
                lock (methodsPerMinute)
                {
                    var methods = methodsPerMinute.Keys.ToList();
                    methodData = new Tuple <string, float> [methods.Count];

                    for (var j = 0; j < methods.Count; j++)
                    {
                        methodData[j] = new Tuple <string, float>(methods[j], (float)methodsPerMinute[methods[j]]);
                    }
                }
                methodsSection.AddChild(CreatePieChart(nodeTitle + " Methods", "/min", methodData, TotalHandling.Sum, "method_piechart"));

                Tuple <string, float>[] statusCodeData;
                lock (statusCodesPerMinute)
                {
                    var statusCodes = statusCodesPerMinute.Keys.ToList();
                    statusCodeData = new Tuple <string, float> [statusCodes.Count];

                    for (var j = 0; j < statusCodes.Count; j++)
                    {
                        statusCodeData[j] = new Tuple <string, float>(statusCodes[j].ToString(), (float)statusCodesPerMinute[statusCodes[j]]);
                    }
                }
                statusCodesSection.AddChild(CreatePieChart(nodeTitle + " Status", "/min", statusCodeData, TotalHandling.Sum, "status_piechart"));
            }
        }
Beispiel #11
0
            public override bool Delete(IComparable key, IndexList list)
            {
                int  AClosestIndex;
                bool match = Search(0, key, out AClosestIndex);

                if (!match && AClosestIndex > 0)
                {
                    AClosestIndex--;
                }
                Node child = _nodes[AClosestIndex];

                match = child.Delete(key, list);
                if (match)
                {
                    int childCapacity = child._keys.Length;

                    // A Delete occurred, check for a possible merge
                    if (child._count < (childCapacity / 3))                     // if less than a third full
                    {
                        Node prior = (AClosestIndex == 0 ? null : _nodes[AClosestIndex - 1]);
                        Node next  = (AClosestIndex == (_count - 1) ? null : _nodes[AClosestIndex + 1]);
                        if
                        (                                                                                               // if there is enough room in the adjacent node(s) to handle this node's entries
                            (childCapacity * 2)
                            - ((prior == null ? 0 : prior._count) + (next == null ? 0 : next._count))
                            >= child._count
                        )
                        {
                            // Merge with adjacent nodes
                            if (prior != null)
                            {
                                int needed = (child._count / 2) + (child._count % 2);                                   // Assume half rounded up
                                child.AppendTo
                                (
                                    prior,
                                    Math.Min                                            // Append the lesser of the number of slots available in the prior node, and half of the items to allocate plus the number that the next will not be able to handle of its half
                                    (
                                        childCapacity - prior._count,
                                        needed + (next == null ? 0 : Math.Max(0, needed - (childCapacity - next._count)))
                                    )
                                );
                            }

                            if (next != null)
                            {
                                child.PrependTo(next);
                            }

                            DeleteNode(AClosestIndex);
                            RoutingNode routingChild = child as RoutingNode;
                            if (routingChild != null)
                            {
                                list.RelinquishRoutingNode(routingChild);
                            }
                            else
                            {
                                list.RelinquishDataNode((DataNode)child);
                            }
                        }
                    }
                }
                return(match);
            }