Ejemplo n.º 1
0
        /// <summary>
        /// Called by the consumer view to indicate it was stopped or destroyed, such that the
        /// consumer can be deregistered and further dispatches disregard this consumer.
        /// </summary>
        /// <param name="namedWindowConsumerView">is the consumer representative view</param>
        public void RemoveConsumer(NamedWindowConsumerView namedWindowConsumerView)
        {
            EPStatementAgentInstanceHandle handleRemoved = null;

            // Find the consumer view
            foreach (var entry in _consumersInContext)
            {
                var foundAndRemoved = entry.Value.Remove(namedWindowConsumerView);
                // Remove the consumer view
                if ((foundAndRemoved) && (entry.Value.Count == 0))
                {
                    // Remove the handle if this list is now empty
                    handleRemoved = entry.Key;
                    break;
                }
            }
            if (handleRemoved != null)
            {
                var newConsumers = NamedWindowUtil.CreateConsumerMap(_tailView.IsPrioritized);
                newConsumers.PutAll(_consumersInContext);
                newConsumers.Remove(handleRemoved);
                _consumersInContext = newConsumers;
            }

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

            if (virtualDWView != null && handleRemoved != null)
            {
                virtualDWView.VirtualDataWindow.HandleEvent(new VirtualDataWindowEventConsumerRemove(_tailView.EventType.Name, namedWindowConsumerView, handleRemoved.StatementHandle.StatementName, handleRemoved.AgentInstanceId));
            }
        }
Ejemplo n.º 2
0
 public NamedWindowTailViewInstance(NamedWindowRootViewInstance rootViewInstance, NamedWindowTailView tailView, AgentInstanceContext agentInstanceContext)
 {
     _rootViewInstance     = rootViewInstance;
     _tailView             = tailView;
     _agentInstanceContext = agentInstanceContext;
     _consumersInContext   = NamedWindowUtil.CreateConsumerMap(tailView.IsPrioritized);
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public NamedWindowTailViewInstance(NamedWindowRootViewInstance rootViewInstance, NamedWindowTailView tailView, NamedWindowProcessor namedWindowProcessor, AgentInstanceContext agentInstanceContext)
 {
     _rootViewInstance     = rootViewInstance;
     _tailView             = tailView;
     _namedWindowProcessor = namedWindowProcessor;
     _agentInstanceContext = agentInstanceContext;
     _consumersInContext   = NamedWindowUtil.CreateConsumerMap(tailView.IsPrioritized);
     _latchFactory         = tailView.MakeLatchFactory();
 }
Ejemplo n.º 5
0
        private volatile IDictionary <EPStatementAgentInstanceHandle, IList <NamedWindowConsumerView> > _consumersNonContext;  // handles as copy-on-write

        public NamedWindowTailView(EventType eventType, NamedWindowService namedWindowService, StatementResultService statementResultService, ValueAddEventProcessor revisionProcessor, bool prioritized, bool parentBatchWindow)
        {
            _eventType              = eventType;
            _namedWindowService     = namedWindowService;
            _statementResultService = statementResultService;
            _revisionProcessor      = revisionProcessor;
            _isPrioritized          = prioritized;
            _isParentBatchWindow    = parentBatchWindow;
            _consumersNonContext    = NamedWindowUtil.CreateConsumerMap(_isPrioritized);
        }
Ejemplo n.º 6
0
 public NamedWindowTailViewInstance(NamedWindowRootViewInstance rootViewInstance, NamedWindowTailView tailView, NamedWindowProcessor namedWindowProcessor, AgentInstanceContext agentInstanceContext)
 {
     _rootViewInstance     = rootViewInstance;
     _tailView             = tailView;
     _namedWindowProcessor = namedWindowProcessor;
     _agentInstanceContext = agentInstanceContext;
     _consumersInContext   = NamedWindowUtil.CreateConsumerMap(tailView.IsPrioritized);
     _latchFactory         = new NamedWindowConsumerLatchFactory(
         namedWindowProcessor.NamedWindowType.Name,
         tailView.ThreadingConfig.IsNamedWindowConsumerDispatchPreserveOrder,
         tailView.ThreadingConfig.NamedWindowConsumerDispatchTimeout,
         tailView.ThreadingConfig.NamedWindowConsumerDispatchLocking,
         tailView.TimeSourceService);
 }
Ejemplo n.º 7
0
        private volatile IDictionary <EPStatementAgentInstanceHandle, IList <NamedWindowConsumerView> > _consumersNonContext;  // handles as copy-on-write

        public NamedWindowTailView(
            EventType eventType,
            NamedWindowMgmtService namedWindowMgmtService,
            NamedWindowDispatchService namedWindowDispatchService,
            StatementResultService statementResultService,
            ValueAddEventProcessor revisionProcessor,
            bool prioritized,
            bool parentBatchWindow,
            TimeSourceService timeSourceService,
            ConfigurationEngineDefaults.ThreadingConfig threadingConfig)
        {
            EventType = eventType;
            NamedWindowMgmtService     = namedWindowMgmtService;
            NamedWindowDispatchService = namedWindowDispatchService;
            StatementResultService     = statementResultService;
            RevisionProcessor          = revisionProcessor;
            IsPrioritized        = prioritized;
            IsParentBatchWindow  = parentBatchWindow;
            _consumersNonContext = NamedWindowUtil.CreateConsumerMap(IsPrioritized);
            ThreadingConfig      = threadingConfig;
            TimeSourceService    = timeSourceService;
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        /// <summary>Called by the consumer view to indicate it was stopped or destroyed, such that the consumer can be deregistered and further dispatches disregard this consumer. </summary>
        /// <param name="namedWindowConsumerView">is the consumer representative view</param>
        public void RemoveConsumer(NamedWindowConsumerView namedWindowConsumerView)
        {
            EPStatementAgentInstanceHandle handleRemoved = null;

            // Find the consumer view
            foreach (var entry in _consumersNonContext)
            {
                var foundAndRemoved = entry.Value.Remove(namedWindowConsumerView);
                // Remove the consumer view
                if ((foundAndRemoved) && (entry.Value.Count == 0))
                {
                    // Remove the handle if this list is now empty
                    handleRemoved = entry.Key;
                    break;
                }
            }
            if (handleRemoved != null)
            {
                var newConsumers = NamedWindowUtil.CreateConsumerMap(IsPrioritized);
                newConsumers.PutAll(_consumersNonContext);
                newConsumers.Remove(handleRemoved);
                _consumersNonContext = newConsumers;
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Dispose the view.
 /// </summary>
 public void Dispose()
 {
     _consumersInContext = NamedWindowUtil.CreateConsumerMap(_tailView.IsPrioritized);
 }