Search in sources :

Example 41 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IncrementalExecutor method execute.

@Override
public synchronized void execute(ComplexEventChunk streamEventChunk) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Event Chunk received by " + this.duration + " incremental executor: " + streamEventChunk.toString());
    }
    streamEventChunk.reset();
    while (streamEventChunk.hasNext()) {
        StreamEvent streamEvent = (StreamEvent) streamEventChunk.next();
        streamEventChunk.remove();
        ExecutorState executorState = stateHolder.getState();
        try {
            long timestamp = getTimestamp(streamEvent, executorState);
            long startTime = executorState.startTimeOfAggregates;
            executorState.startTimeOfAggregates = IncrementalTimeConverterUtil.getStartTimeOfAggregates(timestamp, duration, timeZone);
            if (timestamp >= executorState.nextEmitTime) {
                executorState.nextEmitTime = IncrementalTimeConverterUtil.getNextEmitTime(timestamp, duration, timeZone);
                dispatchAggregateEvents(executorState.startTimeOfAggregates);
                sendTimerEvent(executorState);
            }
            if (streamEvent.getType() == ComplexEvent.Type.CURRENT) {
                processAggregates(streamEvent, executorState);
            }
        } finally {
            stateHolder.returnState(executorState);
        }
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 42 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class OutOfOrderEventsDataAggregator method aggregateData.

public ComplexEventChunk<StreamEvent> aggregateData(ComplexEventChunk<StreamEvent> retrievedData) {
    Set<String> groupByKeys = new HashSet<>();
    while (retrievedData.hasNext()) {
        StreamEvent streamEvent = retrievedData.next();
        String groupByKey = groupByKeyGenerator.constructEventKey(streamEvent);
        groupByKeys.add(groupByKey);
        SiddhiAppContext.startGroupByFlow(groupByKey);
        synchronized (this) {
            ValueState state = (ValueState) valueStateHolder.getState();
            try {
                boolean shouldUpdate = true;
                if (shouldUpdateTimestamp != null) {
                    shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(streamEvent), state);
                }
                for (int i = 0; i < baseExecutors.size(); i++) {
                    // keeping timestamp value location as null
                    ExpressionExecutor expressionExecutor = baseExecutors.get(i);
                    if (shouldUpdate) {
                        state.setValue(expressionExecutor.execute(streamEvent), i + 1);
                    } else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
                        state.setValue(expressionExecutor.execute(streamEvent), i + 1);
                    }
                }
            } finally {
                valueStateHolder.returnState(state);
                SiddhiAppContext.stopGroupByFlow();
            }
        }
    }
    // clean all executors
    for (String groupByKey : groupByKeys) {
        SiddhiAppContext.startGroupByFlow(groupByKey);
        try {
            for (ExpressionExecutor expressionExecutor : baseExecutors) {
                expressionExecutor.execute(resetEvent);
            }
        } finally {
            SiddhiAppContext.stopGroupByFlow();
        }
    }
    return createEventChunkFromAggregatedData();
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) HashSet(java.util.HashSet)

Example 43 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class PersistedIncrementalExecutor method sendTimerEvent.

private void sendTimerEvent(ExecutorState executorState) {
    if (getNextExecutor() != null) {
        StreamEvent timerEvent = streamEventFactory.newInstance();
        timerEvent.setType(ComplexEvent.Type.TIMER);
        timerEvent.setTimestamp(executorState.startTimeOfAggregates);
        ComplexEventChunk<StreamEvent> timerStreamEventChunk = new ComplexEventChunk<>();
        timerStreamEventChunk.add(timerEvent);
        next.execute(timerStreamEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 44 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class BaseIncrementalValueStore method process.

public synchronized void process(Map<String, StreamEvent> groupedByEvents) {
    for (Map.Entry<String, StreamEvent> eventEntry : groupedByEvents.entrySet()) {
        synchronized (this) {
            SiddhiAppContext.startGroupByFlow(eventEntry.getKey() + "-" + eventEntry.getValue().getTimestamp());
            ValueState state = valueStateHolder.getState();
            try {
                boolean shouldUpdate = true;
                if (shouldUpdateTimestamp != null) {
                    shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(eventEntry.getValue()), state);
                }
                for (int i = 0; i < expressionExecutors.size(); i++) {
                    // keeping timestamp value location as null
                    ExpressionExecutor expressionExecutor = expressionExecutors.get(i);
                    if (shouldUpdate) {
                        state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
                    } else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
                        state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
                    }
                }
                setProcessed(true);
            } finally {
                valueStateHolder.returnState(state);
                SiddhiAppContext.stopGroupByFlow();
            }
        }
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class BaseIncrementalValueStore method getGroupedByEvents.

public synchronized Map<String, StreamEvent> getGroupedByEvents() {
    Map<String, StreamEvent> groupedByEvents = new HashMap<>();
    if (isProcessed()) {
        Map<String, ValueState> baseIncrementalValueStoreMap = this.valueStateHolder.getAllGroupByStates();
        try {
            for (Map.Entry<String, ValueState> state : baseIncrementalValueStoreMap.entrySet()) {
                StreamEvent streamEvent = streamEventFactory.newInstance();
                long timestamp = getTimestamp();
                streamEvent.setTimestamp(timestamp);
                state.getValue().setValue(timestamp, 0);
                streamEvent.setOutputData(state.getValue().values);
                groupedByEvents.put(state.getKey(), streamEvent);
            }
        } finally {
            this.valueStateHolder.returnGroupByStates(baseIncrementalValueStoreMap);
        }
    }
    return groupedByEvents;
}
Also used : HashMap(java.util.HashMap) StreamEvent(io.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StreamEvent (io.siddhi.core.event.stream.StreamEvent)203 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)92 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)74 StateEvent (io.siddhi.core.event.state.StateEvent)52 ComplexEvent (io.siddhi.core.event.ComplexEvent)33 ArrayList (java.util.ArrayList)27 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)26 Map (java.util.Map)24 Event (io.siddhi.core.event.Event)23 Test (org.testng.annotations.Test)23 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)20 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Attribute (io.siddhi.query.api.definition.Attribute)17 HashMap (java.util.HashMap)17 Operation (io.siddhi.core.event.stream.Operation)12 LinkedList (java.util.LinkedList)12 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)11 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)10 HashSet (java.util.HashSet)10 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)8