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();
}
}
Aggregations