use of io.siddhi.core.event.ComplexEventChunk 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.ComplexEventChunk 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.ComplexEventChunk in project siddhi by wso2.
the class GroupByPerSnapshotOutputRateLimiter method tryFlushEvents.
private void tryFlushEvents(List<ComplexEventChunk> outputEventChunks, ComplexEvent event, RateLimiterState state) {
if (event.getTimestamp() >= state.scheduledTime) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
for (ComplexEvent complexEvent : state.groupByKeyEvents.values()) {
outputEventChunk.add(cloneComplexEvent(complexEvent));
}
outputEventChunks.add(outputEventChunk);
state.scheduledTime += value;
scheduler.notifyAt(state.scheduledTime);
}
}
use of io.siddhi.core.event.ComplexEventChunk 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.ComplexEventChunk in project siddhi by wso2.
the class SnapshotOutputRateLimiter method sendToCallBacks.
protected void sendToCallBacks(List<ComplexEventChunk> outputEventChunks) {
if (!outputEventChunks.isEmpty()) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
for (ComplexEventChunk eventChunk : outputEventChunks) {
outputEventChunk.addAll(eventChunk);
}
wrappedSnapshotOutputRateLimiter.passToCallBacks(outputEventChunk);
}
}
Aggregations