Search in sources :

Example 51 with ComplexEventChunk

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

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.isBatch());
        complexEventChunk.reset();
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            StreamEvent borrowEvent = streamEventPool.borrowEvent();
            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(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 52 with ComplexEventChunk

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

the class OutputCallback method constructMatchingStateEventChunk.

protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventPool stateEventPool, int matchingStreamIndex, StreamEventPool streamEventPool, StreamEventConverter streamEventConverter) {
    ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<StateEvent>(matchingComplexEventChunk.isBatch());
    while (matchingComplexEventChunk.hasNext()) {
        ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
        matchingComplexEventChunk.remove();
        StateEvent stateEvent = stateEventPool.borrowEvent();
        if (convertToStreamEvent) {
            StreamEvent borrowEvent = streamEventPool.borrowEvent();
            streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
            stateEvent.addEvent(matchingStreamIndex, borrowEvent);
        } else {
            stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
        }
        stateEventChunk.add(stateEvent);
    }
    return stateEventChunk;
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 53 with ComplexEventChunk

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

the class AllPerEventOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                complexEventChunk.remove();
                allComplexEventChunk.add(event);
                counter++;
                if (counter == value) {
                    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                    outputEventChunk.add(allComplexEventChunk.getFirst());
                    allComplexEventChunk.clear();
                    counter = 0;
                    outputEventChunks.add(outputEventChunk);
                }
            }
        }
    }
    for (ComplexEventChunk 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 54 with ComplexEventChunk

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

the class AggregationWindowedPerSnapshotOutputRateLimiter method tryFlushEvents.

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

Example 55 with ComplexEventChunk

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

the class AbsentLogicalPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>(false);
    if (!this.active) {
        return returnEventChunk;
    }
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    this.lock.lock();
    try {
        for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            if (withinStates.size() > 0) {
                if (isExpired(stateEvent, streamEvent.getTimestamp())) {
                    iterator.remove();
                    continue;
                }
            }
            if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
                iterator.remove();
                continue;
            }
            StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
            stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
            process(stateEvent);
            if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePerProcessor != null)) {
                // Reset to the original state after processing
                stateEvent.setEvent(stateId, currentStreamEvent);
            }
            if (this.thisLastProcessor.isEventReturned()) {
                this.thisLastProcessor.clearProcessedEvent();
                // The event has passed the filter condition. So remove from being an absent candidate.
                iterator.remove();
                if (stateType == StateInputStream.Type.SEQUENCE) {
                    partnerStatePreProcessor.pendingStateEventList.remove(stateEvent);
                }
            }
            if (!stateChanged) {
                switch(stateType) {
                    case PATTERN:
                        stateEvent.setEvent(stateId, currentStreamEvent);
                        break;
                    case SEQUENCE:
                        stateEvent.setEvent(stateId, currentStreamEvent);
                        iterator.remove();
                        break;
                }
            }
        }
    } finally {
        this.lock.unlock();
    }
    return returnEventChunk;
}
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)

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