Search in sources :

Example 91 with StreamEvent

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

the class SingleProcessStreamReceiver method processAndClear.

protected void processAndClear(ComplexEventChunk<StreamEvent> streamEventChunk) {
    ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(false);
    synchronized (lockKey) {
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            streamEventChunk.remove();
            stabilizeStates();
            currentStreamEventChunk.add(streamEvent);
            ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) next).processAndReturn(currentStreamEventChunk);
            if (eventChunk.getFirst() != null) {
                retEventChunk.add(eventChunk.getFirst());
            }
            eventChunk.clear();
            currentStreamEventChunk.clear();
        }
    }
    while (retEventChunk.hasNext()) {
        StateEvent stateEvent = retEventChunk.next();
        retEventChunk.remove();
        querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, false));
    }
}
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)

Example 92 with StreamEvent

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

the class JoinProcessor method process.

/**
 * Process the handed StreamEvent.
 *
 * @param complexEventChunk event chunk to be processed
 */
@Override
public void process(ComplexEventChunk complexEventChunk) {
    if (trigger) {
        ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(true);
        StateEvent joinStateEvent = new StateEvent(2, 0);
        StreamEvent nextEvent = (StreamEvent) complexEventChunk.getFirst();
        complexEventChunk.clear();
        while (nextEvent != null) {
            StreamEvent streamEvent = nextEvent;
            nextEvent = streamEvent.getNext();
            streamEvent.setNext(null);
            joinLockWrapper.lock();
            try {
                ComplexEvent.Type eventType = streamEvent.getType();
                if (eventType == ComplexEvent.Type.TIMER) {
                    continue;
                } else if (eventType == ComplexEvent.Type.RESET) {
                    if (!leftJoinProcessor) {
                        returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
                    } else {
                        returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
                    }
                } else {
                    joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
                    StreamEvent foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
                    joinStateEvent.setEvent(matchingStreamIndex, null);
                    if (foundStreamEvent == null) {
                        if (outerJoinProcessor && !leftJoinProcessor) {
                            returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
                        } else if (outerJoinProcessor && leftJoinProcessor) {
                            returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
                        }
                    } else {
                        while (foundStreamEvent != null) {
                            StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
                            foundStreamEvent.setNext(null);
                            if (!leftJoinProcessor) {
                                returnEventChunk.add(joinEventBuilder(foundStreamEvent, streamEvent, eventType));
                            } else {
                                returnEventChunk.add(joinEventBuilder(streamEvent, foundStreamEvent, eventType));
                            }
                            foundStreamEvent = nextFoundStreamEvent;
                        }
                    }
                }
            } finally {
                joinLockWrapper.unlock();
            }
            if (returnEventChunk.getFirst() != null) {
                selector.process(returnEventChunk);
                returnEventChunk.clear();
            }
        }
    } else {
        if (preJoinProcessor) {
            joinLockWrapper.lock();
            try {
                nextProcessor.process(complexEventChunk);
            } finally {
                joinLockWrapper.unlock();
            }
        }
    }
}
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 93 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent 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 94 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent 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 95 with StreamEvent

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

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(org.ballerinalang.siddhi.core.event.ComplexEvent) ArrayList(java.util.ArrayList) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) Event(org.ballerinalang.siddhi.core.event.Event)

Aggregations

StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)117 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)41 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)40 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)19 Test (org.testng.annotations.Test)18 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)17 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)16 Event (org.ballerinalang.siddhi.core.event.Event)15 ArrayList (java.util.ArrayList)11 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)8 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)8 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)7 ConversionStreamEventChunk (org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)5 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)5