Ejemplo n.º 1
0
 /// <summary>Constructor. </summary>
 protected FilterServiceBase(FilterServiceGranularLockFactory lockFactory, bool allowIsolation)
 {
     _lockFactory            = lockFactory;
     _eventTypeIndex         = new EventTypeIndex(lockFactory);
     _indexBuilder           = new EventTypeIndexBuilder(_eventTypeIndex, allowIsolation);
     _filterServiceListeners = new CopyOnWriteArraySet <FilterServiceListener>();
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Add a filter callback according to the filter specification to the top node returning
        ///     information to be used to remove the filter callback.
        /// </summary>
        /// <param name="valueSet">is the filter definition</param>
        /// <param name="filterCallback">is the callback to be added</param>
        /// <param name="topNode">node to be added to any subnode beneath it</param>
        /// <param name="lockFactory">lock factory</param>
        public static void Add(
            FilterValueSetParam[][] valueSet,
            FilterHandle filterCallback,
            FilterHandleSetNode topNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            if (ExecutionPathDebugLog.IsDebugEnabled && log.IsDebugEnabled) {
                log.Debug(
                    ".add (" + Thread.CurrentThread.ManagedThreadId + ") Adding filter callback, " +
                    "  topNode=" + topNode +
                    "  filterCallback=" + filterCallback);
            }

            if (valueSet.Length == 0) {
                AddToNode(new ArrayDeque<FilterValueSetParam>(1), filterCallback, topNode, lockFactory);
            }
            else {
                var remainingParameters = new ArrayDeque<FilterValueSetParam>();
                for (var i = 0; i < valueSet.Length; i++) {
                    remainingParameters.Clear();
                    remainingParameters.AddAll(valueSet[i]);
                    AddToNode(remainingParameters, filterCallback, topNode, lockFactory);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add filter callback to an event evaluator, which could be either an index node or a set node.
        /// </summary>
        /// <param name="remainingParameters">The remaining parameters.</param>
        /// <param name="filterCallback">The filter callback.</param>
        /// <param name="eventEvaluator">to add the filterCallback to.</param>
        /// <param name="treePathInfo">is for holding the information on where the add occured</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <returns>
        /// bool indicating if the eventEvaluator was successfully added
        /// </returns>
        private static bool AddToEvaluator(
            ArrayDeque <FilterValueSetParam> remainingParameters,
            FilterHandle filterCallback,
            EventEvaluator eventEvaluator,
            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair> treePathInfo,
            FilterServiceGranularLockFactory lockFactory)
        {
            if (eventEvaluator is FilterHandleSetNode)
            {
                var node = (FilterHandleSetNode)eventEvaluator;
#if DEBUG && DIAGNOSTICS
                System.Diagnostics.Debug.WriteLine("{0}: AddToEvaluator: {1}", Thread.CurrentThread.ManagedThreadId, node);
#endif
                AddToNode(remainingParameters, filterCallback, node, treePathInfo, lockFactory);
                return(true);
            }

            // Check if the next index matches any of the remaining filterCallback parameters
            var nextIndex = (FilterParamIndexBase)eventEvaluator;

            var parameter = IndexHelper.FindParameter(remainingParameters, nextIndex);
            if (parameter != null)
            {
                remainingParameters.Remove(parameter);
                treePathInfo.Add(new EventTypeIndexBuilderIndexLookupablePair(nextIndex, parameter.FilterForValue));
#if DEBUG && DIAGNOSTICS
                System.Diagnostics.Debug.WriteLine("{0}: AddToEvaluator -> AddToIndex: {1}", Thread.CurrentThread.ManagedThreadId, nextIndex);
#endif
                AddToIndex(remainingParameters, filterCallback, nextIndex, parameter.FilterForValue, treePathInfo, lockFactory);
                return(true);
            }

            // This eventEvaluator does not work with any of the remaining filter parameters
            return(false);
        }
Ejemplo n.º 4
0
        public void SetUp()
        {
            lockFactory = new FilterServiceGranularLockFactoryReentrant(
                container.RWLockManager());

            var testBean = new SupportBean();

            testBean.IntPrimitive    = 50;
            testBean.DoublePrimitive = 0.5;
            testBean.TheString       = "jack";
            testBean.LongPrimitive   = 10;
            testBean.ShortPrimitive  = (short)20;

            eventBean = SupportEventBeanFactory
                        .GetInstance(container)
                        .CreateObject(testBean);
            eventType = eventBean.EventType;

            matches = new List <FilterHandle>();

            // Allocate a couple of callbacks
            testFilterCallback = new SupportFilterHandle[20];
            for (var i = 0; i < testFilterCallback.Length; i++)
            {
                testFilterCallback[i] = new SupportFilterHandle();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add a filter callback according to the filter specification to the top node returning information to be used to remove the filter callback.
        /// </summary>
        /// <param name="filterValueSet">is the filter definition</param>
        /// <param name="filterCallback">is the callback to be added</param>
        /// <param name="topNode">node to be added to any subnode beneath it</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <returns>
        /// an encapsulation of information need to allow for safe removal of the filter tree.
        /// </returns>
        public static ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>[] Add(
            FilterValueSet filterValueSet,
            FilterHandle filterCallback,
            FilterHandleSetNode topNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".add (" + Thread.CurrentThread.ManagedThreadId + ") Adding filter callback, " +
                          "  topNode=" + topNode +
                          "  filterCallback=" + filterCallback);
            }

            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>[] treePathInfo;
            if (filterValueSet.Parameters.Length == 0)
            {
                treePathInfo    = AllocateTreePath(1);
                treePathInfo[0] = new ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>(1);
                AddToNode(new ArrayDeque <FilterValueSetParam>(1), filterCallback, topNode, treePathInfo[0], lockFactory);
            }
            else
            {
                treePathInfo = AllocateTreePath(filterValueSet.Parameters.Length);
                var remainingParameters = new ArrayDeque <FilterValueSetParam>(4);
                for (int i = 0; i < filterValueSet.Parameters.Length; i++)
                {
                    treePathInfo[i] = new ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>(filterValueSet.Parameters[i].Length);
                    remainingParameters.Clear();
                    remainingParameters.AddAll(filterValueSet.Parameters[i]);
                    AddToNode(remainingParameters, filterCallback, topNode, treePathInfo[i], lockFactory);
                }
            }

            return(treePathInfo);
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            _container   = SupportContainer.Reset();
            _lockFactory = new FilterServiceGranularLockFactoryReentrant(
                _container.Resolve <IReaderWriterLockManager>());

            var testBean = new SupportBean();

            testBean.IntPrimitive    = 50;
            testBean.DoublePrimitive = 0.5;
            testBean.TheString       = "jack";
            testBean.LongPrimitive   = 10;
            testBean.ShortPrimitive  = (short)20;

            _eventBean = SupportEventBeanFactory.CreateObject(testBean);
            _eventType = _eventBean.EventType;

            _matches = new List <FilterHandle>();

            // Allocate a couple of callbacks
            _testFilterCallback = new SupportFilterHandle[20];
            for (var i = 0; i < _testFilterCallback.Length; i++)
            {
                _testFilterCallback[i] = new SupportFilterHandle();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Add the filters, from previously-taken filters.
 /// </summary>
 /// <param name="filterSet">to add</param>
 /// <param name="lockFactory">The lock factory.</param>
 public void Apply(FilterSet filterSet, FilterServiceGranularLockFactory lockFactory)
 {
     foreach (var entry in filterSet.Filters)
     {
         Add(entry.FilterValueSet, entry.Handle, lockFactory);
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Add filter callback to an event evaluator, which could be either an index node or a set node.
        /// </summary>
        /// <param name="remainingParameters">The remaining parameters.</param>
        /// <param name="filterCallback">The filter callback.</param>
        /// <param name="eventEvaluator">to add the filterCallback to.</param>
        /// <param name="treePathInfo">is for holding the information on where the add occured</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <returns>
        /// bool indicating if the eventEvaluator was successfully added
        /// </returns>
        private static bool AddToEvaluator(
            ArrayDeque <FilterValueSetParam> remainingParameters,
            FilterHandle filterCallback,
            EventEvaluator eventEvaluator,
            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair> treePathInfo,
            FilterServiceGranularLockFactory lockFactory)
        {
            if (eventEvaluator is FilterHandleSetNode)
            {
                var node = (FilterHandleSetNode)eventEvaluator;
                AddToNode(remainingParameters, filterCallback, node, treePathInfo, lockFactory);
                return(true);
            }

            // Check if the next index matches any of the remaining filterCallback parameters
            var nextIndex = (FilterParamIndexBase)eventEvaluator;

            var parameter = IndexHelper.FindParameter(remainingParameters, nextIndex);

            if (parameter != null)
            {
                remainingParameters.Remove(parameter);
                treePathInfo.Add(new EventTypeIndexBuilderIndexLookupablePair(nextIndex, parameter.FilterForValue));
                AddToIndex(remainingParameters, filterCallback, nextIndex, parameter.FilterForValue, treePathInfo, lockFactory);
                return(true);
            }

            // This eventEvaluator does not work with any of the remaining filter parameters
            return(false);
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            lockFactory = new FilterServiceGranularLockFactoryReentrant(
                container.RWLockManager());

            eventType = SupportEventTypeFactory
                        .GetInstance(container)
                        .CreateBeanType(typeof(SupportBean));
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            _lockFactory     = new FilterServiceGranularLockFactoryReentrant(_container.RWLockManager());
            _eventType       = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            _topNode         = new FilterHandleSetNode(_container.RWLockManager().CreateDefaultLock());
            _filterCallbacks = new List <FilterHandle>();
            _pathsAddedTo    = new List <ArrayDeque <EventTypeIndexBuilderIndexLookupablePair> >();

            _testFilterSpecs = new List <FilterSpecCompiled>();
            _matchedEvents   = new List <EventBean>();
            _unmatchedEvents = new List <EventBean>();

            // Any int and double value specified here must match only the current filter spec not any other filter spec
            _testFilterSpecs.Add(MakeSpec(new Object[] { "IntPrimitive", FilterOperator.GREATER_OR_EQUAL, 100000 }));
            _matchedEvents.Add(MakeEvent(9999999, -1));
            _unmatchedEvents.Add(MakeEvent(0, -1));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "IntPrimitive", FilterOperator.GREATER_OR_EQUAL, 10,
                                                         "DoublePrimitive", FilterOperator.EQUAL, 0.5 }));
            _matchedEvents.Add(MakeEvent(10, 0.5));
            _unmatchedEvents.Add(MakeEvent(0, 0.5));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "DoublePrimitive", FilterOperator.EQUAL, 0.8 }));
            _matchedEvents.Add(MakeEvent(-1, 0.8));
            _unmatchedEvents.Add(MakeEvent(-1, 0.1));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "DoublePrimitive", FilterOperator.EQUAL, 99.99,
                                                         "IntPrimitive", FilterOperator.LESS, 1 }));
            _matchedEvents.Add(MakeEvent(0, 99.99));
            _unmatchedEvents.Add(MakeEvent(2, 0.5));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "DoublePrimitive", FilterOperator.GREATER, .99,
                                                         "IntPrimitive", FilterOperator.EQUAL, 5001 }));
            _matchedEvents.Add(MakeEvent(5001, 1.1));
            _unmatchedEvents.Add(MakeEvent(5002, 0.98));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "IntPrimitive", FilterOperator.LESS, -99000 }));
            _matchedEvents.Add(MakeEvent(-99001, -1));
            _unmatchedEvents.Add(MakeEvent(-98999, -1));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "IntPrimitive", FilterOperator.GREATER_OR_EQUAL, 11,
                                                         "DoublePrimitive", FilterOperator.GREATER, 888.0 }));
            _matchedEvents.Add(MakeEvent(11, 888.001));
            _unmatchedEvents.Add(MakeEvent(10, 888));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "IntPrimitive", FilterOperator.EQUAL, 973,
                                                         "DoublePrimitive", FilterOperator.EQUAL, 709.0 }));
            _matchedEvents.Add(MakeEvent(973, 709));
            _unmatchedEvents.Add(MakeEvent(0, 0.5));

            _testFilterSpecs.Add(MakeSpec(new Object[] { "IntPrimitive", FilterOperator.EQUAL, 973,
                                                         "DoublePrimitive", FilterOperator.EQUAL, 655.0 }));
            _matchedEvents.Add(MakeEvent(973, 655));
            _unmatchedEvents.Add(MakeEvent(33838, 655.5));
        }
