Search in sources :

Example 6 with ComplexEventChunk

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

the class ProcessStreamReceiver method receive.

@Override
public void receive(Event[] events) {
    StreamEvent firstEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertEvent(events[0], firstEvent);
    StreamEvent currentEvent = firstEvent;
    for (int i = 1, eventsLength = events.length; i < eventsLength; i++) {
        StreamEvent nextEvent = streamEventPool.borrowEvent();
        streamEventConverter.convertEvent(events[i], nextEvent);
        currentEvent.setNext(nextEvent);
        currentEvent = nextEvent;
    }
    if (siddhiDebugger != null) {
        siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, firstEvent);
    }
    process(new ComplexEventChunk<StreamEvent>(firstEvent, currentEvent, this.batchProcessingAllowed));
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 7 with ComplexEventChunk

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

the class ProcessStreamReceiver method receive.

@Override
public void receive(Event event, boolean endOfBatch) {
    StreamEvent borrowedEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertEvent(event, borrowedEvent);
    ComplexEventChunk<StreamEvent> streamEventChunk = null;
    synchronized (this) {
        batchingStreamEventChunk.add(borrowedEvent);
        if (endOfBatch) {
            streamEventChunk = batchingStreamEventChunk;
            batchingStreamEventChunk = new ComplexEventChunk<StreamEvent>(this.batchProcessingAllowed);
        }
    }
    if (streamEventChunk != null) {
        if (siddhiDebugger != null) {
            siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, streamEventChunk.getFirst());
        }
        process(streamEventChunk);
    }
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 8 with ComplexEventChunk

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

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.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 9 with ComplexEventChunk

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

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.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 10 with ComplexEventChunk

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

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.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)72 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)69 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)44 ArrayList (java.util.ArrayList)30 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)26 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)19 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)17 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)13 Map (java.util.Map)12 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)8 HashMap (java.util.HashMap)6 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)5 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)4 Collection (java.util.Collection)3 Event (org.wso2.siddhi.core.event.Event)3 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)3 Table (org.wso2.siddhi.core.table.Table)3 Iterator (java.util.Iterator)2 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2