use of io.siddhi.core.event.GroupedComplexEvent in project siddhi by wso2.
the class FirstGroupByPerEventOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
Integer count = state.groupByOutputTime.get(groupedComplexEvent.getGroupKey());
if (count == null) {
state.groupByOutputTime.put(groupedComplexEvent.getGroupKey(), 1);
outputEventChunk.add(groupedComplexEvent);
} else if (count.equals(value - 1)) {
state.groupByOutputTime.remove(groupedComplexEvent.getGroupKey());
} else {
state.groupByOutputTime.put(groupedComplexEvent.getGroupKey(), count + 1);
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
use of io.siddhi.core.event.GroupedComplexEvent in project siddhi by wso2.
the class AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
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);
LastEventHolder lastEventHolder = state.groupByKeyEvents.get(groupedComplexEvent.getGroupKey());
if (lastEventHolder == null) {
lastEventHolder = new LastEventHolder();
state.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) {
state.groupByKeyEvents.clear();
}
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
use of io.siddhi.core.event.GroupedComplexEvent in project siddhi by wso2.
the class GroupByPerSnapshotOutputRateLimiter method process.
/**
* Sends the collected unique outputs per group by key upon arrival of timer event from scheduler.
*
* @param complexEventChunk Incoming {@link ComplexEventChunk}
*/
@Override
public void process(ComplexEventChunk complexEventChunk) {
List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event, state);
} else if (event.getType() == ComplexEvent.Type.CURRENT) {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event, state);
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
state.groupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
use of io.siddhi.core.event.GroupedComplexEvent in project siddhi by wso2.
the class FirstGroupByPerTimeOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
Long outputTime = state.groupByOutputTime.get(groupedComplexEvent.getGroupKey());
if (outputTime == null || outputTime + value <= currentTime) {
state.groupByOutputTime.put(groupedComplexEvent.getGroupKey(), currentTime);
outputEventChunk.add(groupedComplexEvent);
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
use of io.siddhi.core.event.GroupedComplexEvent 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);
SiddhiAppContext.startGroupByFlow(groupByKey);
try {
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);
}
}
} finally {
SiddhiAppContext.stopGroupByFlow();
}
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 (offset != SiddhiConstants.UNKNOWN_STATE) {
offsetEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
complexEventChunk.reset();
return complexEventChunk;
}
return null;
}
Aggregations