Search in sources :

Example 56 with ComplexEvent

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

the class QueryCallback method receiveStreamEvent.

public void receiveStreamEvent(ComplexEventChunk complexEventChunk) {
    Event[] currentEvents = null;
    Event[] expiredEvents = null;
    long timestamp = -1;
    List<Event> currentEventBuffer = new ArrayList<Event>();
    List<Event> expiredEventBuffer = new ArrayList<Event>();
    complexEventChunk.reset();
    while (complexEventChunk.hasNext()) {
        ComplexEvent streamEvent = complexEventChunk.next();
        if (streamEvent.getType() == StreamEvent.Type.EXPIRED) {
            bufferEvent(streamEvent, expiredEventBuffer);
        } else if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
            bufferEvent(streamEvent, currentEventBuffer);
        }
        timestamp = streamEvent.getTimestamp();
    }
    if (!currentEventBuffer.isEmpty()) {
        currentEvents = currentEventBuffer.toArray(new Event[currentEventBuffer.size()]);
        currentEventBuffer.clear();
    }
    if (!expiredEventBuffer.isEmpty()) {
        expiredEvents = expiredEventBuffer.toArray(new Event[expiredEventBuffer.size()]);
        expiredEventBuffer.clear();
    }
    send(timestamp, currentEvents, expiredEvents);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ArrayList(java.util.ArrayList) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Example 57 with ComplexEvent

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

the class AllPerEventOutputRateLimiter 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();
                if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEventChunk.remove();
                    state.allComplexEventChunk.add(event);
                    state.counter++;
                    if (state.counter == value) {
                        outputEventChunk.add(state.allComplexEventChunk.getFirst());
                        state.allComplexEventChunk.clear();
                        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 58 with ComplexEvent

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

the class LastPerEventOutputRateLimiter 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();
                if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                    if (++state.counter == value) {
                        complexEventChunk.remove();
                        outputEventChunk.add(event);
                        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 59 with ComplexEvent

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

the class AggregationWindowedPerSnapshotOutputRateLimiter method tryFlushEvents.

private void tryFlushEvents(List<ComplexEventChunk> outputEventChunks, ComplexEvent event, AggregationRateLimiterState state) {
    if (event.getTimestamp() >= state.scheduledTime) {
        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
        for (ComplexEvent originalComplexEvent : state.eventList) {
            ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent);
            for (Integer position : aggregateAttributePositionList) {
                eventCopy.getOutputData()[position] = state.aggregateAttributeValueMap.get(position);
            }
            outputEventChunk.add(eventCopy);
        }
        outputEventChunks.add(outputEventChunk);
        state.scheduledTime += value;
        scheduler.notifyAt(state.scheduledTime);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Example 60 with ComplexEvent

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

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

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