Ejemplo n.º 11
0
        /// <summary>Add to the current node building up the tree path information.</summary>
        /// <param name="remainingParameters">any remaining parameters</param>
        /// <param name="filterCallback">the filter callback</param>
        /// <param name="currentNode">is the node to add to</param>
        /// <param name="lockFactory">the lock factory</param>
        private static void AddToNode(
            ArrayDeque<FilterValueSetParam> remainingParameters,
            FilterHandle filterCallback,
            FilterHandleSetNode currentNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            // If no parameters are specified, add to current node, and done
            if (remainingParameters.IsEmpty()) {
                using (currentNode.NodeRWLock.WriteLock.Acquire())
                {
                    currentNode.Add(filterCallback);
                }

                return;
            }

            // Need to find an existing index that matches one of the filter parameters
            Pair<FilterValueSetParam, FilterParamIndexBase> pair;
            using (currentNode.NodeRWLock.ReadLock.Acquire())
            {
                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;
                    AddToIndex(remainingParameters, filterCallback, index, filterForValue, lockFactory);
                    return;
                }
            }

            // An index for any of the filter parameters was not found, create one
            using (currentNode.NodeRWLock.WriteLock.Acquire())
            {
                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 indexInner = pair.Second;
                    AddToIndex(remainingParameters, filterCallback, indexInner, filterForValue, lockFactory);
                    return;
                }

                // No index found that matches any parameters, create a new one
                // Pick the next parameter for an index
                var parameterPickedForIndex = remainingParameters.RemoveFirst();
                var index = IndexFactory.CreateIndex(parameterPickedForIndex.Lookupable, lockFactory, parameterPickedForIndex.FilterOperator);

                currentNode.Add(index);
                AddToIndex(remainingParameters, filterCallback, index, parameterPickedForIndex.FilterForValue, lockFactory);
            }
        }
 public void SetUp()
 {
     _container     = SupportContainer.Reset();
     _lockFactory   = new FilterServiceGranularLockFactoryReentrant(_container.RWLockManager());
     _testEvaluator = new SupportEventEvaluator();
     _testBean      = new SupportBean();
     _testEventBean = SupportEventBeanFactory.CreateObject(_testBean);
     _testEventType = _testEventBean.EventType;
     _matchesList   = new List <FilterHandle>();
 }
