Search in sources :

Example 41 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class AbstractQueryableRecordTable method connectAndLoadCache.

@Override
protected void connectAndLoadCache() throws ConnectionUnavailableException {
    connect();
    if (cacheEnabled) {
        ((CacheTable) cacheTable).deleteAll();
        StateEvent stateEventForCaching = new StateEvent(1, 0);
        StreamEvent preLoadedData;
        queryStoreWithoutCheckingCache.set(Boolean.TRUE);
        try {
            preLoadedData = query(stateEventForCaching, compiledConditionForCaching, compiledSelectionForCaching, outputAttributesForCaching);
        } finally {
            queryStoreWithoutCheckingCache.set(Boolean.FALSE);
        }
        if (preLoadedData != null) {
            ((CacheTable) cacheTable).addStreamEventUptoMaxSize(preLoadedData);
        }
        if (cacheExpiryEnabled) {
            siddhiAppContext.getScheduledExecutorService().scheduleAtFixedRate(new CacheExpirer(retentionPeriod, cacheTable, tableMap, this, siddhiAppContext).generateCacheExpirer(), 0, purgeInterval, TimeUnit.MILLISECONDS);
        }
    }
}
Also used : OnDemandQueryParser.generateMatchingMetaInfoHolderForCacheTable(io.siddhi.core.util.parser.OnDemandQueryParser.generateMatchingMetaInfoHolderForCacheTable) CacheTable(io.siddhi.core.table.CacheTable) OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent(io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent) CacheExpirer(io.siddhi.core.util.cache.CacheExpirer)

Example 42 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class InMemoryTable method reduceEventsForUpdateOrInsert.

protected ComplexEventChunk<StreamEvent> reduceEventsForUpdateOrInsert(AddingStreamEventExtractor addingStreamEventExtractor, InMemoryCompiledCondition inMemoryCompiledCondition, InMemoryCompiledUpdateSet compiledUpdateSet, ComplexEventChunk<StateEvent> failedEvents) {
    ComplexEventChunk<StreamEvent> toInsertEventChunk = new ComplexEventChunk<>();
    failedEvents.reset();
    while (failedEvents.hasNext()) {
        StateEvent failedEvent = failedEvents.next();
        boolean updated = false;
        toInsertEventChunk.reset();
        while (toInsertEventChunk.hasNext()) {
            StreamEvent toInsertEvent = toInsertEventChunk.next();
            failedEvent.setEvent(inMemoryCompiledCondition.getStoreEventIndex(), toInsertEvent);
            if ((Boolean) inMemoryCompiledCondition.getUpdateOrInsertExpressionExecutor().execute(failedEvent)) {
                for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                    toInsertEvent.setOutputData(entry.getValue().execute(failedEvent), entry.getKey());
                }
                updated = true;
            }
        }
        if (!updated) {
            toInsertEventChunk.add(addingStreamEventExtractor.getAddingStreamEvent(failedEvent));
        }
    }
    return toInsertEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class AbstractRecordTable method updateOrAdd.

@Override
public void updateOrAdd(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
    List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
    List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
    List<Object[]> addingRecords = new ArrayList<>();
    updateOrAddingEventChunk.reset();
    long timestamp = 0L;
    while (updateOrAddingEventChunk.hasNext()) {
        StateEvent stateEvent = updateOrAddingEventChunk.next();
        Map<String, Object> variableMap = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
            variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateConditionParameterMaps.add(variableMap);
        Map<String, Object> variableMapForUpdateSet = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
            variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateSetParameterMaps.add(variableMapForUpdateSet);
        addingRecords.add(stateEvent.getStreamEvent(0).getOutputData());
        timestamp = stateEvent.getTimestamp();
    }
    try {
        if (recordTableHandler != null) {
            recordTableHandler.updateOrAdd(timestamp, recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
        } else {
            updateOrAdd(recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
        }
    } catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
        onUpdateOrAddError(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor, e);
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) HashMap(java.util.HashMap) DatabaseRuntimeException(io.siddhi.core.exception.DatabaseRuntimeException) ArrayList(java.util.ArrayList) StateEvent(io.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 44 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class CollectionOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent updateOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            if (((Collection<StreamEvent>) storeEvents).size() > 0) {
                for (StreamEvent storeEvent : ((Collection<StreamEvent>) storeEvents)) {
                    updateOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                    if ((Boolean) expressionExecutor.execute(updateOrAddingEvent)) {
                        for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                            storeEvent.setOutputData(entry.getValue().execute(updateOrAddingEvent), entry.getKey());
                        }
                        updated = true;
                    }
                }
            }
            if (!updated) {
                updatingOrAddingEventChunk.remove();
                failedEventChunk.add(updateOrAddingEvent);
            }
        } finally {
            updateOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) Map(java.util.Map)

Example 45 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class EventChunkOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    ComplexEventChunk<StreamEvent> storeEventChunk = (ComplexEventChunk<StreamEvent>) storeEvents;
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            storeEventChunk.reset();
            while (storeEventChunk.hasNext()) {
                StreamEvent storeEvent = storeEventChunk.next();
                overwritingOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(overwritingOrAddingEvent)) {
                    for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                        storeEvent.setOutputData(entry.getValue().execute(overwritingOrAddingEvent), entry.getKey());
                    }
                    updated = true;
                }
            }
            if (!updated) {
                updatingOrAddingEventChunk.remove();
                failedEventChunk.add(overwritingOrAddingEvent);
            }
        } finally {
            overwritingOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) Map(java.util.Map)

Aggregations

StateEvent (io.siddhi.core.event.state.StateEvent)70 StreamEvent (io.siddhi.core.event.stream.StreamEvent)48 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)36 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)26 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)19 ComplexEvent (io.siddhi.core.event.ComplexEvent)13 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)11 Map (java.util.Map)10 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)6 ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)5 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)5 HashMap (java.util.HashMap)5 Attribute (io.siddhi.query.api.definition.Attribute)4 Event (io.siddhi.core.event.Event)3 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)3 DatabaseRuntimeException (io.siddhi.core.exception.DatabaseRuntimeException)3 OnDemandQueryRuntimeException (io.siddhi.core.exception.OnDemandQueryRuntimeException)3 OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent (io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent)3 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2