use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class FindStoreQueryRuntime method executeSelector.
private Event[] executeSelector(StreamEvent streamEvents, MetaStreamEvent.EventType eventType) {
ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>(true);
while (streamEvents != null) {
StreamEvent streamEvent = streamEvents;
streamEvents = streamEvents.getNext();
streamEvent.setNext(null);
StateEvent stateEvent = stateEventPool.borrowEvent();
if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
stateEvent.addEvent(1, streamEvent);
} else {
stateEvent.addEvent(0, streamEvent);
}
complexEventChunk.add(stateEvent);
}
ComplexEventChunk outputComplexEventChunk = selector.execute(complexEventChunk);
if (outputComplexEventChunk != null) {
List<Event> events = new ArrayList<>();
outputComplexEventChunk.reset();
while (outputComplexEventChunk.hasNext()) {
ComplexEvent complexEvent = outputComplexEventChunk.next();
events.add(new Event(complexEvent.getTimestamp(), complexEvent.getOutputData()));
}
return events.toArray(new Event[0]);
} else {
return null;
}
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class StateMultiProcessStreamReceiver method processAndClear.
protected void processAndClear(int processIndex, StreamEvent streamEvent) {
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(batchProcessingAllowed);
ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent, batchProcessingAllowed);
ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) nextProcessors[processIndex]).processAndReturn(currentStreamEventChunk);
if (eventChunk.getFirst() != null) {
retEventChunk.add(eventChunk.getFirst());
}
eventChunk.clear();
if (querySelector != null) {
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, batchProcessingAllowed));
}
}
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class JoinProcessor method joinEventBuilder.
/**
* Join the given two event streams.
*
* @param leftStream event left stream
* @param rightStream event right stream
* @param type complex event type
* @return StateEvent state event
*/
public StateEvent joinEventBuilder(StreamEvent leftStream, StreamEvent rightStream, ComplexEvent.Type type) {
StateEvent returnEvent = stateEventPool.borrowEvent();
returnEvent.setEvent(0, leftStream);
returnEvent.setEvent(1, rightStream);
returnEvent.setType(type);
if (!leftJoinProcessor) {
returnEvent.setTimestamp(rightStream.getTimestamp());
} else {
returnEvent.setTimestamp(leftStream.getTimestamp());
}
return returnEvent;
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class FindStoreQueryRuntime 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 = stateEventPool.borrowEvent();
if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
stateEvent.addEvent(1, streamEvent);
} else {
stateEvent.addEvent(0, streamEvent);
}
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>(true);
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class SelectStoreQueryRuntime method execute.
public Event[] execute() {
try {
StateEvent stateEvent = new StateEvent(1, 0);
StreamEvent streamEvents = queryableProcessor.query(stateEvent, compiledCondition, compiledSelection);
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 StoreQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
}
}
Aggregations