public void AddDispatch(
     NamedWindowConsumerLatchFactory latchFactory,
     NamedWindowDeltaData delta,
     IDictionary <EPStatementAgentInstanceHandle, IList <NamedWindowConsumerView> > consumers)
 {
     _threadLocal.GetOrCreate().Add(
         latchFactory.NewLatch(delta, consumers));
 }
 public void Add(int[] payload)
 {
     _received.GetOrCreate().AddLast(payload);
     if (!_isDispatchWaiting.GetOrCreate())
     {
         _dispatchService.AddExternal(this);
         _isDispatchWaiting.Value = true;
     }
 }
Exemple #3
0
 public ExprConcatNodeEvalThreadLocal(
     ExprConcatNode parent,
     ExprEvaluator[] evaluators)
 {
     localBuffer = new SystemThreadLocal<StringBuilder>(() => new StringBuilder());
     buffer = localBuffer.GetOrCreate();
     this.parent = parent;
     this.evaluators = evaluators;
     buffer = localBuffer.GetOrCreate();
 }
Exemple #4
0
 public void MatchFound(EventBean theEvent, ICollection <FilterHandleCallback> allStmtMatches)
 {
     if (collector != null)
     {
         var holder = _collectorDataTL.GetOrCreate();
         if (holder == null)
         {
             holder = new EPDataFlowEventBeanCollectorContext(graphContext, submitEventBean, theEvent);
             _collectorDataTL.Value = holder;
         }
         else
         {
             holder.Event = theEvent;
         }
         collector.Collect(holder);
     }
     else if (submitEventBean)
     {
         emittables.Push(theEvent);
     }
     else
     {
         emittables.Push(theEvent.Underlying);
     }
 }
        public object Evaluate(EvaluateParams evaluateParams)
        {
            var buffer = _localBuffer.GetOrCreate();

            buffer.Length = 0;
            return(ExprConcatNodeEvalWNew.Evaluate(evaluateParams, buffer, _evaluators, _parent));
        }
 public void Handle(ICollection <FilterHandleCallback> callbacks, EventBean theEvent)
 {
     if (callbacks.Count >= 8)
     {
         var dedup = Dedups.GetOrCreate();
         dedup.Clear();
         dedup.AddAll(callbacks);
         foreach (var callback in dedup)
         {
             callback.MatchFound(theEvent, callbacks);
         }
         dedup.Clear();
     }
     else
     {
         var count = 0;
         foreach (var callback in callbacks)
         {
             var haveInvoked = CheckDup(callback, callbacks, count);
             if (!haveInvoked)
             {
                 callback.MatchFound(theEvent, callbacks);
             }
             count++;
         }
     }
 }
Exemple #7
0
        public override bool Evaluate(EventBean theEvent)
        {
            _variableService?.SetLocalVersion();

            var eventsPerStream = _arrayPerThread.GetOrCreate();
            eventsPerStream[0] = theEvent;
            return EvaluatePerStream(eventsPerStream);
        }
Exemple #8
0
        public void Add(int[] payload)
        {
            _received.GetOrCreate().AddLast(payload);
            if (!_isDispatchWaiting.GetOrCreate())
            {
                DispatchFuture nextFuture;
                lock (this)
                {
                    nextFuture = new DispatchFuture(this, _currentFuture);
                    _currentFuture.Later = nextFuture;
                    _currentFuture = nextFuture;
                }

                _dispatchService.AddExternal(nextFuture);
                _isDispatchWaiting.Value = true;
            }
        }
 public override bool Evaluate(EventBean theEvent)
 {
     if (VariableService != null)
     {
         VariableService.SetLocalVersion();
     }
     EventBean[] eventsPerStream = _arrayPerThread.GetOrCreate();
     eventsPerStream[0] = theEvent;
     return(EvaluatePerStream(eventsPerStream));
 }
        /// <summary>
        /// Adds the acquired lock.  If the lock does not already belong to the context, then it will be locked and
        /// the disposable lock will be returned.
        /// </summary>
        /// <param name="lock">The lock.</param>
        /// <returns></returns>
        public IDisposable AddAcquiredLock(ILockable @lock)
        {
            var table = _threadLocal.GetOrCreate();

            if (table.ContainsKey(@lock))
            {
                return(null);
            }

            var latch = @lock.Acquire();

            return(table[@lock] = latch);
        }
Exemple #11
0
        //[MethodImplOptions.AggressiveInlining]