Ejemplo n.º 13
0
 protected FilterServiceBase(
     FilterServiceGranularLockFactory lockFactory,
     int stageId)
 {
     this.lockFactory = lockFactory;
     this.stageId = stageId;
     eventTypeIndex = new EventTypeIndex(lockFactory);
     indexBuilder = new EventTypeIndexBuilder(eventTypeIndex);
     filterServiceListeners = new CopyOnWriteArraySet<FilterServiceListener>();
 }
Ejemplo n.º 14
0
 public IndexTreeBuilderRunnable(EventType eventType, FilterHandleSetNode topNode, IList <FilterSpecCompiled> testFilterSpecs, IList <EventBean> matchedEvents, IList <EventBean> unmatchedEvents)
 {
     _lockFactory = new FilterServiceGranularLockFactoryReentrant(
         SupportContainer.Instance.RWLockManager());
     _eventType       = eventType;
     _topNode         = topNode;
     _testFilterSpecs = testFilterSpecs;
     _matchedEvents   = matchedEvents;
     _unmatchedEvents = unmatchedEvents;
 }
Ejemplo n.º 15
0
        public void SetUp()
        {
            lockFactory = new FilterServiceGranularLockFactoryReentrant(container.RWLockManager());

            testEvaluator = new SupportEventEvaluator();
            testBean      = new SupportBean();
            testEventBean = SupportEventBeanFactory
                            .GetInstance(container)
                            .CreateObject(testBean);
            testEventType = testEventBean.EventType;
            matchesList   = new List <FilterHandle>();
        }
 public SupportIndexTreeBuilderRunnable(
     EventType eventType,
     FilterHandleSetNode topNode,
     IList <FilterSpecActivatable> testFilterSpecs,
     IList <EventBean> matchedEvents,
     IList <EventBean> unmatchedEvents,
     IReaderWriterLockManager rwLockManager)
 {
     this.eventType       = eventType;
     this.topNode         = topNode;
     this.testFilterSpecs = testFilterSpecs;
     this.matchedEvents   = matchedEvents;
     this.unmatchedEvents = unmatchedEvents;
     this.lockFactory     = new FilterServiceGranularLockFactoryReentrant(rwLockManager);
 }
