use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class SnapshotableEventQueueOperator method find.
@Override
public StreamEvent find(StateEvent matchingEvent, Object storeEvents, StreamEventCloner storeEventCloner) {
SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<>();
storeEventQueue.reset();
while (storeEventQueue.hasNext()) {
StreamEvent storeEvent = storeEventQueue.next();
matchingEvent.setEvent(storeEventPosition, storeEvent);
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
}
matchingEvent.setEvent(storeEventPosition, null);
}
return returnEventChunk.getFirst();
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class IndexOperator method update.
@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet) {
updatingEventChunk.reset();
while (updatingEventChunk.hasNext()) {
StateEvent updatingEvent = updatingEventChunk.next();
StreamEvent streamEvents = collectionExecutor.find(updatingEvent, (IndexedEventHolder) storeEvents, null);
if (streamEvents != null) {
ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>();
foundEventChunk.add(streamEvents);
update((IndexedEventHolder) storeEvents, compiledUpdateSet, updatingEvent, foundEventChunk);
}
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class IndexOperator method tryUpdate.
@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
updatingOrAddingEventChunk.reset();
while (updatingOrAddingEventChunk.hasNext()) {
StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
StreamEvent streamEvents = collectionExecutor.find(overwritingOrAddingEvent, (IndexedEventHolder) storeEvents, null);
ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>();
foundEventChunk.add(streamEvents);
if (foundEventChunk.getFirst() != null) {
// for cases when indexed attribute is also updated but that not changed
// to reduce number of passes needed to update the events
update((IndexedEventHolder) storeEvents, compiledUpdateSet, overwritingOrAddingEvent, foundEventChunk);
} else {
updatingOrAddingEventChunk.remove();
failedEventChunk.add(overwritingOrAddingEvent);
}
}
return failedEventChunk;
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class CacheTable method addAndTrimUptoMaxSize.
public void addAndTrimUptoMaxSize(ComplexEventChunk<StreamEvent> addingEventChunk) {
ComplexEventChunk<StreamEvent> addingEventChunkForCache = new ComplexEventChunk<>();
addingEventChunk.reset();
while (addingEventChunk.hasNext()) {
StreamEvent event = addingEventChunk.next();
addingEventChunkForCache.add((StreamEvent) generateEventWithRequiredFields(event, siddhiAppContext, cacheExpiryEnabled));
}
readWriteLock.writeLock().lock();
try {
super.add(addingEventChunkForCache);
if (this.size() > maxSize) {
this.deleteEntriesUsingCachePolicy(this.size() - maxSize);
}
} finally {
readWriteLock.writeLock().unlock();
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class BatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
ComplexEventChunk<StreamEvent> currentEventChunk = new ComplexEventChunk<StreamEvent>();
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
if (outputExpectsExpiredEvents) {
if (state.expiredEventQueue.getFirst() != null) {
while (state.expiredEventQueue.hasNext()) {
state.expiredEventQueue.next().setTimestamp(currentTime);
}
currentEventChunk.add(state.expiredEventQueue.getFirst());
if (state.resetEvent != null) {
currentEventChunk.add(state.resetEvent);
state.resetEvent = null;
}
}
state.expiredEventQueue.clear();
}
// check whether the streamEventChunk has next event before add into output stream event chunk
ComplexEventChunk<StreamEvent> currentEventQueue = new ComplexEventChunk<>();
int count = 0;
if (streamEventChunk.hasNext()) {
do {
StreamEvent streamEvent = streamEventChunk.next();
StreamEvent clonedStreamEventToProcess = streamEventCloner.copyStreamEvent(streamEvent);
if (outputExpectsExpiredEvents) {
StreamEvent clonedStreamEventToExpire = streamEventCloner.copyStreamEvent(streamEvent);
clonedStreamEventToExpire.setType(StreamEvent.Type.EXPIRED);
state.expiredEventQueue.add(clonedStreamEventToExpire);
}
currentEventQueue.add(clonedStreamEventToProcess);
count++;
if (count == length) {
if (currentEventQueue.getFirst() != null) {
if (state.resetEvent != null) {
currentEventChunk.add(state.resetEvent);
}
state.resetEvent = streamEventCloner.copyStreamEvent(currentEventQueue.getFirst());
state.resetEvent.setType(ComplexEvent.Type.RESET);
currentEventChunk.add(currentEventQueue.getFirst());
}
count = 0;
currentEventQueue.clear();
if (currentEventChunk.getFirst() != null) {
streamEventChunks.add(currentEventChunk);
currentEventChunk = new ComplexEventChunk<StreamEvent>();
}
}
} while (streamEventChunk.hasNext());
if (currentEventQueue.getFirst() != null) {
if (state.resetEvent != null) {
currentEventChunk.add(state.resetEvent);
}
state.resetEvent = streamEventCloner.copyStreamEvent(currentEventQueue.getFirst());
state.resetEvent.setType(ComplexEvent.Type.RESET);
currentEventChunk.add(currentEventQueue.getFirst());
}
if (currentEventChunk.getFirst() != null) {
streamEventChunks.add(currentEventChunk);
}
}
}
for (ComplexEventChunk<StreamEvent> processStreamEventChunk : streamEventChunks) {
nextProcessor.process(processStreamEventChunk);
}
}
Aggregations