use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
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);
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
synchronized (this) {
complexEventChunk.reset();
String currentGroupByKey = null;
Map<Integer, Object> currentAggregateAttributeValueMap = null;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event);
} else {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event);
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
currentGroupByKey = groupedComplexEvent.getGroupKey();
currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
if (currentAggregateAttributeValueMap == null) {
currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
}
}
if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
eventList.add(groupedComplexEvent);
for (Integer position : aggregateAttributePositionList) {
currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
for (Iterator<GroupedComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
GroupedComplexEvent currentEvent = iterator.next();
if (comparator.compare(currentEvent.getComplexEvent(), groupedComplexEvent.getComplexEvent()) == 0) {
iterator.remove();
for (Integer position : aggregateAttributePositionList) {
currentAggregateAttributeValueMap.put(position, groupedComplexEvent.getOutputData()[position]);
}
break;
}
}
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
eventList.clear();
groupByAggregateAttributeValueMap.clear();
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class AggregationWindowedPerSnapshotOutputRateLimiter 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.TIMER) {
tryFlushEvents(outputEventChunks, event);
} else {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event);
if (event.getType() == ComplexEvent.Type.CURRENT) {
eventList.add(event);
for (Integer position : aggregateAttributePositionList) {
aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
} else if (event.getType() == ComplexEvent.Type.EXPIRED) {
for (Iterator<ComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
ComplexEvent complexEvent = iterator.next();
if (comparator.compare(event, complexEvent) == 0) {
iterator.remove();
for (Integer position : aggregateAttributePositionList) {
aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
break;
}
}
} else if (event.getType() == ComplexEvent.Type.RESET) {
eventList.clear();
aggregateAttributeValueMap.clear();
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
complexEventChunk.reset();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event);
} else {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event);
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
LastEventHolder lastEventHolder = groupByKeyEvents.get(groupedComplexEvent.getGroupKey());
if (lastEventHolder == null) {
lastEventHolder = new LastEventHolder();
groupByKeyEvents.put(groupedComplexEvent.getGroupKey(), lastEventHolder);
}
if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
lastEventHolder.addLastInEvent(groupedComplexEvent.getComplexEvent());
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
lastEventHolder.removeLastInEvent(groupedComplexEvent.getComplexEvent());
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
groupByKeyEvents.clear();
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk 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