Search in sources :

Example 21 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent 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 22 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent 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 23 with ComplexEvent

use of io.siddhi.core.event.ComplexEvent 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)

Example 24 with ComplexEvent

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

the class WindowedPerSnapshotOutputRateLimiter 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.eventList) {
            outputEventChunk.add(cloneComplexEvent(complexEvent));
        }
        outputEventChunks.add(outputEventChunk);
        state.scheduledTime = 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 25 with ComplexEvent

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

the class AllPerTimeOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    complexEventChunk.reset();
    RateLimiterState state = stateHolder.getState();
    try {
        synchronized (state) {
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                if (event.getType() == ComplexEvent.Type.TIMER) {
                    if (event.getTimestamp() >= state.scheduledTime) {
                        ComplexEvent first = state.allComplexEventChunk.getFirst();
                        if (first != null) {
                            state.allComplexEventChunk.clear();
                            outputEventChunk.add(first);
                        }
                        state.scheduledTime = state.scheduledTime + value;
                        scheduler.notifyAt(state.scheduledTime);
                    }
                } else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEventChunk.remove();
                    state.allComplexEventChunk.add(event);
                }
            }
        }
    } 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)

Aggregations

ComplexEvent (io.siddhi.core.event.ComplexEvent)75 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)41 StreamEvent (io.siddhi.core.event.stream.StreamEvent)34 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)19 Event (io.siddhi.core.event.Event)16 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (io.siddhi.core.SiddhiManager)13 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)13 StreamCallback (io.siddhi.core.stream.output.StreamCallback)13 StateEvent (io.siddhi.core.event.state.StateEvent)12 InputHandler (io.siddhi.core.stream.input.InputHandler)12 Test (org.testng.annotations.Test)12 LinkedList (java.util.LinkedList)8 AttributeProcessor (io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 ArrayList (java.util.ArrayList)4 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 Map (java.util.Map)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)2 Iterator (java.util.Iterator)2 Operation (io.siddhi.core.event.stream.Operation)1