Example #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>
        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.IsEmpty()) {
                    // 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));
            }
        }
Example #2
0
            consumersNonContext; // handles as copy-on-write

        public NamedWindowTailViewImpl(
            EventType eventType,
            bool isParentBatchWindow,
            EPStatementInitServices services)
            : base(eventType, isParentBatchWindow, services)
        {
            this.consumersNonContext = NamedWindowUtil.CreateConsumerMap(isPrioritized);
        }
Example #3
0
 public NamedWindowTailViewInstance(
     NamedWindowRootViewInstance rootViewInstance,
     NamedWindowTailView tailView,
     NamedWindow namedWindow,
     AgentInstanceContext agentInstanceContext)
 {
     _rootViewInstance = rootViewInstance;
     _tailView = tailView;
     _namedWindow = namedWindow;
     _agentInstanceContext = agentInstanceContext;
     _consumersInContext = NamedWindowUtil.CreateConsumerMap(tailView.IsPrioritized);
     _latchFactory = tailView.MakeLatchFactory();
 }
Example #4
0
        public override NamedWindowConsumerView AddConsumerNoContext(NamedWindowConsumerDesc consumerDesc)
        {
            NamedWindowConsumerCallback consumerCallback = new ProxyNamedWindowConsumerCallback() {
                ProcGetEnumerator = () => throw new UnsupportedOperationException(
                    "Iterator not supported on named windows that have a context attached and when that context is not the same as the consuming statement's context"),
                ProcIsParentBatchWindow = () => isParentBatchWindow,
                ProcSnapshot = (
                    queryGraph,
                    annotations) => Collections.GetEmptyList<EventBean>(),
                ProcStopped = RemoveConsumerNoContext,
            };

            // Construct consumer view, allow a callback to this view to remove the consumer
            bool audit = AuditEnum.STREAM.GetAudit(consumerDesc.AgentInstanceContext.StatementContext.Annotations) !=
                         null;
            NamedWindowConsumerView consumerView = new NamedWindowConsumerView(
                consumerDesc.NamedWindowConsumerId,
                consumerDesc.FilterEvaluator,
                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 runtime lock
                IDictionary<EPStatementAgentInstanceHandle, IList<NamedWindowConsumerView>> newConsumers =
                    NamedWindowUtil.CreateConsumerMap(isPrioritized);
                newConsumers.PutAll(consumersNonContext);
                newConsumers.Put(consumerDesc.AgentInstanceContext.EpStatementAgentInstanceHandle, viewsPerStatements);
                consumersNonContext = newConsumers;
            }

            viewsPerStatements.Add(consumerView);

            return consumerView;
        }
Example #5
0
        public override void RemoveConsumerNoContext(NamedWindowConsumerView namedWindowConsumerView)
        {
            EPStatementAgentInstanceHandle handleRemoved = null;
            // Find the consumer view
            foreach (KeyValuePair<EPStatementAgentInstanceHandle, IList<NamedWindowConsumerView>> entry in
                consumersNonContext) {
                bool 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) {
                IDictionary<EPStatementAgentInstanceHandle, IList<NamedWindowConsumerView>> newConsumers =
                    NamedWindowUtil.CreateConsumerMap(isPrioritized);
                newConsumers.PutAll(consumersNonContext);
                newConsumers.Remove(handleRemoved);
                consumersNonContext = newConsumers;
            }
        }
Example #6
0
 public void Destroy()
 {
     _consumersInContext = NamedWindowUtil.CreateConsumerMap(TailView.IsPrioritized);
 }
Example #7
0
        public NamedWindowConsumerView AddConsumer(
            NamedWindowConsumerDesc consumerDesc,
            bool isSubselect)
        {
            NamedWindowConsumerCallback consumerCallback = new ProxyNamedWindowConsumerCallback {
                ProcGetEnumerator = () => {
                    var instance = _namedWindow.GetNamedWindowInstance(AgentInstanceContext);
                    if (instance == null) {
                        // this can happen on context-partition "output when terminated"
                        return GetEnumerator();
                    }

                    return instance.TailViewInstance.GetEnumerator();
                },
                ProcStopped = namedWindowConsumerView
                    => RemoveConsumer(namedWindowConsumerView),
                ProcIsParentBatchWindow = ()
                    => _rootViewInstance.IsParentBatchWindow,
                ProcSnapshot = (
                        queryGraph,
                        annotations)
                    => Snapshot(queryGraph, annotations)
            };

            // 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(
                consumerDesc.NamedWindowConsumerId,
                consumerDesc.FilterEvaluator,
                consumerDesc.OptPropertyEvaluator,
                TailView.EventType,
                consumerCallback,
                consumerDesc.AgentInstanceContext,
                audit);

            // indicate to virtual data window that a consumer was added
            var virtualDWView = _rootViewInstance.VirtualDataWindow;
            virtualDWView?.VirtualDataWindow.HandleEvent(
                new VirtualDataWindowEventConsumerAdd(
                    TailView.EventType.Name,
                    consumerView,
                    consumerDesc.AgentInstanceContext.StatementName,
                    consumerDesc.AgentInstanceContext.AgentInstanceId,
                    consumerDesc.FilterEvaluator,
                    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 runtime 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;
        }