use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method parameterMapToStateEvent.
private StateEvent parameterMapToStateEvent(Map<String, Object> parameterMap) {
StateEvent stateEvent = new StateEvent(2, parameterMap.size());
List<Object> outputData = new ArrayList<>();
List<Attribute> attributeList = inMemoryTable.getTableDefinition().getAttributeList();
for (int i = 0; i < attributeList.size(); i++) {
if (parameterMap.get(attributeList.get(i).getName()) != null) {
outputData.add(parameterMap.get(attributeList.get(i).getName()));
} else {
outputData.add(null);
}
}
StreamEvent event = storeEventPool.newInstance();
event.setOutputData(outputData.toArray());
stateEvent.addEvent(0, event);
return stateEvent;
}
use of io.siddhi.core.event.state.StateEvent 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();
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class StateMultiProcessStreamReceiver method processAndClear.
protected void processAndClear(int processIndex, StreamEvent streamEvent) {
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>();
ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent);
ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) nextProcessors[processIndex]).processAndReturn(currentStreamEventChunk);
if (eventChunk.getFirst() != null) {
retEventChunk.add(eventChunk.getFirst());
}
eventChunk.clear();
if (querySelector != null) {
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent));
}
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class JoinProcessor method joinEventBuilder.
/**
* Join the given two event streams.
*
* @param leftStream event left stream
* @param rightStream event right stream
* @param type complex event type
* @return StateEvent state event
*/
public StateEvent joinEventBuilder(StreamEvent leftStream, StreamEvent rightStream, ComplexEvent.Type type) {
StateEvent returnEvent = stateEventFactory.newInstance();
returnEvent.setEvent(0, leftStream);
returnEvent.setEvent(1, rightStream);
returnEvent.setType(type);
if (!leftJoinProcessor) {
returnEvent.setTimestamp(rightStream.getTimestamp());
} else {
returnEvent.setTimestamp(leftStream.getTimestamp());
}
return returnEvent;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
LogicalStreamPreState state = (LogicalStreamPreState) stateHolder.getState();
try {
if (!state.active) {
return new ComplexEventChunk<>();
}
ComplexEventChunk<StateEvent> event = super.processAndReturn(complexEventChunk);
StateEvent firstEvent = event.getFirst();
if (firstEvent != null) {
event = new ComplexEventChunk<>();
}
// Always return an empty event
return event;
} finally {
stateHolder.returnState(state);
}
}
Aggregations