Ejemplo n.º 17
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            _lockFactory = new FilterServiceGranularLockFactoryReentrant(_container.RWLockManager());
            _eventType   = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            _parameters  = new LinkedList <FilterValueSetParam>();

            // Create parameter test list
            _parameterOne = new FilterValueSetParamImpl(MakeLookupable("IntPrimitive"), FilterOperator.GREATER, 10);
            _parameters.AddLast(_parameterOne);
            _parameterTwo = new FilterValueSetParamImpl(MakeLookupable("DoubleBoxed"), FilterOperator.GREATER, 20d);
            _parameters.AddLast(_parameterTwo);
            _parameterThree = new FilterValueSetParamImpl(MakeLookupable("TheString"), FilterOperator.EQUAL, "sometext");
            _parameters.AddLast(_parameterThree);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Add a filter to the event type index structure, and to the filter subtree.
        ///     Throws an IllegalStateException exception if the callback is already registered.
        /// </summary>
        /// <param name="valueSet">is the filter information</param>
        /// <param name="filterCallback">is the callback</param>
        /// <param name="lockFactory">lock factory</param>
        /// <param name="eventType">event type</param>
        public void Add(
            EventType eventType,
            FilterValueSetParam[][] valueSet,
            FilterHandle filterCallback,
            FilterServiceGranularLockFactory lockFactory)
        {
            // Check if a filter tree exists for this event type
            var rootNode = eventTypeIndex.Get(eventType);

            // Make sure we have a root node
            if (rootNode == null) {
                using (callbacksLock.Acquire()) {
                    rootNode = eventTypeIndex.Get(eventType);
                    if (rootNode == null) {
                        rootNode = new FilterHandleSetNode(lockFactory.ObtainNew());
                        eventTypeIndex.Add(eventType, rootNode);
                    }
                }
            }

            // Now add to tree
            IndexTreeBuilderAdd.Add(valueSet, filterCallback, rootNode, lockFactory);
        }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Factory for indexes that store filter parameter constants for a given event property and filter operator.
        /// <para />
        /// Does not perform any check of validity of property name.
        /// </summary>
        /// <param name="lookupable">The lookupable.</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <param name="filterOperator">is the type of index to use</param>
        /// <returns>
        /// the proper index based on the filter operator type
        /// </returns>
        /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator  + filterOperator</exception>
        public static FilterParamIndexBase CreateIndex(FilterSpecLookupable lookupable, FilterServiceGranularLockFactory lockFactory, FilterOperator filterOperator)
        {
            FilterParamIndexBase index;
            Type returnValueType = lookupable.ReturnType;

            // Handle all EQUAL comparisons
            if (filterOperator == FilterOperator.EQUAL)
            {
                index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            // Handle all NOT-EQUAL comparisons
            if (filterOperator == FilterOperator.NOT_EQUAL)
            {
                index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            if (filterOperator == FilterOperator.IS)
            {
                index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            if (filterOperator == FilterOperator.IS_NOT)
            {
                index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            // Handle all GREATER, LESS etc. comparisons
            if ((filterOperator == FilterOperator.GREATER) ||
                (filterOperator == FilterOperator.GREATER_OR_EQUAL) ||
                (filterOperator == FilterOperator.LESS) ||
                (filterOperator == FilterOperator.LESS_OR_EQUAL))
            {
                if (returnValueType != typeof(String))
                {
                    index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else
                {
                    index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                return(index);
            }

            // Handle all normal and inverted RANGE comparisons
            if (filterOperator.IsRangeOperator())
            {
                if (returnValueType != typeof(String))
                {
                    index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else
                {
                    index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                return(index);
            }
            if (filterOperator.IsInvertedRangeOperator())
            {
                if (returnValueType != typeof(String))
                {
                    return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator));
                }
                else
                {
                    return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator));
                }
            }

            // Handle all IN and NOT IN comparisons
            if (filterOperator == FilterOperator.IN_LIST_OF_VALUES)
            {
                return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew()));
            }
            if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES)
            {
                return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew()));
            }

            // Handle all bool expression
            if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION)
            {
                return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew()));
            }
            throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Factory for indexes that store filter parameter constants for a given event property and filter
        ///     operator.
        ///     <para />
        ///     Does not perform any check of validity of property name.
        /// </summary>
        /// <param name="filterOperator">is the type of index to use</param>
        /// <param name="lockFactory">lock factory</param>
        /// <param name="lookupable">the lookup item</param>
        /// <returns>the proper index based on the filter operator type</returns>
        public static FilterParamIndexBase CreateIndex(
            ExprFilterSpecLookupable lookupable,
            FilterServiceGranularLockFactory lockFactory,
            FilterOperator filterOperator)
        {
            FilterParamIndexBase index;
            var returnValueType = lookupable.ReturnType;

            // Handle all EQUAL comparisons
            if (filterOperator == FilterOperator.EQUAL) {
                index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew());
                return index;
            }

            // Handle all NOT-EQUAL comparisons
            if (filterOperator == FilterOperator.NOT_EQUAL) {
                index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew());
                return index;
            }

            if (filterOperator == FilterOperator.IS) {
                index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew());
                return index;
            }

            if (filterOperator == FilterOperator.IS_NOT) {
                index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew());
                return index;
            }

            // Handle all GREATER, LESS etc. comparisons
            if (filterOperator == FilterOperator.GREATER ||
                filterOperator == FilterOperator.GREATER_OR_EQUAL ||
                filterOperator == FilterOperator.LESS ||
                filterOperator == FilterOperator.LESS_OR_EQUAL) {
                if (returnValueType != typeof(string)) {
                    index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else {
                    index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator);
                }

                return index;
            }

            // Handle all normal and inverted RANGE comparisons
            if (filterOperator.IsRangeOperator()) {
                if (returnValueType != typeof(string)) {
                    index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else {
                    index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }

                return index;
            }

            if (filterOperator.IsInvertedRangeOperator()) {
                if (returnValueType != typeof(string)) {
                    return new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator);
                }

                return new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator);
            }

            // Handle all IN and NOT IN comparisons
            if (filterOperator == FilterOperator.IN_LIST_OF_VALUES) {
                return new FilterParamIndexIn(lookupable, lockFactory.ObtainNew());
            }

            if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES) {
                return new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew());
            }

            
            // Handle re-usable boolean expression
            if (filterOperator == FilterOperator.REBOOL) {
                if (lookupable.ReturnType == null) {
                    return new FilterParamIndexReboolNoValue(lookupable, lockFactory.ObtainNew());
                }
                return new FilterParamIndexReboolWithValue(lookupable, lockFactory.ObtainNew());
            }
            
            // Handle all boolean expression
            if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION) {
                return new FilterParamIndexBooleanExpr(lockFactory.ObtainNew());
            }

            // Handle advanced-index
            if (filterOperator == FilterOperator.ADVANCED_INDEX) {
                var advLookable = (FilterSpecLookupableAdvancedIndex) lookupable;
                if (advLookable.IndexType.Equals(SettingsApplicationDotMethodPointInsideRectangle.INDEXTYPE_NAME)) {
                    return new FilterParamIndexQuadTreePointRegion(lockFactory.ObtainNew(), lookupable);
                }

                if (advLookable.IndexType.Equals(SettingsApplicationDotMethodRectangeIntersectsRectangle.INDEXTYPE_NAME)) {
                    return new FilterParamIndexQuadTreeMXCIF(lockFactory.ObtainNew(), lookupable);
                }

                throw new IllegalStateException("Unrecognized index type " + advLookable.IndexType);
            }

            throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator);
        }
