示例#1
0
        private void RunAssertionAddRemoveFilter(FilterService service)
        {
            var eventType    = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            var spec         = SupportFilterSpecBuilder.Build(eventType, new Object[] { "TheString", FilterOperator.EQUAL, "HELLO" });
            var filterValues = spec.GetValueSet(null, null, null);

            var callables = new Func <bool> [5];

            for (int ii = 0; ii < callables.Length; ii++)
            {
                callables[ii] =
                    () =>
                {
                    var handle = new SupportFilterHandle();
                    for (int jj = 0; jj < 10000; jj++)
                    {
                        var entry = service.Add(filterValues, handle);
                        service.Remove(handle, entry);
                    }
                    return(true);
                };
            }

            Object[] result = TryMT(callables);
            EPAssertionUtil.AssertAllBooleanTrue(result);
        }
示例#2
0
        protected void StartFiltering()
        {
            FilterService filterService = _evalFilterNode.Context.PatternContext.FilterService;

            Handle = new EPStatementHandleCallback(_evalFilterNode.Context.AgentInstanceContext.EpStatementAgentInstanceHandle, this);
            FilterValueSet filterValues = _evalFilterNode.FactoryNode.FilterSpec.GetValueSet(BeginState, _evalFilterNode.Context.AgentInstanceContext, _evalFilterNode.AddendumFilters);

            FilterServiceEntry = filterService.Add(filterValues, Handle);
            long filtersVersion = filterService.FiltersVersion;

            _evalFilterNode.Context.AgentInstanceContext.EpStatementAgentInstanceHandle.StatementFilterVersion.StmtFilterVersion = filtersVersion;
        }
示例#3
0
        /// <summary>
        /// See the method of the same name in <seealso cref="com.espertech.esper.view.stream.StreamFactoryService" />.
        /// Always attempts to reuse an existing event stream. May thus return a new event stream or an existing event
        /// stream depending on whether filter criteria match.
        /// </summary>
        /// <param name="statementId">the statement id</param>
        /// <param name="filterSpec">is the filter definition</param>
        /// <param name="filterService">filter service to activate filter if not already active</param>
        /// <param name="epStatementAgentInstanceHandle">is the statement resource lock</param>
        /// <param name="isJoin">is indicatng whether the stream will participate in a join statement, information necessary for stream reuse and multithreading concerns</param>
        /// <param name="agentInstanceContext"></param>
        /// <param name="hasOrderBy">if the consumer has order-by</param>
        /// <param name="filterWithSameTypeSubselect">if set to <c>true</c> [filter with same type subselect].</param>
        /// <param name="annotations">The annotations.</param>
        /// <param name="stateless">if set to <c>true</c> [stateless].</param>
        /// <param name="streamNum">The stream num.</param>
        /// <param name="isCanIterateUnbound">if set to <c>true</c> [is can iterate unbound].</param>
        /// <returns>
        /// newly createdStatement event stream, not reusing existing instances
        /// </returns>
        /// <exception cref="IllegalStateException">Filter spec object already found in collection</exception>
        public Pair <EventStream, IReaderWriterLock> CreateStream(
            int statementId,
            FilterSpecCompiled filterSpec,
            FilterService filterService,
            EPStatementAgentInstanceHandle epStatementAgentInstanceHandle,
            bool isJoin,
            AgentInstanceContext agentInstanceContext,
            bool hasOrderBy,
            bool filterWithSameTypeSubselect,
            Attribute[] annotations,
            bool stateless,
            int streamNum,
            bool isCanIterateUnbound)
        {
            EventStream eventStream;

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".createStream hashCode=" + filterSpec.GetHashCode() + " filter=" + filterSpec);
            }

            // Check if a stream for this filter already exists
            StreamEntry entry;
            var         forceNewStream = isJoin || (!_isReuseViews) || hasOrderBy || filterWithSameTypeSubselect || stateless;

            if (forceNewStream)
            {
                entry = _eventStreamsIdentity.Get(filterSpec);
            }
            else
            {
                entry = _eventStreamsRefCounted[filterSpec];
            }

            // If pair exists, either reference count or illegal state
            if (entry != null)
            {
                if (forceNewStream)
                {
                    throw new IllegalStateException("Filter spec object already found in collection");
                }
                else
                {
                    Log.Debug(".createStream filter already found");
                    _eventStreamsRefCounted.Reference(filterSpec);

                    // audit proxy
                    eventStream = EventStreamProxy.GetAuditProxy(
                        _engineURI, epStatementAgentInstanceHandle.StatementHandle.StatementName, annotations,
                        filterSpec, entry.EventStream);

                    // We return the lock of the statement first establishing the stream to use that as the new statement's lock
                    return(new Pair <EventStream, IReaderWriterLock>(
                               eventStream, entry.Callback.AgentInstanceHandle.StatementAgentInstanceLock));
                }
            }

            // New event stream
            var resultEventType = filterSpec.ResultEventType;
            var zeroDepthStream = isCanIterateUnbound
                ? (EventStream) new ZeroDepthStreamIterable(resultEventType)
                : (EventStream) new ZeroDepthStreamNoIterate(resultEventType);

            // audit proxy
            var inputStream = EventStreamProxy.GetAuditProxy(
                _engineURI, epStatementAgentInstanceHandle.StatementHandle.StatementName, annotations, filterSpec,
                zeroDepthStream);

            eventStream = inputStream;
            FilterHandleCallback filterCallback;

            if (filterSpec.OptionalPropertyEvaluator != null)
            {
                filterCallback = new ProxyFilterHandleCallback()
                {
                    ProcStatementId = () => statementId,
                    ProcMatchFound  = (theEvent, allStmtMatches) =>
                    {
                        var result = filterSpec.OptionalPropertyEvaluator.GetProperty(theEvent, agentInstanceContext);
                        if (result != null)
                        {
                            eventStream.Insert(result);
                        }
                    },
                    ProcIsSubselect = () => false
                };
            }
            else
            {
                filterCallback = new ProxyFilterHandleCallback()
                {
                    ProcStatementId = () => statementId,
                    ProcMatchFound  = (theEvent, allStmtMatches) =>
                    {
                        if (InstrumentationHelper.ENABLED)
                        {
                            InstrumentationHelper.Get().QFilterActivationStream(theEvent.EventType.Name, streamNum);
                        }
                        eventStream.Insert(theEvent);
                        if (InstrumentationHelper.ENABLED)
                        {
                            InstrumentationHelper.Get().AFilterActivationStream();
                        }
                    },
                    ProcIsSubselect = () => false
                };
            }

            var handle = new EPStatementHandleCallback(epStatementAgentInstanceHandle, filterCallback);

            // Store stream for reuse
            entry = new StreamEntry(eventStream, handle);
            if (forceNewStream)
            {
                _eventStreamsIdentity.Put(filterSpec, entry);
            }
            else
            {
                _eventStreamsRefCounted[filterSpec] = entry;
            }

            // Activate filter
            var filterValues       = filterSpec.GetValueSet(null, agentInstanceContext, null);
            var filterServiceEntry = filterService.Add(filterValues, handle);

            entry.FilterServiceEntry = filterServiceEntry;

            return(new Pair <EventStream, IReaderWriterLock>(inputStream, null));
        }