use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class Window method add.
/**
* Add the given ComplexEventChunk to the Window.
*
* @param complexEventChunk the event chunk to be added
*/
public void add(ComplexEventChunk complexEventChunk) {
try {
this.lockWrapper.lock();
complexEventChunk.reset();
// Convert all events to StreamEvent because StateEvents can be passed if directly received from a join
ComplexEvent complexEvents = complexEventChunk.getFirst();
StreamEvent firstEvent = streamEventPool.borrowEvent();
eventConverter.convertComplexEvent(complexEvents, firstEvent);
StreamEvent currentEvent = firstEvent;
complexEvents = complexEvents.getNext();
int numberOfEvents = 0;
while (complexEvents != null) {
numberOfEvents++;
StreamEvent nextEvent = streamEventPool.borrowEvent();
eventConverter.convertComplexEvent(complexEvents, nextEvent);
currentEvent.setNext(nextEvent);
currentEvent = nextEvent;
complexEvents = complexEvents.getNext();
}
try {
if (throughputTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
throughputTrackerInsert.eventsIn(numberOfEvents);
latencyTrackerInsert.markIn();
}
// Send to the window windowProcessor
windowProcessor.process(new ComplexEventChunk<StreamEvent>(firstEvent, currentEvent, complexEventChunk.isBatch()));
} finally {
if (throughputTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
latencyTrackerInsert.markOut();
}
}
} finally {
this.lockWrapper.unlock();
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class QuerySelector method processInBatchNoGroupBy.
private ComplexEventChunk processInBatchNoGroupBy(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ComplexEvent lastEvent = null;
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
switch(event.getType()) {
case CURRENT:
case EXPIRED:
eventPopulator.populateStateEvent(event);
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
complexEventChunk.remove();
lastEvent = event;
}
}
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (lastEvent != null) {
complexEventChunk.clear();
if (limit == SiddhiConstants.UNKNOWN_STATE || limit > 0) {
complexEventChunk.add(lastEvent);
}
return complexEventChunk;
}
return null;
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class QuerySelector method orderEventChunk.
private void orderEventChunk(ComplexEventChunk complexEventChunk) {
ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk(complexEventChunk.isBatch());
List<ComplexEvent> eventList = new ArrayList<>();
ComplexEvent.Type currentEventType = null;
complexEventChunk.reset();
if (complexEventChunk.getFirst() != null) {
currentEventType = complexEventChunk.getFirst().getType();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
if (currentEventType == event.getType()) {
eventList.add(event);
} else {
currentEventType = event.getType();
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
eventList.clear();
eventList.add(event);
}
}
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
complexEventChunk.clear();
complexEventChunk.add(orderingComplexEventChunk.getFirst());
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class QuerySelector method limitEventChunk.
private void limitEventChunk(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
int limitCount = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == StreamEvent.Type.CURRENT || event.getType() == StreamEvent.Type.EXPIRED) {
if ((limit > limitCount) && (event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
limitCount++;
} else {
complexEventChunk.remove();
}
}
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class QuerySelector method processGroupBy.
private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ComplexEventChunk<ComplexEvent> currentComplexEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
synchronized (this) {
int limitCount = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
switch(event.getType()) {
case CURRENT:
case EXPIRED:
eventPopulator.populateStateEvent(event);
String groupedByKey = groupByKeyGenerator.constructEventKey(event);
GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupedByKey);
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
complexEventChunk.remove();
if (limit == SiddhiConstants.UNKNOWN_STATE) {
currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey, event));
} else {
if (limitCount < limit) {
currentComplexEventChunk.add(new GroupedComplexEvent(groupedByKey, event));
limitCount++;
}
}
}
}
GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (isOrderBy) {
orderEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
currentComplexEventChunk.reset();
if (currentComplexEventChunk.hasNext()) {
return currentComplexEventChunk;
}
return null;
}
Aggregations