Ejemplo n.º 22
0
 public EventTypeIndex(FilterServiceGranularLockFactory lockFactory)
 {
     eventTypes = new Dictionary<EventType, FilterHandleSetNode>();
     eventTypesRWLock = lockFactory.ObtainNew();
 }
Ejemplo n.º 23
0
 public void SetUp()
 {
     _container   = SupportContainer.Reset();
     _eventType   = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
     _lockFactory = new FilterServiceGranularLockFactoryReentrant(_container.RWLockManager());
 }
Ejemplo n.º 24
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);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Add a filter to the event type index structure, and to the filter subtree.
        /// Throws an IllegalStateException exception if the callback is already registered.
        /// </summary>
        /// <param name="filterValueSet">is the filter information</param>
        /// <param name="filterCallback">is the callback</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <returns></returns>
        /// <exception cref="IllegalStateException">Callback for filter specification already exists in collection</exception>
        public FilterServiceEntry Add(FilterValueSet filterValueSet, FilterHandle filterCallback, FilterServiceGranularLockFactory lockFactory)
        {
            using (Instrument.With(
                       i => i.QFilterAdd(filterValueSet, filterCallback),
                       i => i.AFilterAdd()))
            {
                var eventType = filterValueSet.EventType;

                // Check if a filter tree exists for this event type
                var rootNode = _eventTypeIndex.Get(eventType);

                // Make sure we have a root node
                if (rootNode == null)
                {
                    using (_callbacksLock.Acquire())
                    {
                        rootNode = _eventTypeIndex.Get(eventType);
                        if (rootNode == null)
                        {
                            rootNode = new FilterHandleSetNode(lockFactory.ObtainNew());
                            _eventTypeIndex.Add(eventType, rootNode);
                        }
                    }
                }

                // GetInstance add to tree
                var path      = IndexTreeBuilder.Add(filterValueSet, filterCallback, rootNode, lockFactory);
                var pathArray = path.Select(p => p.ToArray()).ToArray();
                var pair      = new EventTypeIndexBuilderValueIndexesPair(filterValueSet, pathArray);

                // for non-isolatable callbacks the consumer keeps track of tree location
                if (_isolatableCallbacks == null)
                {
                    return(pair);
                }

                // for isolatable callbacks this class is keeping track of tree location
                using (_callbacksLock.Acquire()) {
                    _isolatableCallbacks.Put(filterCallback, pair);
                }

                return(null);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Add to an index the value to filter for.
        /// </summary>
        /// <param name="index">is the index to add to</param>
        /// <param name="filterForValue">is the filter parameter value to add</param>
        /// <param name="remainingParameters">any remaining parameters</param>
        /// <param name="filterCallback">the filter callback</param>
        /// <param name="lockFactory">the lock factory</param>
        private static void AddToIndex(
            ArrayDeque<FilterValueSetParam> remainingParameters,
            FilterHandle filterCallback,
            FilterParamIndexBase index,
            object filterForValue,
            FilterServiceGranularLockFactory lockFactory)
        {
            EventEvaluator eventEvaluator;

            using (index.ReadWriteLock.ReadLock.Acquire())
            { 
                eventEvaluator = index.Get(filterForValue);

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

            // new filter parameter value, need a write lock
            using (index.ReadWriteLock.WriteLock.Acquire())
            {
                eventEvaluator = index.Get(filterForValue);

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

                    // The found eventEvaluator must be converted to a new FilterHandleSetNode
                    var nextIndexInner = (FilterParamIndexBase) eventEvaluator;
                    var newNode = new FilterHandleSetNode(lockFactory.ObtainNew());
                    newNode.Add(nextIndexInner);
                    index.Remove(filterForValue);
                    index.Put(filterForValue, newNode);
                    AddToNode(remainingParameters, filterCallback, newNode, 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, lockFactory);
                    index.Put(filterForValue, node);
                    return;
                }

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

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

                index.Put(filterForValue, nextIndex);
                AddToIndex(remainingParameters, filterCallback, nextIndex, parameterPickedForIndex.FilterForValue, lockFactory);
            }
        }