Beispiel #1
0
        public void TestFindIndex()
        {
            List <FilterParamIndexBase> indexes = new List <FilterParamIndexBase>();

            // Create index list wity index that doesn't match
            FilterParamIndexBase indexOne = IndexFactory.CreateIndex(MakeLookupable("BoolPrimitive"), _lockFactory, FilterOperator.EQUAL);

            indexes.Add(indexOne);
            Assert.IsTrue(IndexHelper.FindIndex(_parameters, indexes) == null);

            // Create index list wity index that doesn't match
            indexOne = IndexFactory.CreateIndex(MakeLookupable("DoubleBoxed"), _lockFactory, FilterOperator.GREATER_OR_EQUAL);
            indexes.Clear();
            indexes.Add(indexOne);
            Assert.IsTrue(IndexHelper.FindIndex(_parameters, indexes) == null);

            // Add an index that does match a parameter
            FilterParamIndexBase indexTwo = IndexFactory.CreateIndex(MakeLookupable("DoubleBoxed"), _lockFactory, FilterOperator.GREATER);

            indexes.Add(indexTwo);
            Pair <FilterValueSetParam, FilterParamIndexBase> pair = IndexHelper.FindIndex(_parameters, indexes);

            Assert.IsTrue(pair != null);
            Assert.AreEqual(_parameterTwo, pair.First);
            Assert.AreEqual(indexTwo, pair.Second);

            // Add another index that does match a parameter, should return first match however which is doubleBoxed
            FilterParamIndexBase indexThree = IndexFactory.CreateIndex(MakeLookupable("IntPrimitive"), _lockFactory, FilterOperator.GREATER);

            indexes.Add(indexThree);
            pair = IndexHelper.FindIndex(_parameters, indexes);
            Assert.AreEqual(_parameterOne, pair.First);
            Assert.AreEqual(indexThree, pair.Second);

            // Try again removing one index
            indexes.Remove(indexTwo);
            pair = IndexHelper.FindIndex(_parameters, indexes);
            Assert.AreEqual(_parameterOne, pair.First);
            Assert.AreEqual(indexThree, pair.Second);
        }
Beispiel #2
0
        /// <summary>
        /// Add to the current node building up the tree path information.
        /// </summary>
        /// <param name="remainingParameters">The remaining parameters.</param>
        /// <param name="filterCallback">The filter callback.</param>
        /// <param name="currentNode">is the node to add to</param>
        /// <param name="treePathInfo">is filled with information about which indizes were chosen to add the filter to</param>
        /// <param name="lockFactory">The lock factory.</param>
        private static void AddToNode(
            ArrayDeque <FilterValueSetParam> remainingParameters,
            FilterHandle filterCallback,
            FilterHandleSetNode currentNode,
            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair> treePathInfo,
            FilterServiceGranularLockFactory lockFactory)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".addToNode (" + Thread.CurrentThread.ManagedThreadId + ") Adding filterCallback, node=" + currentNode +
                          "  remainingParameters=" + PrintRemainingParameters(remainingParameters));
            }

            // If no parameters are specified, add to current node, and done
            if (remainingParameters.IsEmpty())
            {
                using (currentNode.NodeRWLock.AcquireWriteLock())
                {
                    currentNode.Add(filterCallback);
                }
                return;
            }

            // Need to find an existing index that matches one of the filter parameters
            Pair <FilterValueSetParam, FilterParamIndexBase> pair;

            using (currentNode.NodeRWLock.AcquireReadLock())
            {
                pair = IndexHelper.FindIndex(remainingParameters, currentNode.Indizes);

                // Found an index matching a filter parameter
                if (pair != null)
                {
                    remainingParameters.Remove(pair.First);
                    var filterForValue = pair.First.FilterForValue;
                    var index          = pair.Second;
                    treePathInfo.Add(new EventTypeIndexBuilderIndexLookupablePair(index, filterForValue));
                    AddToIndex(remainingParameters, filterCallback, index, filterForValue, treePathInfo, lockFactory);
                    return;
                }
            }

            // An index for any of the filter parameters was not found, create one
            using (currentNode.NodeRWLock.AcquireWriteLock())
            {
                pair = IndexHelper.FindIndex(remainingParameters, currentNode.Indizes);

                // Attempt to find an index again this time under a write lock
                if (pair != null)
                {
                    remainingParameters.Remove(pair.First);
                    var filterForValue = pair.First.FilterForValue;
                    var indexX         = pair.Second;
                    treePathInfo.Add(new EventTypeIndexBuilderIndexLookupablePair(indexX, filterForValue));
                    AddToIndex(remainingParameters, filterCallback, indexX, filterForValue, treePathInfo, lockFactory);
                    return;
                }

                // No index found that matches any parameters, create a new one
                // Pick the next parameter for an index
                FilterValueSetParam parameterPickedForIndex = remainingParameters.RemoveFirst();

                var index = IndexFactory.CreateIndex(parameterPickedForIndex.Lookupable, lockFactory, parameterPickedForIndex.FilterOperator);

                currentNode.Indizes.Add(index);
                treePathInfo.Add(new EventTypeIndexBuilderIndexLookupablePair(index, parameterPickedForIndex.FilterForValue));
                AddToIndex(remainingParameters, filterCallback, index, parameterPickedForIndex.FilterForValue, treePathInfo, lockFactory);
            }
        }