Search in sources :

Example 11 with ComplexEventChunk

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

the class FirstGroupByPerTimeOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    complexEventChunk.reset();
    RateLimiterState state = stateHolder.getState();
    try {
        synchronized (state) {
            long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                complexEventChunk.remove();
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                Long outputTime = state.groupByOutputTime.get(groupedComplexEvent.getGroupKey());
                if (outputTime == null || outputTime + value <= currentTime) {
                    state.groupByOutputTime.put(groupedComplexEvent.getGroupKey(), currentTime);
                    outputEventChunk.add(groupedComplexEvent);
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    outputEventChunk.reset();
    if (outputEventChunk.hasNext()) {
        sendToCallBacks(outputEventChunk);
    }
}
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)

Example 12 with ComplexEventChunk

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

the class CronWindowProcessor method dispatchEvents.

public void dispatchEvents() {
    Map<String, Map<String, WindowState>> allStates = stateHolder.getAllStates();
    try {
        for (Map.Entry<String, Map<String, WindowState>> allStatesEntry : allStates.entrySet()) {
            for (Map.Entry<String, WindowState> stateEntry : allStatesEntry.getValue().entrySet()) {
                WindowState windowState = stateEntry.getValue();
                ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>();
                synchronized (windowState) {
                    if (windowState.currentEventQueue.getFirst() != null) {
                        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
                        while (windowState.expiredEventQueue.hasNext()) {
                            StreamEvent expiredEvent = windowState.expiredEventQueue.next();
                            expiredEvent.setTimestamp(currentTime);
                        }
                        if (windowState.expiredEventQueue.getFirst() != null) {
                            streamEventChunk.add(windowState.expiredEventQueue.getFirst());
                        }
                        windowState.expiredEventQueue.clear();
                        while (windowState.currentEventQueue.hasNext()) {
                            StreamEvent currentEvent = windowState.currentEventQueue.next();
                            StreamEvent toExpireEvent = streamEventClonerHolder.getStreamEventCloner().copyStreamEvent(currentEvent);
                            toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                            windowState.expiredEventQueue.add(toExpireEvent);
                        }
                        streamEventChunk.add(windowState.currentEventQueue.getFirst());
                        windowState.currentEventQueue.clear();
                    }
                }
                SiddhiAppContext.startPartitionFlow(allStatesEntry.getKey());
                SiddhiAppContext.startGroupByFlow(stateEntry.getKey());
                try {
                    if (streamEventChunk.getFirst() != null) {
                        nextProcessor.process(streamEventChunk);
                    }
                } finally {
                    SiddhiAppContext.stopGroupByFlow();
                    SiddhiAppContext.stopPartitionFlow();
                }
            }
        }
    } finally {
        stateHolder.returnAllStates(allStates);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map) JobDataMap(org.quartz.JobDataMap)

Example 13 with ComplexEventChunk

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

the class QuerySelector method orderEventChunk.

private void orderEventChunk(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk();
    List<ComplexEvent> eventList = new ArrayList<>();
    ComplexEvent.Type currentEventType = null;
    complexEventChunk.reset();
    if (complexEventChunk.getFirst() != null) {
        currentEventType = complexEventChunk.getFirst().getType();
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            complexEventChunk.remove();
            if (currentEventType == event.getType()) {
                eventList.add(event);
            } else {
                currentEventType = event.getType();
                eventList.sort(orderByEventComparator);
                for (ComplexEvent complexEvent : eventList) {
                    orderingComplexEventChunk.add(complexEvent);
                }
                eventList.clear();
                eventList.add(event);
            }
        }
        eventList.sort(orderByEventComparator);
        for (ComplexEvent complexEvent : eventList) {
            orderingComplexEventChunk.add(complexEvent);
        }
        complexEventChunk.clear();
        complexEventChunk.add(orderingComplexEventChunk.getFirst());
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 14 with ComplexEventChunk

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

the class QuerySelector method processGroupBy.

private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ComplexEventChunk<ComplexEvent> currentComplexEventChunk = new ComplexEventChunk<ComplexEvent>();
    synchronized (this) {
        int limitCount = 0;
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            switch(event.getType()) {
                case CURRENT:
                case EXPIRED:
                    eventPopulator.populateStateEvent(event);
                    String groupByKey = groupByKeyGenerator.constructEventKey(event);
                    SiddhiAppContext.startGroupByFlow(groupByKey);
                    try {
                        for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                            attributeProcessor.process(event);
                        }
                        if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                            if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
                                complexEventChunk.remove();
                                if (limit == SiddhiConstants.UNKNOWN_STATE) {
                                    currentComplexEventChunk.add(new GroupedComplexEvent(groupByKey, event));
                                } else {
                                    if (limitCount < limit) {
                                        currentComplexEventChunk.add(new GroupedComplexEvent(groupByKey, event));
                                        limitCount++;
                                    }
                                }
                            }
                        }
                    } finally {
                        SiddhiAppContext.stopGroupByFlow();
                    }
                    break;
                case TIMER:
                    break;
                case RESET:
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    break;
            }
        }
    }
    if (isOrderBy) {
        orderEventChunk(complexEventChunk);
    }
    if (offset != SiddhiConstants.UNKNOWN_STATE) {
        offsetEventChunk(complexEventChunk);
    }
    if (limit != SiddhiConstants.UNKNOWN_STATE) {
        limitEventChunk(complexEventChunk);
    }
    currentComplexEventChunk.reset();
    if (currentComplexEventChunk.hasNext()) {
        return currentComplexEventChunk;
    }
    return null;
}
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) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)

Example 15 with ComplexEventChunk

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

the class InsertIntoTableCallback method send.

@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
    if (getSiddhiDebugger() != null) {
        getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
    }
    if (convertToStreamEvent) {
        ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>();
        complexEventChunk.reset();
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            StreamEvent borrowEvent = streamEventFactory.newInstance();
            streamEventConverter.convertData(complexEvent.getTimestamp(), complexEvent.getOutputData(), complexEvent.getType(), borrowEvent);
            streamEventChunk.add(borrowEvent);
        }
        table.addEvents(streamEventChunk, noOfEvents);
    } else {
        table.addEvents((ComplexEventChunk<StreamEvent>) complexEventChunk, noOfEvents);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent)

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