use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
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.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class QuerySelector method processInBatchGroupBy.
private ComplexEventChunk processInBatchGroupBy(ComplexEventChunk complexEventChunk) {
Map<String, ComplexEvent> groupedEvents = new LinkedHashMap<String, ComplexEvent>();
complexEventChunk.reset();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
switch(event.getType()) {
case CURRENT:
case EXPIRED:
eventPopulator.populateStateEvent(event);
String groupByKey = groupByKeyGenerator.constructEventKey(event);
GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupByKey);
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();
groupedEvents.put(groupByKey, event);
}
}
GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (groupedEvents.size() != 0) {
complexEventChunk.clear();
for (Map.Entry<String, ComplexEvent> groupedEventEntry : groupedEvents.entrySet()) {
complexEventChunk.add(new GroupedComplexEvent(groupedEventEntry.getKey(), groupedEventEntry.getValue()));
}
if (isOrderBy) {
orderEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
complexEventChunk.reset();
return complexEventChunk;
}
return null;
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
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.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class LastPerEventOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
if (++counter == value) {
complexEventChunk.remove();
ComplexEventChunk<ComplexEvent> lastPerEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
lastPerEventChunk.add(event);
counter = 0;
outputEventChunks.add(lastPerEventChunk);
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method constructOutputChunk.
private void constructOutputChunk(List<ComplexEventChunk<ComplexEvent>> outputEventChunks) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
for (GroupedComplexEvent originalComplexEvent : eventList) {
String currentGroupByKey = originalComplexEvent.getGroupKey();
Map<Integer, Object> currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent.getComplexEvent());
for (Integer position : aggregateAttributePositionList) {
eventCopy.getOutputData()[position] = currentAggregateAttributeValueMap.get(position);
}
outputEventChunk.add(eventCopy);
}
outputEventChunks.add(outputEventChunk);
}
Aggregations