Search in sources :

Example 36 with ComplexEvent

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

the class JoinProcessor method execute.

private void execute(ComplexEventChunk complexEventChunk, List<ComplexEventChunk> returnEventChunkList) {
    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);
        ComplexEvent.Type eventType = streamEvent.getType();
        if (eventType == ComplexEvent.Type.TIMER) {
            continue;
        } else if (eventType == ComplexEvent.Type.RESET) {
            if (!leftJoinProcessor) {
                StateEvent outputStateEvent = joinEventBuilder(null, streamEvent, eventType);
                returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
            } else {
                StateEvent outputStateEvent = joinEventBuilder(streamEvent, null, eventType);
                returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
            }
        } else {
            joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
            StreamEvent foundStreamEvent;
            if (this.isOptimisedQuery) {
                try {
                    foundStreamEvent = query(joinStateEvent);
                } catch (SiddhiAppRuntimeException e) {
                    log.warn("Performing select clause in databases failed due to '" + e.getMessage() + " in query '" + queryName + "' within Siddhi app '" + siddhiAppName + "' hence reverting back to querying only with where clause.", e);
                    this.isOptimisedQuery = false;
                    foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
                }
            } else {
                foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
            }
            joinStateEvent.setEvent(matchingStreamIndex, null);
            if (foundStreamEvent == null) {
                if (outerJoinProcessor && !leftJoinProcessor) {
                    StateEvent outputStateEvent = joinEventBuilder(null, streamEvent, eventType);
                    returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
                } else if (outerJoinProcessor && leftJoinProcessor) {
                    StateEvent outputStateEvent = joinEventBuilder(streamEvent, null, eventType);
                    returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
                }
            } else if (!isOptimisedQuery) {
                ComplexEventChunk<ComplexEvent> returnEventChunk = new ComplexEventChunk<>();
                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;
                }
                returnEventChunkList.add(new SelectorTypeComplexEventChunk(returnEventChunk, false));
            } else {
                ComplexEventChunk<ComplexEvent> returnEventChunk = new ComplexEventChunk<>();
                while (foundStreamEvent != null) {
                    StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
                    StateEvent returnEvent = stateEventFactory.newInstance();
                    returnEvent.setType(eventType);
                    returnEvent.setTimestamp(foundStreamEvent.getTimestamp());
                    Object[] outputData = foundStreamEvent.getOutputData();
                    for (int i = 0; i < outputData.length; i++) {
                        Object data = outputData[i];
                        returnEvent.setOutputData(data, i);
                    }
                    returnEventChunk.add(returnEvent);
                    foundStreamEvent = nextFoundStreamEvent;
                }
                returnEventChunkList.add(new SelectorTypeComplexEventChunk(returnEventChunk, true));
            }
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) SelectorTypeComplexEventChunk(io.siddhi.core.query.selector.SelectorTypeComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) StateEvent(io.siddhi.core.event.state.StateEvent) SelectorTypeComplexEventChunk(io.siddhi.core.query.selector.SelectorTypeComplexEventChunk)

Example 37 with ComplexEvent

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

the class DeleteOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    stateEvent.addEvent(0, streamEvent);
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 38 with ComplexEvent

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

the class InsertOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    stateEvent.addEvent(0, streamEvent);
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 39 with ComplexEvent

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

the class InsertIntoWindowCallback method send.

/**
 * Add the event into the {@link Window}
 *
 * @param complexEventChunk the event to add
 * @param noOfEvents        number of events
 */
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
    if (getSiddhiDebugger() != null) {
        getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
    }
    // If events are inserted directly from another window, expired events can arrive
    complexEventChunk.reset();
    while (complexEventChunk.hasNext()) {
        ComplexEvent complexEvent = complexEventChunk.next();
        if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
            complexEvent.setType(ComplexEvent.Type.CURRENT);
        }
    }
    window.add(complexEventChunk);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent)

Example 40 with ComplexEvent

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

the class OutputCallback method constructMatchingStateEventChunk.

protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventFactory stateEventFactory, int matchingStreamIndex, StreamEventFactory streamEventFactory, StreamEventConverter streamEventConverter) {
    ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<>();
    while (matchingComplexEventChunk.hasNext()) {
        ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
        matchingComplexEventChunk.remove();
        StateEvent stateEvent = stateEventFactory.newInstance();
        if (convertToStreamEvent) {
            StreamEvent borrowEvent = streamEventFactory.newInstance();
            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(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Aggregations

ComplexEvent (io.siddhi.core.event.ComplexEvent)75 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)41 StreamEvent (io.siddhi.core.event.stream.StreamEvent)34 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)19 Event (io.siddhi.core.event.Event)16 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (io.siddhi.core.SiddhiManager)13 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)13 StreamCallback (io.siddhi.core.stream.output.StreamCallback)13 StateEvent (io.siddhi.core.event.state.StateEvent)12 InputHandler (io.siddhi.core.stream.input.InputHandler)12 Test (org.testng.annotations.Test)12 LinkedList (java.util.LinkedList)8 AttributeProcessor (io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 ArrayList (java.util.ArrayList)4 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 Map (java.util.Map)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)2 Iterator (java.util.Iterator)2 Operation (io.siddhi.core.event.stream.Operation)1