Search in sources :

Example 16 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class OutputRateLimiter method process.

public void process(List<ComplexEventChunk> complexEventChunks) {
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    for (ComplexEventChunk aComplexEventChunk : complexEventChunks) {
        complexEventChunk.addAll(aComplexEventChunk);
    }
    process(complexEventChunk);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Example 17 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class FirstPerEventOutputRateLimiter 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();
                state.counter++;
                if (state.counter == 1) {
                    outputEventChunk.add(event);
                } else if (state.counter == value) {
                    state.counter = 0;
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    outputEventChunk.reset();
    if (outputEventChunk.hasNext()) {
        sendToCallBacks(outputEventChunk);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Example 18 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class AggregationWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
    AggregationRateLimiterState 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);
                    if (event.getType() == ComplexEvent.Type.CURRENT) {
                        state.eventList.add(event);
                        for (Integer position : aggregateAttributePositionList) {
                            state.aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                        }
                    } else if (event.getType() == ComplexEvent.Type.EXPIRED) {
                        for (Iterator<ComplexEvent> iterator = state.eventList.iterator(); iterator.hasNext(); ) {
                            ComplexEvent complexEvent = iterator.next();
                            if (comparator.compare(event, complexEvent) == 0) {
                                iterator.remove();
                                for (Integer position : aggregateAttributePositionList) {
                                    state.aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                                }
                                break;
                            }
                        }
                    } else if (event.getType() == ComplexEvent.Type.RESET) {
                        state.eventList.clear();
                        state.aggregateAttributeValueMap.clear();
                    }
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    sendToCallBacks(outputEventChunks);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Iterator(java.util.Iterator) LinkedList(java.util.LinkedList)

Example 19 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class PerSnapshotOutputRateLimiter 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 if (event.getType() == ComplexEvent.Type.CURRENT) {
                    complexEventChunk.remove();
                    tryFlushEvents(outputEventChunks, event, state);
                    state.lastEvent = event;
                } else {
                    tryFlushEvents(outputEventChunks, event, state);
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    sendToCallBacks(outputEventChunks);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) LinkedList(java.util.LinkedList)

Example 20 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class WindowedPerSnapshotOutputRateLimiter 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 instanceof GroupedComplexEvent) {
                    event = ((GroupedComplexEvent) event).getComplexEvent();
                }
                if (event.getType() == ComplexEvent.Type.TIMER) {
                    tryFlushEvents(outputEventChunks, event, state);
                } else if (event.getType() == ComplexEvent.Type.CURRENT) {
                    complexEventChunk.remove();
                    tryFlushEvents(outputEventChunks, event, state);
                    state.eventList.add(event);
                } else if (event.getType() == ComplexEvent.Type.EXPIRED) {
                    tryFlushEvents(outputEventChunks, event, state);
                    for (Iterator<ComplexEvent> iterator = state.eventList.iterator(); iterator.hasNext(); ) {
                        ComplexEvent currentEvent = iterator.next();
                        if (comparator.compare(currentEvent, event) == 0) {
                            iterator.remove();
                            break;
                        }
                    }
                } else if (event.getType() == ComplexEvent.Type.RESET) {
                    tryFlushEvents(outputEventChunks, event, state);
                    state.eventList.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)

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