use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
AggregationGroupByRateLimiterState state = (AggregationGroupByRateLimiterState) stateHolder.getState();
try {
synchronized (state) {
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, state);
} else {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event, state);
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
currentGroupByKey = groupedComplexEvent.getGroupKey();
currentAggregateAttributeValueMap = state.groupByAggregateAttributeValueMap.get(currentGroupByKey);
if (currentAggregateAttributeValueMap == null) {
currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
state.groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
}
}
if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
state.eventList.add(groupedComplexEvent);
for (Integer position : aggregateAttributePositionList) {
currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
} else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
for (Iterator<GroupedComplexEvent> iterator = state.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) {
state.eventList.clear();
state.groupByAggregateAttributeValueMap.clear();
}
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method constructOutputChunk.
private void constructOutputChunk(List<ComplexEventChunk> outputEventChunks, AggregationGroupByRateLimiterState state) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
Set<String> outputGroupingKeys = new HashSet<>();
for (GroupedComplexEvent originalComplexEvent : state.eventList) {
String currentGroupByKey = originalComplexEvent.getGroupKey();
if (!outputGroupingKeys.contains(currentGroupByKey)) {
outputGroupingKeys.add(currentGroupByKey);
Map<Integer, Object> currentAggregateAttributeValueMap = state.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 io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class LastGroupByPerTimeOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
if (event.getTimestamp() >= state.scheduledTime) {
if (state.allGroupByKeyEvents.size() != 0) {
for (ComplexEvent complexEvent : state.allGroupByKeyEvents.values()) {
outputEventChunk.add(complexEvent);
}
state.allGroupByKeyEvents.clear();
}
state.scheduledTime = state.scheduledTime + value;
scheduler.notifyAt(state.scheduledTime);
}
} else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
complexEventChunk.remove();
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
state.allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class FilterProcessor method process.
@Override
public void process(List<ComplexEventChunk> complexEventChunks) {
ComplexEventChunk complexEventChunk = new ComplexEventChunk();
for (ComplexEventChunk streamEventChunk : complexEventChunks) {
complexEventChunk.addAll(streamEventChunk);
}
process(complexEventChunk);
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class EmptyWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
List<ComplexEventChunk> streamEventChunks = new LinkedList<>();
synchronized (state) {
ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<StreamEvent>();
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
outputStreamEventChunk.add(streamEvent);
if (outputExpectsExpiredEvents) {
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
expiredEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(expiredEvent);
}
StreamEvent resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
resetEvent.setType(ComplexEvent.Type.RESET);
resetEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(resetEvent);
if (outputStreamEventChunk.getFirst() != null) {
streamEventChunks.add(outputStreamEventChunk);
outputStreamEventChunk = new ComplexEventChunk<>();
}
}
}
nextProcessor.process(streamEventChunks);
}
Aggregations