Search in sources :

Example 1 with Operator

use of io.siddhi.core.util.collection.operator.Operator in project siddhi by wso2.

the class CacheTable method updateOrAddAndTrimUptoMaxSize.

public void updateOrAddAndTrimUptoMaxSize(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor, int maxTableSize) {
    ComplexEventChunk<StateEvent> updateOrAddingEventChunkForCache = new ComplexEventChunk<>();
    updateOrAddingEventChunk.reset();
    while (updateOrAddingEventChunk.hasNext()) {
        StateEvent event = updateOrAddingEventChunk.next();
        updateOrAddingEventChunkForCache.add((StateEvent) generateEventWithRequiredFields(event, siddhiAppContext, cacheExpiryEnabled));
    }
    readWriteLock.writeLock().lock();
    TableState state = stateHolder.getState();
    try {
        InMemoryCompiledCondition inMemoryCompiledCondition = (InMemoryCompiledCondition) compiledCondition;
        ComplexEventChunk<StateEvent> failedEvents = ((Operator) inMemoryCompiledCondition.getOperatorCompiledCondition()).tryUpdate(updateOrAddingEventChunkForCache, state.getEventHolder(), (InMemoryCompiledUpdateSet) compiledUpdateSet, addingStreamEventExtractor);
        if (failedEvents != null && failedEvents.getFirst() != null) {
            state.getEventHolder().add(reduceEventsForUpdateOrInsert(addingStreamEventExtractor, inMemoryCompiledCondition, (InMemoryCompiledUpdateSet) compiledUpdateSet, failedEvents));
        }
        if (this.size() > maxSize) {
            this.deleteEntriesUsingCachePolicy(this.size() - maxSize);
        }
    } finally {
        stateHolder.returnState(state);
        readWriteLock.writeLock().unlock();
    }
}
Also used : Operator(io.siddhi.core.util.collection.operator.Operator) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Aggregations

ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)1 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)1 StateEvent (io.siddhi.core.event.state.StateEvent)1 Operator (io.siddhi.core.util.collection.operator.Operator)1