Search in sources :

Example 26 with StateEvent

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

the class EventChunkOperator method delete.

@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
    ComplexEventChunk<StreamEvent> storeEventChunk = (ComplexEventChunk<StreamEvent>) storeEvents;
    deletingEventChunk.reset();
    while (deletingEventChunk.hasNext()) {
        StateEvent deletingEvent = deletingEventChunk.next();
        try {
            storeEventChunk.reset();
            while (storeEventChunk.hasNext()) {
                StreamEvent storeEvent = storeEventChunk.next();
                deletingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(deletingEvent)) {
                    storeEventChunk.remove();
                }
            }
        } finally {
            deletingEvent.setEvent(storeEventPosition, null);
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 27 with StateEvent

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

the class OnDemandQueryRuntimeUtil method executeSelectorAndReturnChunk.

private static ComplexEventChunk executeSelectorAndReturnChunk(StateEventFactory stateEventFactory, StreamEvent streamEvent, StreamEvent storeEvents, int storeEventIndex, QuerySelector selector) {
    ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>();
    while (storeEvents != null) {
        StreamEvent storeEvent = storeEvents;
        storeEvents = storeEvents.getNext();
        storeEvent.setNext(null);
        StateEvent joinEvent = stateEventFactory.newInstance();
        if (streamEvent == null) {
            joinEvent.addEvent(storeEventIndex, storeEvent);
        } else {
            joinEvent.addEvent(0, streamEvent);
            joinEvent.addEvent(1, storeEvent);
        }
        complexEventChunk.add(joinEvent);
    }
    return selector.execute(complexEventChunk);
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 28 with StateEvent

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

the class AbstractQueryableRecordTable method handleCacheExpiry.

public void handleCacheExpiry(CompiledCondition cacheExpiryCompiledCondition, ComplexEventChunk<StateEvent> deleteEventChunk) {
    if (log.isDebugEnabled()) {
        log.debug(siddhiAppContext.getName() + ": CacheExpirer started");
    }
    StateEvent stateEventForCaching = new StateEvent(1, 0);
    StreamEvent loadedDataFromStore;
    readWriteLock.writeLock().lock();
    try {
        if (storeTableSize != -1 && storeSizeLastCheckedTime > siddhiAppContext.getTimestampGenerator().currentTime() - retentionPeriod * 10) {
            if (log.isDebugEnabled()) {
                log.debug(siddhiAppContext.getName() + ": checking size of store table");
            }
            try {
                if (storeTableSize <= maxCacheSize) {
                    AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.TRUE);
                    try {
                        if (cacheLastReloadTime < siddhiAppContext.getTimestampGenerator().currentTime() + retentionPeriod) {
                            loadedDataFromStore = query(stateEventForCaching, compiledConditionForCaching, compiledSelectionForCaching, outputAttributesForCaching);
                            clearCacheAndReload(loadedDataFromStore);
                            cacheLastReloadTime = siddhiAppContext.getTimestampGenerator().currentTime();
                        }
                    } finally {
                        AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.FALSE);
                    }
                } else {
                    cacheTable.delete(deleteEventChunk, cacheExpiryCompiledCondition);
                }
            } catch (ConnectionUnavailableException e) {
                throw new SiddhiAppRuntimeException(siddhiAppContext.getName() + ": " + e.getMessage());
            }
        } else {
            try {
                AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.TRUE);
                try {
                    loadedDataFromStore = query(stateEventForCaching, compiledConditionForCaching, compiledSelectionForCaching, outputAttributesForCaching);
                    storeTableSize = findEventChunkSize(loadedDataFromStore);
                    storeSizeLastCheckedTime = siddhiAppContext.getTimestampGenerator().currentTime();
                } finally {
                    AbstractQueryableRecordTable.queryStoreWithoutCheckingCache.set(Boolean.FALSE);
                }
                if (storeTableSize <= maxCacheSize) {
                    if (cacheLastReloadTime < siddhiAppContext.getTimestampGenerator().currentTime() + retentionPeriod) {
                        clearCacheAndReload(loadedDataFromStore);
                        cacheLastReloadTime = siddhiAppContext.getTimestampGenerator().currentTime();
                    }
                } else {
                    cacheTable.delete(deleteEventChunk, cacheExpiryCompiledCondition);
                }
            } catch (Exception e) {
                throw new SiddhiAppRuntimeException(siddhiAppContext.getName() + ": " + e.getMessage());
            }
        }
        if (log.isDebugEnabled()) {
            log.debug(siddhiAppContext.getName() + ": CacheExpirer ended");
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
Also used : OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent(io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 29 with StateEvent

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

the class CollectionOperator method delete.

@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
    if (((Collection<StreamEvent>) storeEvents).size() > 0) {
        deletingEventChunk.reset();
        while (deletingEventChunk.hasNext()) {
            StateEvent deletingEvent = deletingEventChunk.next();
            try {
                for (Iterator<StreamEvent> iterator = ((Collection<StreamEvent>) storeEvents).iterator(); iterator.hasNext(); ) {
                    StreamEvent storeEvent = iterator.next();
                    deletingEvent.setEvent(storeEventPosition, storeEvent);
                    if ((Boolean) expressionExecutor.execute(deletingEvent)) {
                        iterator.remove();
                    }
                }
            } finally {
                deletingEvent.setEvent(storeEventPosition, null);
            }
        }
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) Collection(java.util.Collection) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 30 with StateEvent

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

the class TestStoreContainingInMemoryTable method find.

@Override
protected RecordIterator<Object[]> find(Map<String, Object> findConditionParameterMap, CompiledCondition compiledCondition) throws ConnectionUnavailableException {
    if (findMatchingEvent == null) {
        findMatchingEvent = new StateEvent(1, 0);
    }
    try {
        StreamEvent outEvent = inMemoryTable.find(compiledCondition, findMatchingEvent);
        List<Object[]> objects = new LinkedList<>();
        if (outEvent != null) {
            while (outEvent.hasNext()) {
                objects.add(outEvent.getOutputData());
                outEvent = outEvent.getNext();
            }
            objects.add(outEvent.getOutputData());
        }
        return new TestStoreWithCacheIterator(objects.iterator());
    } finally {
        findMatchingEvent = null;
    }
}
Also used : 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) LinkedList(java.util.LinkedList)

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