use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class SelectOnDemandQueryRuntime method execute.
public Event[] execute() {
try {
StateEvent stateEvent = new StateEvent(1, 0);
StreamEvent streamEvents = queryableProcessor.query(stateEvent, compiledCondition, compiledSelection, outputAttributes);
if (streamEvents == null) {
return null;
} else {
List<Event> events = new ArrayList<Event>();
while (streamEvents != null) {
events.add(new Event(streamEvents.getTimestamp(), streamEvents.getOutputData()));
streamEvents = streamEvents.getNext();
}
return events.toArray(new Event[0]);
}
} catch (Throwable t) {
throw new OnDemandQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class SelectOnDemandQueryRuntime method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getOutputData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
stateEvent.addEvent(1, streamEvent);
} else {
stateEvent.addEvent(0, streamEvent);
}
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class UpdateOrInsertOnDemandQueryRuntime method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
stateEvent.addEvent(0, streamEvent);
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class JoinProcessor method execute.
private void execute(ComplexEventChunk complexEventChunk, List<ComplexEventChunk> returnEventChunkList) {
StateEvent joinStateEvent = new StateEvent(2, 0);
StreamEvent nextEvent = (StreamEvent) complexEventChunk.getFirst();
complexEventChunk.clear();
while (nextEvent != null) {
StreamEvent streamEvent = nextEvent;
nextEvent = streamEvent.getNext();
streamEvent.setNext(null);
ComplexEvent.Type eventType = streamEvent.getType();
if (eventType == ComplexEvent.Type.TIMER) {
continue;
} else if (eventType == ComplexEvent.Type.RESET) {
if (!leftJoinProcessor) {
StateEvent outputStateEvent = joinEventBuilder(null, streamEvent, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
} else {
StateEvent outputStateEvent = joinEventBuilder(streamEvent, null, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
}
} else {
joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
StreamEvent foundStreamEvent;
if (this.isOptimisedQuery) {
try {
foundStreamEvent = query(joinStateEvent);
} catch (SiddhiAppRuntimeException e) {
log.warn("Performing select clause in databases failed due to '" + e.getMessage() + " in query '" + queryName + "' within Siddhi app '" + siddhiAppName + "' hence reverting back to querying only with where clause.", e);
this.isOptimisedQuery = false;
foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
}
} else {
foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
}
joinStateEvent.setEvent(matchingStreamIndex, null);
if (foundStreamEvent == null) {
if (outerJoinProcessor && !leftJoinProcessor) {
StateEvent outputStateEvent = joinEventBuilder(null, streamEvent, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
} else if (outerJoinProcessor && leftJoinProcessor) {
StateEvent outputStateEvent = joinEventBuilder(streamEvent, null, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
}
} else if (!isOptimisedQuery) {
ComplexEventChunk<ComplexEvent> returnEventChunk = new ComplexEventChunk<>();
while (foundStreamEvent != null) {
StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
foundStreamEvent.setNext(null);
if (!leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(foundStreamEvent, streamEvent, eventType));
} else {
returnEventChunk.add(joinEventBuilder(streamEvent, foundStreamEvent, eventType));
}
foundStreamEvent = nextFoundStreamEvent;
}
returnEventChunkList.add(new SelectorTypeComplexEventChunk(returnEventChunk, false));
} else {
ComplexEventChunk<ComplexEvent> returnEventChunk = new ComplexEventChunk<>();
while (foundStreamEvent != null) {
StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
StateEvent returnEvent = stateEventFactory.newInstance();
returnEvent.setType(eventType);
returnEvent.setTimestamp(foundStreamEvent.getTimestamp());
Object[] outputData = foundStreamEvent.getOutputData();
for (int i = 0; i < outputData.length; i++) {
Object data = outputData[i];
returnEvent.setOutputData(data, i);
}
returnEventChunk.add(returnEvent);
foundStreamEvent = nextFoundStreamEvent;
}
returnEventChunkList.add(new SelectorTypeComplexEventChunk(returnEventChunk, true));
}
}
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class AbsentStreamPostStateProcessor method process.
/**
* This method just mark the state changed but does not send the stateEvent to the next processors.
*
* @param stateEvent the state event
* @param complexEventChunk the ComplexEventChunk
*/
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
// Mark the state changed
thisStatePreProcessor.stateChanged();
// Update the timestamp
StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setTimestamp(streamEvent.getTimestamp());
// This is the notification to AbsentStreamPreStateProcessor that this event has been processed
this.isEventReturned = true;
if (thisStatePreProcessor.isStartState) {
if (nextEveryStatePreProcessor != null && nextEveryStatePreProcessor == thisStatePreProcessor) {
// nextEveryStatePreProcessor refers the AbsentStreamPreStateProcessor
nextEveryStatePreProcessor.addEveryState(stateEvent);
}
}
((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
Aggregations