예제 #1
0
        // Remove an filterCallback from the current node, return true if the node is the node is empty now
        private static bool RemoveFromNode(
            FilterHandle filterCallback,
            FilterHandleSetNode currentNode,
            EventTypeIndexBuilderIndexLookupablePair[] treePathInfo,
            int treePathPosition)
        {
            var nextPair = treePathPosition < treePathInfo.Length ? treePathInfo[treePathPosition++] : null;

            // No remaining filter parameters
            if (nextPair == null)
            {
                using (currentNode.NodeRWLock.AcquireWriteLock())
                {
                    var isRemoved = currentNode.Remove(filterCallback);
                    var isEmpty   = currentNode.IsEmpty();

                    if (!isRemoved)
                    {
                        Log.Warn(".removeFromNode (" + Thread.CurrentThread.ManagedThreadId + ") Could not find the filterCallback to be removed within the supplied node , node=" +
                                 currentNode + "  filterCallback=" + filterCallback);
                    }

                    return(isEmpty);
                }
            }

            // Remove from index
            var nextIndex        = nextPair.Index;
            var filteredForValue = nextPair.Lookupable;

            using (currentNode.NodeRWLock.AcquireWriteLock())
            {
                var isEmpty = RemoveFromIndex(filterCallback, nextIndex, treePathInfo, treePathPosition, filteredForValue);

                if (!isEmpty)
                {
                    return(false);
                }

                // Remove the index if the index is now empty
                if (nextIndex.Count == 0)
                {
                    var isRemoved = currentNode.Remove(nextIndex);

                    if (!isRemoved)
                    {
                        Log.Warn(".removeFromNode (" + Thread.CurrentThread.ManagedThreadId + ") Could not find the index in index list for removal, index=" +
                                 nextIndex + "  filterCallback=" + filterCallback);
                        return(false);
                    }
                }

                return(currentNode.IsEmpty());
            }
        }
예제 #2
0
        public void TestNodeGetSet()
        {
            FilterHandle exprOne = new SupportFilterHandle();

            // Check pre-conditions
            Assert.IsTrue(_testNode.NodeRWLock != null);
            Assert.IsFalse(_testNode.Contains(exprOne));
            Assert.AreEqual(0, _testNode.FilterCallbackCount);
            Assert.AreEqual(0, _testNode.Indizes.Count);
            Assert.IsTrue(_testNode.IsEmpty());

            _testNode.Add(exprOne);

            // Check after add
            Assert.IsTrue(_testNode.Contains(exprOne));
            Assert.AreEqual(1, _testNode.FilterCallbackCount);
            Assert.IsFalse(_testNode.IsEmpty());

            // Add an indexOne
            EventType            eventType  = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            FilterSpecLookupable lookupable = new FilterSpecLookupable("IntPrimitive", eventType.GetGetter("IntPrimitive"), eventType.GetPropertyType("IntPrimitive"), false);
            FilterParamIndexBase indexOne   = new SupportFilterParamIndex(lookupable);

            _testNode.Add(indexOne);

            // Check after add
            Assert.AreEqual(1, _testNode.Indizes.Count);
            Assert.AreEqual(indexOne, _testNode.Indizes.FirstOrDefault());

            // Check removes
            Assert.IsTrue(_testNode.Remove(exprOne));
            Assert.IsFalse(_testNode.IsEmpty());
            Assert.IsFalse(_testNode.Remove(exprOne));
            Assert.IsTrue(_testNode.Remove(indexOne));
            Assert.IsFalse(_testNode.Remove(indexOne));
            Assert.IsTrue(_testNode.IsEmpty());
        }