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