use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class MatcherParser method constructMatchingMetaStateHolder.
public static MatchingMetaInfoHolder constructMatchingMetaStateHolder(MetaComplexEvent matchingMetaComplexEvent, int defaultStreamEventIndex, AbstractDefinition candsidateDefinition, int currentState) {
int storeEventIndex = 0;
MetaStreamEvent tableStreamEvent = new MetaStreamEvent();
tableStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
tableStreamEvent.addInputDefinition(candsidateDefinition);
for (Attribute attribute : candsidateDefinition.getAttributeList()) {
tableStreamEvent.addOutputData(attribute);
}
MetaStateEvent metaStateEvent = null;
if (matchingMetaComplexEvent instanceof MetaStreamEvent) {
metaStateEvent = new MetaStateEvent(2);
metaStateEvent.addEvent(((MetaStreamEvent) matchingMetaComplexEvent));
metaStateEvent.addEvent(tableStreamEvent);
storeEventIndex = 1;
defaultStreamEventIndex = 0;
if (currentState == SiddhiConstants.UNKNOWN_STATE) {
currentState = defaultStreamEventIndex;
}
} else {
MetaStreamEvent[] metaStreamEvents = ((MetaStateEvent) matchingMetaComplexEvent).getMetaStreamEvents();
// for join
for (; storeEventIndex < metaStreamEvents.length; storeEventIndex++) {
MetaStreamEvent metaStreamEvent = metaStreamEvents[storeEventIndex];
if (storeEventIndex != defaultStreamEventIndex && metaStreamEvent.getLastInputDefinition().equalsIgnoreAnnotations(candsidateDefinition)) {
metaStateEvent = ((MetaStateEvent) matchingMetaComplexEvent);
break;
}
}
if (metaStateEvent == null) {
metaStateEvent = new MetaStateEvent(metaStreamEvents.length + 1);
for (MetaStreamEvent metaStreamEvent : metaStreamEvents) {
metaStateEvent.addEvent(metaStreamEvent);
}
metaStateEvent.addEvent(tableStreamEvent);
storeEventIndex = metaStreamEvents.length;
}
}
return new MatchingMetaInfoHolder(metaStateEvent, defaultStreamEventIndex, storeEventIndex, metaStateEvent.getMetaStreamEvent(defaultStreamEventIndex).getLastInputDefinition(), candsidateDefinition, currentState);
}
use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class CacheTable method initCacheTable.
public void initCacheTable(TableDefinition cacheTableDefinition, ConfigReader configReader, SiddhiAppContext siddhiAppContext, RecordTableHandler recordTableHandler, boolean cacheExpiryEnabled, int maxSize, String cachePolicy) {
this.maxSize = maxSize;
this.cacheExpiryEnabled = cacheExpiryEnabled;
this.siddhiAppContext = siddhiAppContext;
addRequiredFieldsToCacheTableDefinition(cacheTableDefinition, cacheExpiryEnabled);
// initialize cache table
MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
cacheTableMetaStreamEvent.addInputDefinition(cacheTableDefinition);
for (Attribute attribute : cacheTableDefinition.getAttributeList()) {
cacheTableMetaStreamEvent.addOutputData(attribute);
}
StreamEventFactory cacheTableStreamEventFactory = new StreamEventFactory(cacheTableMetaStreamEvent);
StreamEventCloner cacheTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, cacheTableStreamEventFactory);
super.initTable(cacheTableDefinition, cacheTableStreamEventFactory, cacheTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method processAllExpiredEvents.
private void processAllExpiredEvents(StreamEventCloner streamEventCloner, WindowState state, long currentTime, List<ComplexEventChunk<StreamEvent>> streamEventChunks) {
MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
if (!streamInputEvents) {
StreamEvent expiredEvent = state.currentEventQueue.getFirst();
state.currentEventQueue.clear();
while (expiredEvent != null) {
StreamEvent aExpiredEvent = expiredEvent;
expiredEvent = expiredEvent.getNext();
aExpiredEvent.setNext(null);
processStreamEvent(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks);
}
state.currentEventQueue.reset();
} else {
StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
state.expiredEventQueue.clear();
while (expiredEvent != null) {
StreamEvent aExpiredEvent = expiredEvent;
expiredEvent = expiredEvent.getNext();
aExpiredEvent.setNext(null);
processStreamEventAsStream(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks, false);
}
state.expiredEventQueue.reset();
}
}
use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
if (expressionStringExecutor == null && !init) {
MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEvent, metaStreamEvent });
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
init = true;
}
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
if (expressionStringExecutor != null) {
String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
if (!expressionStringNew.equals(expressionString)) {
expressionString = expressionStringNew;
processAllExpiredEvents(streamEventCloner, state, currentTime, streamEventChunks);
}
}
if (!streamInputEvents) {
processStreamEvent(state, currentTime, streamEvent, streamEventCloner, streamEventChunks);
} else {
processStreamEventAsStream(state, currentTime, streamEvent, streamEventCloner, streamEventChunks, true);
}
}
}
for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
nextProcessor.process(outputStreamEventChunk);
}
}
use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class ExpressionWindowProcessor method processAllExpiredEvents.
private void processAllExpiredEvents(ComplexEventChunk<StreamEvent> streamEventChunk, WindowState state, long currentTime) {
MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
state.expiredEventQueue.clear();
while (expiredEvent != null) {
StreamEvent aExpiredEvent = expiredEvent;
expiredEvent = expiredEvent.getNext();
aExpiredEvent.setNext(null);
processStreamEvent(streamEventChunk, state, currentTime, aExpiredEvent);
}
state.expiredEventQueue.reset();
}
Aggregations