Search in sources :

Example 6 with ComplexEventChunk

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);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent)

Example 7 with ComplexEventChunk

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);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) LinkedList(java.util.LinkedList)

Example 8 with ComplexEventChunk

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);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Example 9 with ComplexEventChunk

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);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) LinkedList(java.util.LinkedList)

Example 10 with ComplexEventChunk

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);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Aggregations

ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)114 StreamEvent (io.siddhi.core.event.stream.StreamEvent)75 ComplexEvent (io.siddhi.core.event.ComplexEvent)41 StateEvent (io.siddhi.core.event.state.StateEvent)38 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)34 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)14 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)13 LinkedList (java.util.LinkedList)12 Map (java.util.Map)12 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ArrayList (java.util.ArrayList)10 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)7 HashMap (java.util.HashMap)7 Attribute (io.siddhi.query.api.definition.Attribute)5 Event (io.siddhi.core.event.Event)4 TimePeriod (io.siddhi.query.api.aggregation.TimePeriod)4 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)3 Table (io.siddhi.core.table.Table)3 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)2