Esempio n. 1
0
        /// <summary>
        /// Adds a consuming (selecting) statement to the named window.
        /// </summary>
        /// <param name="consumerDesc">The consumer desc.</param>
        /// <param name="isSubselect">if set to <c>true</c> [is subselect].</param>
        /// <returns>
        /// consumer view
        /// </returns>
        public NamedWindowConsumerView AddConsumer(NamedWindowConsumerDesc consumerDesc, bool isSubselect)
        {
            NamedWindowConsumerCallback consumerCallback = new ProxyNamedWindowConsumerCallback()
            {
                ProcGetEnumerator = GetEnumerator,
                ProcStopped       = RemoveConsumer,
            };

            // Construct consumer view, allow a callback to this view to remove the consumer
            var audit        = AuditEnum.STREAM.GetAudit(consumerDesc.AgentInstanceContext.StatementContext.Annotations) != null;
            var consumerView = new NamedWindowConsumerView(
                ExprNodeUtility.GetEvaluators(consumerDesc.FilterList),
                consumerDesc.OptPropertyEvaluator,
                _tailView.EventType,
                consumerCallback,
                consumerDesc.AgentInstanceContext,
                audit);

            // indicate to virtual data window that a consumer was added
            var virtualDWView = _rootViewInstance.VirtualDataWindow;

            if (virtualDWView != null)
            {
                virtualDWView.VirtualDataWindow.HandleEvent(
                    new VirtualDataWindowEventConsumerAdd(
                        _tailView.EventType.Name,
                        consumerView,
                        consumerDesc.AgentInstanceContext.StatementName,
                        consumerDesc.AgentInstanceContext.AgentInstanceId,
                        ExprNodeUtility.ToArray(consumerDesc.FilterList),
                        _agentInstanceContext));
            }

            // Keep a list of consumer views per statement to accommodate joins and subqueries
            var viewsPerStatements = _consumersInContext.Get(consumerDesc.AgentInstanceContext.EpStatementAgentInstanceHandle);

            if (viewsPerStatements == null)
            {
                viewsPerStatements = new CopyOnWriteList <NamedWindowConsumerView>();

                // avoid concurrent modification as a thread may currently iterate over consumers as its dispatching
                // without the engine lock
                var newConsumers = NamedWindowUtil.CreateConsumerMap(_tailView.IsPrioritized);
                newConsumers.PutAll(_consumersInContext);
                newConsumers.Put(consumerDesc.AgentInstanceContext.EpStatementAgentInstanceHandle, viewsPerStatements);
                _consumersInContext = newConsumers;
            }
            if (isSubselect)
            {
                viewsPerStatements.Insert(0, consumerView);
            }
            else
            {
                viewsPerStatements.Add(consumerView);
            }

            return(consumerView);
        }
Esempio n. 2
0
        public NamedWindowConsumerView AddConsumer(NamedWindowConsumerDesc consumerDesc)
        {
            NamedWindowConsumerCallback consumerCallback = new ProxyNamedWindowConsumerCallback(
                () =>
            {
                throw new UnsupportedOperationException(
                    "GetEnumerator not supported on named windows that have a context attached and when that context is not the same as the consuming statement's context");
            },
                RemoveConsumer);

            // Construct consumer view, allow a callback to this view to remove the consumer
            var audit        = AuditEnum.STREAM.GetAudit(consumerDesc.AgentInstanceContext.StatementContext.Annotations) != null;
            var consumerView = new NamedWindowConsumerView(
                ExprNodeUtility.GetEvaluators(consumerDesc.FilterList),
                consumerDesc.OptPropertyEvaluator,
                _eventType,
                consumerCallback,
                consumerDesc.AgentInstanceContext,
                audit);

            // Keep a list of consumer views per statement to accomodate joins and subqueries
            IList <NamedWindowConsumerView> viewsPerStatements = _consumersNonContext.Get(consumerDesc.AgentInstanceContext.EpStatementAgentInstanceHandle);

            if (viewsPerStatements == null)
            {
                viewsPerStatements = new CopyOnWriteList <NamedWindowConsumerView>();

                // avoid concurrent modification as a thread may currently iterate over consumers as its dispatching
                // without the engine lock
                var newConsumers = NamedWindowUtil.CreateConsumerMap(_isPrioritized);
                newConsumers.PutAll(_consumersNonContext);
                newConsumers.Put(consumerDesc.AgentInstanceContext.EpStatementAgentInstanceHandle, viewsPerStatements);
                _consumersNonContext = newConsumers;
            }
            viewsPerStatements.Add(consumerView);

            return(consumerView);
        }