Search in sources :

Example 26 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk 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 27 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk 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)

Example 28 with ComplexEventChunk

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

the class WindowedPerSnapshotOutputRateLimiter 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 instanceof GroupedComplexEvent) {
                event = ((GroupedComplexEvent) event).getComplexEvent();
            }
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else if (event.getType() == ComplexEvent.Type.CURRENT) {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                eventList.add(event);
            } else if (event.getType() == ComplexEvent.Type.EXPIRED) {
                tryFlushEvents(outputEventChunks, event);
                for (Iterator<ComplexEvent> iterator = 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);
                eventList.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 29 with ComplexEventChunk

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

the class LastGroupByPerTimeOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                if (event.getTimestamp() >= scheduledTime) {
                    if (allGroupByKeyEvents.size() != 0) {
                        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        for (ComplexEvent complexEvent : allGroupByKeyEvents.values()) {
                            outputEventChunk.add(complexEvent);
                        }
                        outputEventChunks.add(outputEventChunk);
                        allGroupByKeyEvents.clear();
                    }
                    scheduledTime = scheduledTime + value;
                    scheduler.notifyAt(scheduledTime);
                }
            } else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                complexEventChunk.remove();
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                allGroupByKeyEvents.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)

Example 30 with ComplexEventChunk

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

the class StateMultiProcessStreamReceiver method processAndClear.

protected void processAndClear(int processIndex, StreamEvent streamEvent) {
    ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(batchProcessingAllowed);
    ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent, batchProcessingAllowed);
    ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) nextProcessors[processIndex]).processAndReturn(currentStreamEventChunk);
    if (eventChunk.getFirst() != null) {
        retEventChunk.add(eventChunk.getFirst());
    }
    eventChunk.clear();
    if (querySelector != null) {
        while (retEventChunk.hasNext()) {
            StateEvent stateEvent = retEventChunk.next();
            retEventChunk.remove();
            querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, batchProcessingAllowed));
        }
    }
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Aggregations

ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)69 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)41 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)30 ArrayList (java.util.ArrayList)23 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)19 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)13 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)12 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)8 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)4 HashMap (java.util.HashMap)3 Table (org.ballerinalang.siddhi.core.table.Table)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Event (org.ballerinalang.siddhi.core.event.Event)2 SiddhiAppRuntimeException (org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)2 StreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2 TimePeriod (org.ballerinalang.siddhi.query.api.aggregation.TimePeriod)2 IncrementalDataAggregator (org.ballerinalang.siddhi.core.aggregation.IncrementalDataAggregator)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1