예제 #1
0
        public void TestFindParameter()
        {
            FilterParamIndexBase indexOne = IndexFactory.CreateIndex(MakeLookupable("BoolPrimitive"), _lockFactory, FilterOperator.EQUAL);

            Assert.IsNull(IndexHelper.FindParameter(_parameters, indexOne));

            FilterParamIndexBase indexTwo = IndexFactory.CreateIndex(MakeLookupable("TheString"), _lockFactory, FilterOperator.EQUAL);

            Assert.AreEqual(_parameterThree, IndexHelper.FindParameter(_parameters, indexTwo));

            FilterParamIndexBase indexThree = IndexFactory.CreateIndex(MakeLookupable("IntPrimitive"), _lockFactory, FilterOperator.GREATER);

            Assert.AreEqual(_parameterOne, IndexHelper.FindParameter(_parameters, indexThree));
        }
예제 #2
0
        public void TestCreateIndex()
        {
            // Create a "greater" index
            FilterParamIndexBase index = IndexFactory.CreateIndex(MakeLookupable("IntPrimitive"), _lockFactory, FilterOperator.GREATER);

            Assert.IsTrue(index != null);
            Assert.IsTrue(index is FilterParamIndexCompare);
            Assert.IsTrue(GetPropName(index).Equals("IntPrimitive"));
            Assert.IsTrue(index.FilterOperator == FilterOperator.GREATER);

            // Create an "equals" index
            index = IndexFactory.CreateIndex(MakeLookupable("TheString"), _lockFactory, FilterOperator.EQUAL);

            Assert.IsTrue(index != null);
            Assert.IsTrue(index is FilterParamIndexEquals);
            Assert.AreEqual(GetPropName(index), "TheString");
            Assert.IsTrue(index.FilterOperator == FilterOperator.EQUAL);

            // Create an "not equals" index
            index = IndexFactory.CreateIndex(MakeLookupable("TheString"), _lockFactory, FilterOperator.NOT_EQUAL);

            Assert.IsTrue(index != null);
            Assert.IsTrue(index is FilterParamIndexNotEquals);
            Assert.AreEqual(GetPropName(index), "TheString");
            Assert.IsTrue(index.FilterOperator == FilterOperator.NOT_EQUAL);

            // Create a range index
            index = IndexFactory.CreateIndex(MakeLookupable("DoubleBoxed"), _lockFactory, FilterOperator.RANGE_CLOSED);
            Assert.IsTrue(index is FilterParamIndexDoubleRange);
            index = IndexFactory.CreateIndex(MakeLookupable("DoubleBoxed"), _lockFactory, FilterOperator.NOT_RANGE_CLOSED);
            Assert.IsTrue(index is FilterParamIndexDoubleRangeInverted);

            // Create a in-index
            index = IndexFactory.CreateIndex(MakeLookupable("DoubleBoxed"), _lockFactory, FilterOperator.IN_LIST_OF_VALUES);
            Assert.IsTrue(index is FilterParamIndexIn);
            index = IndexFactory.CreateIndex(MakeLookupable("DoubleBoxed"), _lockFactory, FilterOperator.NOT_IN_LIST_OF_VALUES);
            Assert.IsTrue(index is FilterParamIndexNotIn);

            // Create a boolean-expression-index
            index = IndexFactory.CreateIndex(MakeLookupable("boolean"), _lockFactory, FilterOperator.BOOLEAN_EXPRESSION);
            Assert.IsTrue(index is FilterParamIndexBooleanExpr);
            index = IndexFactory.CreateIndex(MakeLookupable("boolean"), _lockFactory, FilterOperator.BOOLEAN_EXPRESSION);
            Assert.IsTrue(index is FilterParamIndexBooleanExpr);
        }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// Add to an index the value to filter for.
        /// </summary>
        /// <param name="remainingParameters">The remaining parameters.</param>
        /// <param name="filterCallback">The filter callback.</param>
        /// <param name="index">is the index to add to</param>
        /// <param name="filterForValue">is the filter parameter value to add</param>
        /// <param name="treePathInfo">is the specification to fill on where is was added</param>
        /// <param name="lockFactory">The lock factory.</param>
        private static void AddToIndex(
            ArrayDeque <FilterValueSetParam> remainingParameters,
            FilterHandle filterCallback,
            FilterParamIndexBase index,
            Object filterForValue,
            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair> treePathInfo,
            FilterServiceGranularLockFactory lockFactory)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".addToIndex ({0}) Adding to index {1}  expressionValue={2}",
                          Thread.CurrentThread.ManagedThreadId, index, filterForValue);
            }

            EventEvaluator eventEvaluator;

            using (index.ReadWriteLock.AcquireReadLock())
            {
                eventEvaluator = index[filterForValue];

                // The filter parameter value already existed in bean, add and release locks
                if (eventEvaluator != null)
                {
                    var added = AddToEvaluator(remainingParameters, filterCallback, eventEvaluator, treePathInfo, lockFactory);
                    if (added)
                    {
                        return;
                    }
                }
            }

            // new filter parameter value, need a write lock
            using (index.ReadWriteLock.AcquireWriteLock())
            {
                eventEvaluator = index[filterForValue];

                // It may exist now since another thread could have added the entry
                if (eventEvaluator != null)
                {
                    var added = AddToEvaluator(remainingParameters, filterCallback, eventEvaluator, treePathInfo, lockFactory);
                    if (added)
                    {
                        return;
                    }

                    // The found eventEvaluator must be converted to a new FilterHandleSetNode
                    var nextIndexX = (FilterParamIndexBase)eventEvaluator;
                    var newNode    = new FilterHandleSetNode(lockFactory.ObtainNew());
                    newNode.Add(nextIndexX);
                    index.Remove(filterForValue);
                    index[filterForValue] = newNode;
                    AddToNode(remainingParameters, filterCallback, newNode, treePathInfo, lockFactory);

                    return;
                }

                // The index does not currently have this filterCallback value,
                // if there are no remaining parameters, create a node
                if (remainingParameters.IsEmpty())
                {
                    var node = new FilterHandleSetNode(lockFactory.ObtainNew());
                    AddToNode(remainingParameters, filterCallback, node, treePathInfo, lockFactory);
                    index[filterForValue] = node;
                    return;
                }

                // If there are remaining parameters, create a new index for the next parameter
                FilterValueSetParam parameterPickedForIndex = remainingParameters.RemoveFirst();

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

                index[filterForValue] = nextIndex;
                treePathInfo.Add(new EventTypeIndexBuilderIndexLookupablePair(nextIndex, parameterPickedForIndex.FilterForValue));
                AddToIndex(remainingParameters, filterCallback, nextIndex, parameterPickedForIndex.FilterForValue, treePathInfo, lockFactory);
            }
        }
예제 #5
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);
            }
        }