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); }
public EventTable[][] Poll( EventBean[][] lookupEventsPerStream, PollResultIndexingStrategy indexingStrategy, ExprEvaluatorContext exprEvaluatorContext) { var localDataCache = _factory.DataCacheThreadLocal.GetOrCreate(); var strategyStarted = false; var resultPerInputRow = new EventTable[lookupEventsPerStream.Length][]; // Get input parameters for each row EventBean[] eventsPerStream; for (var row = 0; row < lookupEventsPerStream.Length; row++) { // Build lookup keys eventsPerStream = lookupEventsPerStream[row]; var lookupValue = _factory.Evaluator.Evaluate(eventsPerStream, true, exprEvaluatorContext); EventTable[] result = null; // try the threadlocal iteration cache, if set object cacheMultiKey = null; if (localDataCache != null || DataCache.IsActive) { cacheMultiKey = _factory.LookupValueToMultiKey.Invoke(lookupValue); } if (localDataCache != null) { result = localDataCache.GetCached(cacheMultiKey); } // try the connection cache if (result == null) { var multi = DataCache.GetCached(cacheMultiKey); if (multi != null) { result = multi; localDataCache?.Put(cacheMultiKey, multi); } } // use the result from cache 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 IList<EventBean> pollResult = _pollExecStrategy.Poll(lookupValue, _agentInstanceContext); // index the result, if required, using an indexing strategy var indexTable = indexingStrategy.Index(pollResult, DataCache.IsActive, _agentInstanceContext); // assign to row resultPerInputRow[row] = indexTable; // save in cache DataCache.Put(cacheMultiKey, indexTable); localDataCache?.Put(cacheMultiKey, indexTable); } catch (EPException) { if (strategyStarted) { _pollExecStrategy.Done(); } throw; } } } if (strategyStarted) { _pollExecStrategy.Done(); } return resultPerInputRow; }
/// <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); }