Search in sources :

Example 61 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) {
    if (event != null) {
        StreamEvent borrowedEvent = streamEventPool.borrowEvent();
        streamEventConverter.convertEvent(event, borrowedEvent);
        if (siddhiDebugger != null) {
            siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, borrowedEvent);
        }
        process(new ComplexEventChunk<StreamEvent>(borrowedEvent, borrowedEvent, this.batchProcessingAllowed));
    }
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 62 with ComplexEventChunk

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

the class ProcessStreamReceiver method receive.

@Override
public void receive(ComplexEvent complexEvents) {
    if (siddhiDebugger != null) {
        siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, complexEvents);
    }
    StreamEvent firstEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertComplexEvent(complexEvents, firstEvent);
    StreamEvent currentEvent = firstEvent;
    complexEvents = complexEvents.getNext();
    while (complexEvents != null) {
        StreamEvent nextEvent = streamEventPool.borrowEvent();
        streamEventConverter.convertComplexEvent(complexEvents, nextEvent);
        currentEvent.setNext(nextEvent);
        currentEvent = nextEvent;
        complexEvents = complexEvents.getNext();
    }
    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 63 with ComplexEventChunk

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

the class ProcessStreamReceiver method receive.

@Override
public void receive(long timestamp, Object[] data) {
    StreamEvent borrowedEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertData(timestamp, data, borrowedEvent);
    // Send to debugger
    if (siddhiDebugger != null) {
        siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, borrowedEvent);
    }
    process(new ComplexEventChunk<StreamEvent>(borrowedEvent, borrowedEvent, this.batchProcessingAllowed));
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 64 with ComplexEventChunk

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

the class AbsentLogicalPostStateProcessor method process.

protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    // Mark the state changed
    thisStatePreProcessor.stateChanged();
    // Update the timestamp
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    // This is the notification to AbsentStreamPreStateProcessor that this event has been processed
    this.isEventReturned = true;
    ((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 65 with ComplexEventChunk

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

the class AbsentLogicalPreStateProcessor method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    if (!this.active) {
        return;
    }
    this.lock.lock();
    boolean notProcessed = true;
    try {
        long currentTime = complexEventChunk.getFirst().getTimestamp();
        if (currentTime >= this.lastArrivalTime + waitingTime) {
            ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>(false);
            Iterator<StateEvent> iterator;
            if (isStartState && stateType == StateInputStream.Type.SEQUENCE && newAndEveryStateEventList.isEmpty() && pendingStateEventList.isEmpty()) {
                StateEvent stateEvent = stateEventPool.borrowEvent();
                addState(stateEvent);
            } else if (stateType == StateInputStream.Type.SEQUENCE && !newAndEveryStateEventList.isEmpty()) {
                this.resetState();
            }
            this.updateState();
            iterator = pendingStateEventList.iterator();
            while (iterator.hasNext()) {
                StateEvent stateEvent = iterator.next();
                // Remove expired events based on within
                if (withinStates.size() > 0) {
                    if (isExpired(stateEvent, currentTime)) {
                        iterator.remove();
                        continue;
                    }
                }
                // Collect the events that came before the waiting time
                if (waitingTimePassed(currentTime, stateEvent)) {
                    iterator.remove();
                    if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) == null) {
                        // OR Partner not received
                        stateEvent.addEvent(stateId, streamEventPool.borrowEvent());
                        retEventChunk.add(stateEvent);
                    } else if (logicalType == LogicalStateElement.Type.AND && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
                        // AND partner received but didn't send out
                        retEventChunk.add(stateEvent);
                    } else if (logicalType == LogicalStateElement.Type.AND && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) == null) {
                        // AND partner didn't receive
                        // Let the partner to process or not
                        stateEvent.addEvent(stateId, streamEventPool.borrowEvent());
                    }
                }
            }
            retEventChunk.reset();
            notProcessed = retEventChunk.getFirst() == null;
            while (retEventChunk.hasNext()) {
                StateEvent stateEvent = retEventChunk.next();
                retEventChunk.remove();
                sendEvent(stateEvent);
            }
            this.lastArrivalTime = 0;
        }
    } finally {
        this.lock.unlock();
    }
    if (thisStatePostProcessor.nextEveryStatePerProcessor != null || (notProcessed && isStartState)) {
        // If every or (notProcessed and startState), schedule again
        long nextBreak;
        if (lastArrivalTime == 0) {
            nextBreak = siddhiAppContext.getTimestampGenerator().currentTime() + waitingTime;
        } else {
            nextBreak = lastArrivalTime + waitingTime;
        }
        this.scheduler.notifyAt(nextBreak);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) 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