use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
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.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AggregationWindowedPerSnapshotOutputRateLimiter method tryFlushEvents.
private void tryFlushEvents(ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks, ComplexEvent event) {
if (event.getTimestamp() >= scheduledTime) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
for (ComplexEvent originalComplexEvent : eventList) {
ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent);
for (Integer position : aggregateAttributePositionList) {
eventCopy.getOutputData()[position] = aggregateAttributeValueMap.get(position);
}
outputEventChunk.add(eventCopy);
}
outputEventChunks.add(outputEventChunk);
scheduledTime += value;
scheduler.notifyAt(scheduledTime);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class GroupByPerSnapshotOutputRateLimiter method tryFlushEvents.
private void tryFlushEvents(List<ComplexEventChunk<ComplexEvent>> outputEventChunks, ComplexEvent event) {
if (event.getTimestamp() >= scheduledTime) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
for (ComplexEvent complexEvent : groupByKeyEvents.values()) {
outputEventChunk.add(cloneComplexEvent(complexEvent));
}
outputEventChunks.add(outputEventChunk);
scheduledTime += value;
scheduler.notifyAt(scheduledTime);
}
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class GroupByAggregationAttributeExecutor method execute.
@Override
public Object execute(ComplexEvent event) {
long currentTime = timestampGenerator.currentTime();
boolean canClean = false;
if (lastCleanupTimestamp + 5000 < currentTime || obsoleteAggregatorKeys.size() > 25) {
lastCleanupTimestamp = currentTime;
canClean = true;
}
if (event.getType() == ComplexEvent.Type.RESET) {
Object aOutput = null;
if (canClean) {
Iterator<AttributeAggregator> iterator = aggregatorMap.values().iterator();
if (iterator.hasNext()) {
aOutput = iterator.next().process(event);
}
aggregatorMap.clear();
obsoleteAggregatorKeys.clear();
} else {
for (Map.Entry<String, AttributeAggregator> attributeAggregatorEntry : aggregatorMap.entrySet()) {
aOutput = attributeAggregatorEntry.getValue().process(event);
}
}
return aOutput;
}
String key = keyThreadLocal.get();
AttributeAggregator currentAttributeAggregator = aggregatorMap.get(key);
if (currentAttributeAggregator == null) {
currentAttributeAggregator = attributeAggregator.cloneAggregator(key);
aggregatorMap.put(key, currentAttributeAggregator);
}
Object results = currentAttributeAggregator.process(event);
if (event.getType() == ComplexEvent.Type.EXPIRED && currentAttributeAggregator.canDestroy()) {
obsoleteAggregatorKeys.add(key);
}
if (canClean) {
destroyObsoleteAggregators();
}
return results;
}
use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class ListEventHolder method add.
@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) {
addingEventChunk.reset();
while (addingEventChunk.hasNext()) {
ComplexEvent complexEvent = addingEventChunk.next();
StreamEvent streamEvent = tableStreamEventPool.borrowEvent();
eventConverter.convertComplexEvent(complexEvent, streamEvent);
this.add(streamEvent);
}
}
Aggregations