use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class CountPostStateProcessor method process.
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
int streamEvents = 1;
while (streamEvent.getNext() != null) {
streamEvents++;
streamEvent = streamEvent.getNext();
}
((CountPreStateProcessor) thisStatePreProcessor).successCondition();
stateEvent.setTimestamp(streamEvent.getTimestamp());
if (streamEvents >= minCount) {
if (thisStatePreProcessor.stateType == StateInputStream.Type.SEQUENCE) {
if (nextStatePerProcessor != null) {
nextStatePerProcessor.addState(stateEvent);
}
if (streamEvents != maxCount) {
thisStatePreProcessor.addState(stateEvent);
}
} else if (streamEvents == minCount) {
processMinCountReached(stateEvent, complexEventChunk);
}
if (streamEvents == maxCount) {
thisStatePreProcessor.stateChanged();
}
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class CountPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 1)) {
continue;
}
if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 2)) {
continue;
}
stateEvent.addEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
successCondition = false;
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (stateChanged) {
iterator.remove();
}
if (!successCondition) {
switch(stateType) {
case PATTERN:
stateEvent.removeLastEvent(stateId);
break;
case SEQUENCE:
stateEvent.removeLastEvent(stateId);
iterator.remove();
break;
}
}
}
return returnEventChunk;
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class LogicalPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (withinStates.size() > 0) {
if (isExpired(stateEvent, streamEvent.getTimestamp())) {
iterator.remove();
continue;
}
}
if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
iterator.remove();
continue;
}
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (stateChanged) {
iterator.remove();
} else {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, null);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, null);
iterator.remove();
break;
}
}
}
return returnEventChunk;
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class FindStoreQueryRuntime method execute.
@Override
public Event[] execute() {
try {
StateEvent stateEvent = new StateEvent(1, 0);
StreamEvent streamEvents = null;
switch(eventType) {
case TABLE:
streamEvents = table.find(stateEvent, compiledCondition);
break;
case WINDOW:
streamEvents = window.find(stateEvent, compiledCondition);
break;
case AGGREGATE:
stateEvent = new StateEvent(2, 0);
StreamEvent streamEvent = new StreamEvent(0, 2, 0);
stateEvent.addEvent(0, streamEvent);
streamEvents = aggregation.find(stateEvent, compiledCondition);
break;
case DEFAULT:
break;
}
if (streamEvents == null) {
return null;
} else {
if (selector != null) {
return executeSelector(streamEvents, eventType);
} 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);
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent 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;
}
}
Aggregations