#endif

        // Called by OutputProcessView
        public void Indicate(UniformPair <EventBean[]> results)
        {
            if (results != null)
            {
                if ((MetricReportingPath.IsMetricsEnabledValue) && (_statementMetricHandle.IsEnabled))
                {
                    int numIStream = (results.First != null) ? results.First.Length : 0;
                    int numRStream = (results.Second != null) ? results.Second.Length : 0;
                    _metricReportingService.AccountOutput(_statementMetricHandle, numIStream, numRStream);
                }

                var lastResults = _lastResults.GetOrCreate();

                if ((results.First != null) && (results.First.Length != 0))
                {
                    lastResults.AddLast(results);
                }
                else if ((results.Second != null) && (results.Second.Length != 0))
                {
                    lastResults.AddLast(results);
                }
            }
        }
 public object Evaluate(
     EventBean[] eventsPerStream,
     bool isNewData,
     ExprEvaluatorContext context)
 {
     var buffer = _localBuffer.GetOrCreate();
     buffer.Length = 0;
     return ExprConcatNodeForgeEvalWNew.Evaluate(
         eventsPerStream,
         isNewData,
         context,
         buffer,
         _evaluators,
         _form);
 }
Exemple #13
0
        /// <summary>
        /// Evaluate the bool expression given the event as a stream zero event.
        /// </summary>
        /// <param name="theEvent">is the stream zero event (current event)</param>
        /// <param name="exprEvaluatorContext">The expression evaluator context.</param>
        /// <returns>bool result of the expression</returns>
        public bool Evaluate(EventBean theEvent, ExprEvaluatorContext exprEvaluatorContext)
        {
            if (_variableService != null)
            {
                _variableService.SetLocalVersion();
            }
            EventBean[] eventsPerStream = _arrayPerThread.GetOrCreate();
            eventsPerStream[0] = theEvent;

            try {
                var result = (bool?)_exprNodeEval.Evaluate(new EvaluateParams(eventsPerStream, true, exprEvaluatorContext));
                return(result ?? false);
            }
            catch (Exception ex) {
                Log.Error("Error evaluating expression '" + _exprNode.ToExpressionStringMinPrecedenceSafe() + "': " + ex.Message, ex);
                return(false);
            }
        }
