Search in sources :

Example 16 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class IncrementalExecutor method sendTimerEvent.

private void sendTimerEvent(String timeZone) {
    if (getNextExecutor() != null) {
        StreamEvent timerEvent = streamEventPool.borrowEvent();
        timerEvent.setType(ComplexEvent.Type.TIMER);
        timerEvent.setTimestamp(IncrementalTimeConverterUtil.getPreviousStartTime(startTimeOfAggregates, this.duration, timeZone));
        ComplexEventChunk<StreamEvent> timerStreamEventChunk = new ComplexEventChunk<>(true);
        timerStreamEventChunk.add(timerEvent);
        next.execute(timerStreamEventChunk);
    }
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 17 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class TimeLengthWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    this.siddhiAppContext = siddhiAppContext;
    expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
    if (attributeExpressionExecutors.length == 2) {
        length = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else {
                throw new SiddhiAppValidationException("TimeLength window's first parameter attribute should " + "be either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("TimeLength window should have constant parameter " + "attributes but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else {
        throw new SiddhiAppValidationException("TimeLength window should only have two parameters (<int> " + "windowTime,<int> windowLength), but found " + attributeExpressionExecutors.length + " input " + "attributes");
    }
}
Also used : StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) SiddhiAppValidationException(org.ballerinalang.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)

Example 18 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class TimeWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
            expiredEventChunk.reset();
            while (expiredEventChunk.hasNext()) {
                StreamEvent expiredEvent = expiredEventChunk.next();
                long timeDiff = expiredEvent.getTimestamp() - currentTime + timeInMilliSeconds;
                if (timeDiff <= 0) {
                    expiredEventChunk.remove();
                    expiredEvent.setTimestamp(currentTime);
                    streamEventChunk.insertBeforeCurrent(expiredEvent);
                } else {
                    break;
                }
            }
            if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
                StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
                clonedEvent.setType(StreamEvent.Type.EXPIRED);
                this.expiredEventChunk.add(clonedEvent);
                if (lastTimestamp < clonedEvent.getTimestamp()) {
                    scheduler.notifyAt(clonedEvent.getTimestamp() + timeInMilliSeconds);
                    lastTimestamp = clonedEvent.getTimestamp();
                }
            } else {
                streamEventChunk.remove();
            }
        }
        expiredEventChunk.reset();
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 19 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class AbstractQueryableRecordTable method query.

@Override
public StreamEvent query(StateEvent matchingEvent, CompiledCondition compiledCondition, CompiledSelection compiledSelection) throws ConnectionUnavailableException {
    RecordStoreCompiledSelection recordStoreCompiledSelection = ((RecordStoreCompiledSelection) compiledSelection);
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    Map<String, Object> parameterMap = new HashMap<>();
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
        parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledSelection.variableExpressionExecutorMap.entrySet()) {
        parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    Iterator<Object[]> records;
    if (recordTableHandler != null) {
        records = recordTableHandler.query(matchingEvent.getTimestamp(), parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
    } else {
        records = query(parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
    }
    ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
    if (records != null) {
        while (records.hasNext()) {
            Object[] record = records.next();
            StreamEvent streamEvent = storeEventPool.borrowEvent();
            System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
            streamEventComplexEventChunk.add(streamEvent);
        }
    }
    return streamEventComplexEventChunk.getFirst();
}
Also used : ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) HashMap(java.util.HashMap) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class AbstractRecordTable method find.

@Override
public StreamEvent find(CompiledCondition compiledCondition, StateEvent matchingEvent) throws ConnectionUnavailableException {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    Map<String, Object> findConditionParameterMap = new HashMap<>();
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
        findConditionParameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    Iterator<Object[]> records;
    if (recordTableHandler != null) {
        records = recordTableHandler.find(matchingEvent.getTimestamp(), findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
    } else {
        records = find(findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
    }
    ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
    if (records != null) {
        while (records.hasNext()) {
            Object[] record = records.next();
            StreamEvent streamEvent = storeEventPool.borrowEvent();
            System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
            streamEventComplexEventChunk.add(streamEvent);
        }
    }
    return streamEventComplexEventChunk.getFirst();
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) HashMap(java.util.HashMap) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)117 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)41 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)40 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)19 Test (org.testng.annotations.Test)18 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)17 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)16 Event (org.ballerinalang.siddhi.core.event.Event)15 ArrayList (java.util.ArrayList)11 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)8 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)8 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)7 ConversionStreamEventChunk (org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)5 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)5