Search in sources :

Example 71 with ComplexEventChunk

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

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.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 72 with ComplexEventChunk

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

the class FirstGroupByPerEventOutputRateLimiter 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();
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                if (!groupByKeys.contains(groupedComplexEvent.getGroupKey())) {
                    groupByKeys.add(groupedComplexEvent.getGroupKey());
                    allComplexEventChunk.add(groupedComplexEvent.getComplexEvent());
                }
                if (++counter == value) {
                    if (allComplexEventChunk.getFirst() != null) {
                        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        outputEventChunk.add(allComplexEventChunk.getFirst());
                        outputEventChunks.add(outputEventChunk);
                        allComplexEventChunk.clear();
                        counter = 0;
                        groupByKeys.clear();
                    } else {
                        counter = 0;
                        groupByKeys.clear();
                    }
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Example 73 with ComplexEventChunk

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

the class CountPostStateProcessor method process.

protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    int streamEvents = 1;
    while (streamEvent.getNext() != null) {
        streamEvents++;
        streamEvent = streamEvent.getNext();
    }
    ((CountPreStateProcessor) thisStatePreProcessor).successCondition();
    stateEvent.setTimestamp(streamEvent.getTimestamp());
    if (streamEvents >= minCount) {
        if (thisStatePreProcessor.stateType == StateInputStream.Type.SEQUENCE) {
            if (nextStatePerProcessor != null) {
                nextStatePerProcessor.addState(stateEvent);
            }
            if (streamEvents != maxCount) {
                thisStatePreProcessor.addState(stateEvent);
            }
        } else if (streamEvents == minCount) {
            processMinCountReached(stateEvent, complexEventChunk);
        }
        if (streamEvents == maxCount) {
            thisStatePreProcessor.stateChanged();
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 74 with ComplexEventChunk

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

the class CountPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
        StateEvent stateEvent = iterator.next();
        if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 1)) {
            continue;
        }
        if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 2)) {
            continue;
        }
        stateEvent.addEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
        successCondition = false;
        process(stateEvent);
        if (this.thisLastProcessor.isEventReturned()) {
            this.thisLastProcessor.clearProcessedEvent();
            returnEventChunk.add(stateEvent);
        }
        if (stateChanged) {
            iterator.remove();
        }
        if (!successCondition) {
            switch(stateType) {
                case PATTERN:
                    stateEvent.removeLastEvent(stateId);
                    break;
                case SEQUENCE:
                    stateEvent.removeLastEvent(stateId);
                    iterator.remove();
                    break;
            }
        }
    }
    return returnEventChunk;
}
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)

Example 75 with ComplexEventChunk

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

the class LogicalPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    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;
        }
        stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
        process(stateEvent);
        if (this.thisLastProcessor.isEventReturned()) {
            this.thisLastProcessor.clearProcessedEvent();
            returnEventChunk.add(stateEvent);
        }
        if (stateChanged) {
            iterator.remove();
        } else {
            switch(stateType) {
                case PATTERN:
                    stateEvent.setEvent(stateId, null);
                    break;
                case SEQUENCE:
                    stateEvent.setEvent(stateId, null);
                    iterator.remove();
                    break;
            }
        }
    }
    return returnEventChunk;
}
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)

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