Exemple #14
0
            public void Update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement statement, EPServiceProvider epServiceProvider)
            {
                EPDataFlowIRStreamCollectorContext holder = _collectorDataTL.GetOrCreate();

                if (holder == null)
                {
                    holder = new EPDataFlowIRStreamCollectorContext(_emitterForCollector, _submitEventBean, newEvents, oldEvents, statement, epServiceProvider);
                    _collectorDataTL.Value = holder;
                }
                else
                {
                    holder.ServiceProvider = epServiceProvider;
                    holder.Statement       = statement;
                    holder.OldEvents       = oldEvents;
                    holder.NewEvents       = newEvents;
                }

                _collector.Collect(holder);
            }
 public void PushStack(ExpressionResultCacheStackEntry lambda)
 {
     _threadCache.GetOrCreate().PushStack(lambda);
 }
        private void ProcessDispatches(NamedWindowConsumerLatch[] dispatches)
        {
            if (dispatches.Length == 1)
            {
                var latch = dispatches[0];
                try {
                    latch.Await();
                    var newData = latch.DeltaData.NewData;
                    var oldData = latch.DeltaData.OldData;

                    foreach (var entry in latch.DispatchTo)
                    {
                        var handle = entry.Key;

                        handle.StatementHandle.MetricsHandle.Call(
                            _metricReportingService.PerformanceCollector,
                            () => { ProcessHandle(handle, entry.Value, newData, oldData); });

                        if ((_isPrioritized) && (handle.IsPreemptive))
                        {
                            break;
                        }
                    }
                }
                finally {
                    latch.Done();
                }

                return;
            }

            // Multiple different-result dispatches to same or different statements are needed in two situations:
            // a) an event comes in, triggers two insert-into statements inserting into the same named window and the window produces 2 results
            // b) a time batch is grouped in the named window, and a timer fires for both groups at the same time producing more then one result
            // c) two on-merge/update/delete statements fire for the same arriving event each updating the named window

            // Most likely all dispatches go to different statements since most statements are not joins of
            // named windows that produce results at the same time. Therefore sort by statement handle.
            var dispatchesPerStmt = _dispatchesPerStmtTl.GetOrCreate();

            for (int ii = 0; ii < dispatches.Length; ii++)
            {
                var latch = dispatches[ii];
                latch.Await();
                foreach (var entry in latch.DispatchTo)
                {
                    var handle     = entry.Key;
                    var perStmtObj = dispatchesPerStmt.Get(handle);
                    if (perStmtObj == null)
                    {
                        dispatchesPerStmt.Put(handle, latch);
                    }
                    else if (perStmtObj is IList <NamedWindowConsumerLatch> )
                    {
                        var list = (IList <NamedWindowConsumerLatch>)perStmtObj;
                        list.Add(latch);
                    }
                    else     // convert from object to list
                    {
                        var unitObj = (NamedWindowConsumerLatch)perStmtObj;
                        IList <NamedWindowConsumerLatch> list = new List <NamedWindowConsumerLatch>();
                        list.Add(unitObj);
                        list.Add(latch);
                        dispatchesPerStmt.Put(handle, list);
                    }
                }
            }

            try {
                // Dispatch - with or without metrics reporting
                foreach (var entry in dispatchesPerStmt)
                {
                    var handle     = entry.Key;
                    var perStmtObj = entry.Value;

                    // dispatch of a single result to the statement
                    if (perStmtObj is NamedWindowConsumerLatch)
                    {
                        var unit    = (NamedWindowConsumerLatch)perStmtObj;
                        var newData = unit.DeltaData.NewData;
                        var oldData = unit.DeltaData.OldData;

                        handle.StatementHandle.MetricsHandle.Call(
                            _metricReportingService.PerformanceCollector,
                            () => ProcessHandle(handle, unit.DispatchTo.Get(handle), newData, oldData));

                        if ((_isPrioritized) && (handle.IsPreemptive))
                        {
                            break;
                        }

                        continue;
                    }

                    // dispatch of multiple results to a the same statement, need to aggregate per consumer view
                    var deltaPerConsumer = GetDeltaPerConsumer(perStmtObj, handle);
                    handle.StatementHandle.MetricsHandle.Call(
                        _metricReportingService.PerformanceCollector,
                        () => ProcessHandleMultiple(handle, deltaPerConsumer));

                    if ((_isPrioritized) && (handle.IsPreemptive))
                    {
                        break;
                    }
                }
            }
            finally
            {
                for (int ii = 0; ii < dispatches.Length; ii++)
                {
                    dispatches[ii].Done();
                }
            }

            dispatchesPerStmt.Clear();
        }
        /// <summary>
        /// Poll for stored historical or reference data using events per stream and
        /// returing for each event-per-stream row a separate list with events
        /// representing the poll result.
        /// </summary>
        /// <param name="lookupEventsPerStream">is the events per stream where the
        /// first dimension is a number of rows (often 1 depending on windows used) and
        /// the second dimension is the number of streams participating in a join.</param>
        /// <param name="indexingStrategy">the strategy to use for converting poll results into a indexed table for fast lookup</param>
        /// <param name="exprEvaluatorContext">The expression evaluator context.</param>
        /// <returns>
        /// array of lists with one list for each event-per-stream row
        /// </returns>
        public EventTable[][] Poll(EventBean[][] lookupEventsPerStream, PollResultIndexingStrategy indexingStrategy, ExprEvaluatorContext exprEvaluatorContext)
        {
            DataCache localDataCache  = _dataCacheThreadLocal.GetOrCreate();
            bool      strategyStarted = false;

            EventTable[][] resultPerInputRow = new EventTable[lookupEventsPerStream.Length][];

            // Get input parameters for each row
            for (int row = 0; row < lookupEventsPerStream.Length; row++)
            {
                Object[] lookupValues = new Object[_inputParameters.Count];

                // Build lookup keys
                for (int valueNum = 0; valueNum < _inputParameters.Count; valueNum++)
                {
                    EventBean[] eventsPerStream = lookupEventsPerStream[row];
                    Object      lookupValue     = _evaluators[valueNum].Evaluate(new EvaluateParams(eventsPerStream, true, exprEvaluatorContext));
                    lookupValues[valueNum] = lookupValue;
                }

                EventTable[] result = null;

                // try the threadlocal iteration cache, if set
                if (localDataCache != null)
                {
                    result = localDataCache.GetCached(lookupValues);
                }

                // try the connection cache
                if (result == null)
                {
                    EventTable[] multi = _dataCache.GetCached(lookupValues);
                    if (multi != null)
                    {
                        result = multi;
                        if (localDataCache != null)
                        {
                            localDataCache.PutCached(lookupValues, result);
                        }
                    }
                }

                // use the result from cache
                if (result != null)
                // found in cache
                {
                    resultPerInputRow[row] = result;
                }
                // not found in cache, get from actual polling (db query)
                else
                {
                    try
                    {
                        if (!strategyStarted)
                        {
                            _pollExecStrategy.Start();
                            strategyStarted = true;
                        }

                        // Poll using the polling execution strategy and lookup values
                        IList <EventBean> pollResult = _pollExecStrategy.Poll(lookupValues, exprEvaluatorContext);

                        // index the result, if required, using an indexing strategy
                        EventTable[] indexTable = indexingStrategy.Index(pollResult, _dataCache.IsActive);

                        // assign to row
                        resultPerInputRow[row] = indexTable;

                        // save in cache
                        _dataCache.PutCached(lookupValues, indexTable);

                        if (localDataCache != null)
                        {
                            localDataCache.PutCached(lookupValues, indexTable);
                        }
                    }
                    catch (EPException)
                    {
                        if (strategyStarted)
                        {
                            _pollExecStrategy.Done();
                        }

                        throw;
                    }
                }
            }


            if (strategyStarted)
            {
                _pollExecStrategy.Done();
            }

            return(resultPerInputRow);
        }
        public EventTable[][] Poll(EventBean[][] lookupEventsPerStream, PollResultIndexingStrategy indexingStrategy, ExprEvaluatorContext exprEvaluatorContext)
        {
            var localDataCache  = _dataCacheThreadLocal.GetOrCreate();
            var strategyStarted = false;

            var resultPerInputRow = new EventTable[lookupEventsPerStream.Length][];

            // Get input parameters for each row
            for (var row = 0; row < lookupEventsPerStream.Length; row++)
            {
                var methodParams   = new Object[_validatedExprNodes.Length];
                var evaluateParams = new EvaluateParams(lookupEventsPerStream[row], true, exprEvaluatorContext);

                // Build lookup keys
                for (var valueNum = 0; valueNum < _validatedExprNodes.Length; valueNum++)
                {
                    var parameterValue = _validatedExprNodes[valueNum].Evaluate(evaluateParams);
                    methodParams[valueNum] = parameterValue;
                }

                EventTable[] result = null;

                // try the threadlocal iteration cache, if set
                if (localDataCache != null)
                {
                    result = localDataCache.GetCached(methodParams, _methodStreamSpec.Expressions.Count);
                }

                // try the connection cache
                if (result == null)
                {
                    result = _dataCache.GetCached(methodParams, _methodStreamSpec.Expressions.Count);
                    if ((result != null) && (localDataCache != null))
                    {
                        localDataCache.PutCached(methodParams, _methodStreamSpec.Expressions.Count, result);
                    }
                }

                if (result != null)
                {
                    // found in cache
                    resultPerInputRow[row] = result;
                }
                else
                {
                    // not found in cache, get from actual polling (db query)
                    try {
                        if (!strategyStarted)
                        {
                            _pollExecStrategy.Start();
                            strategyStarted = true;
                        }

                        // Poll using the polling execution strategy and lookup values
                        var pollResult = _pollExecStrategy.Poll(methodParams, exprEvaluatorContext);

                        // index the result, if required, using an indexing strategy
                        var indexTable = indexingStrategy.Index(pollResult, _dataCache.IsActive, _statementContext);

                        // assign to row
                        resultPerInputRow[row] = indexTable;

                        // save in cache
                        _dataCache.PutCached(methodParams, _methodStreamSpec.Expressions.Count, indexTable);

                        if (localDataCache != null)
                        {
                            localDataCache.PutCached(methodParams, _methodStreamSpec.Expressions.Count, indexTable);
                        }
                    } catch (EPException ex) {
                        if (strategyStarted)
                        {
                            _pollExecStrategy.Done();
                        }
                        throw;
                    }
                }
            }

            if (strategyStarted)
            {
                _pollExecStrategy.Done();
            }

            return(resultPerInputRow);
        }
Exemple #19
0
 /// <summary>
 /// Add an item to be dispatched.  The item is added to
 /// the external dispatch queue.
 /// </summary>
 /// <param name="dispatchable">to execute later</param>
 public void AddExternal(Dispatchable dispatchable)
 {
     _threadDispatchQueue
     .GetOrCreate()
     .Enqueue(dispatchable);
 }
 public IntersectAsymetricViewLocalState GetAsymetricViewLocalStatePerThread()
 {
     return(_asymetricViewLocalState.GetOrCreate());
 }
 public IntersectDefaultViewLocalState GetDefaultViewLocalStatePerThread()
 {
     return(_defaultViewLocalState.GetOrCreate());
 }
 public IntersectBatchViewLocalState GetBatchViewLocalStatePerThread()
 {
     return(_batchViewLocalState.GetOrCreate());
 }
Exemple #23
0
 public void Dispatch()
 {
     DispatchFromQueue(dispatchStateThreadLocal.GetOrCreate());
 }