Search in sources :

Example 16 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                LastEventHolder lastEventHolder = groupByKeyEvents.get(groupedComplexEvent.getGroupKey());
                if (lastEventHolder == null) {
                    lastEventHolder = new LastEventHolder();
                    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) {
                    groupByKeyEvents.clear();
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Example 17 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class FindStoreQueryRuntime method executeSelector.

private Event[] executeSelector(StreamEvent streamEvents, MetaStreamEvent.EventType eventType) {
    ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>(true);
    while (streamEvents != null) {
        StreamEvent streamEvent = streamEvents;
        streamEvents = streamEvents.getNext();
        streamEvent.setNext(null);
        StateEvent stateEvent = stateEventPool.borrowEvent();
        if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
            stateEvent.addEvent(1, streamEvent);
        } else {
            stateEvent.addEvent(0, streamEvent);
        }
        complexEventChunk.add(stateEvent);
    }
    ComplexEventChunk outputComplexEventChunk = selector.execute(complexEventChunk);
    if (outputComplexEventChunk != null) {
        List<Event> events = new ArrayList<>();
        outputComplexEventChunk.reset();
        while (outputComplexEventChunk.hasNext()) {
            ComplexEvent complexEvent = outputComplexEventChunk.next();
            events.add(new Event(complexEvent.getTimestamp(), complexEvent.getOutputData()));
        }
        return events.toArray(new Event[0]);
    } else {
        return null;
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList) Event(org.ballerinalang.siddhi.core.event.Event) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 18 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class MultiProcessStreamReceiver method receive.

@Override
public void receive(ComplexEvent complexEvent) {
    ComplexEvent aComplexEvent = complexEvent;
    while (aComplexEvent != null) {
        synchronized (this) {
            stabilizeStates();
            for (int anEventSequence : eventSequence) {
                StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
                StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
                StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
                aStreamEventConverter.convertComplexEvent(aComplexEvent, borrowedEvent);
                process(anEventSequence, borrowedEvent);
            }
        }
        aComplexEvent = aComplexEvent.getNext();
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool)

Example 19 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class AllAggregationPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                tryFlushEvents(outputEventChunks, event);
                if (event.getType() == ComplexEvent.Type.CURRENT) {
                    complexEventChunk.remove();
                    lastEvent = event;
                } else {
                    lastEvent = null;
                }
            }
        }
    }
    for (ComplexEventChunk<ComplexEvent> eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 20 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

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 org.ballerinalang.siddhi.core.event.ComplexEventChunk}
 */
@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        complexEventChunk.reset();
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else if (event.getType() == ComplexEvent.Type.CURRENT) {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                groupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Aggregations

ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)29 ArrayList (java.util.ArrayList)20 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)17 Event (org.ballerinalang.siddhi.core.event.Event)15 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)12 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)12 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)12 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)12 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)11 Test (org.testng.annotations.Test)11 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)7 AttributeProcessor (org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1