use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class OverwriteTableIndexOperatorForCache method tryUpdate.
@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
updatingOrAddingEventChunk.reset();
while (updatingOrAddingEventChunk.hasNext()) {
StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
((IndexedEventHolder) storeEvents).overwrite(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
}
return null;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class ExpressionWindowProcessor method processStreamEvent.
private void processStreamEvent(ComplexEventChunk<StreamEvent> streamEventChunk, WindowState state, long currentTime, StreamEvent streamEvent) {
state.expiredEventQueue.add(streamEvent);
StateEvent stateEventCurrent = new StateEvent(3, 0);
stateEventCurrent.setEvent(0, streamEvent);
stateEventCurrent.setEvent(1, state.expiredEventQueue.getFirst());
stateEventCurrent.setEvent(2, streamEvent);
if (!(Boolean) expressionExecutor.execute(stateEventCurrent)) {
state.expiredEventQueue.reset();
while (state.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = state.expiredEventQueue.next();
state.expiredEventQueue.remove();
streamEventChunk.insertBeforeCurrent(expiredEvent);
StateEvent stateEvent = new StateEvent(3, 0);
stateEvent.setEvent(0, expiredEvent);
StreamEvent firstEvent = state.expiredEventQueue.getFirst();
if (firstEvent == null) {
firstEvent = expiredEvent;
}
stateEvent.setEvent(1, firstEvent);
stateEvent.setEvent(2, streamEvent);
stateEvent.setType(ComplexEvent.Type.EXPIRED);
expiredEvent.setTimestamp(currentTime);
if ((Boolean) expressionExecutor.execute(stateEvent)) {
break;
}
}
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class StreamPreStateProcessor method expireEvents.
@Override
public void expireEvents(long timestamp) {
StreamPreState state = stateHolder.getState();
lock.lock();
try {
StateEvent expiredStateEvent = null;
for (Iterator<StateEvent> iterator = state.pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (isExpired(stateEvent, timestamp)) {
iterator.remove();
if (stateEvent.getType() != ComplexEvent.Type.EXPIRED) {
stateEvent.setType(ComplexEvent.Type.EXPIRED);
expiredStateEvent = stateEvent;
}
} else {
break;
}
}
for (Iterator<StateEvent> iterator = state.newAndEveryStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (isExpired(stateEvent, timestamp)) {
iterator.remove();
if (stateEvent.getType() != ComplexEvent.Type.EXPIRED) {
stateEvent.setType(ComplexEvent.Type.EXPIRED);
expiredStateEvent = stateEvent;
}
}
}
if (expiredStateEvent != null && withinEveryPreStateProcessor != null) {
withinEveryPreStateProcessor.addEveryState(expiredStateEvent);
withinEveryPreStateProcessor.updateState();
}
} finally {
lock.unlock();
stateHolder.returnState(state);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class StreamPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>();
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
StreamPreState state = stateHolder.getState();
lock.lock();
try {
for (Iterator<StateEvent> iterator = state.pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (state.stateChanged) {
iterator.remove();
} else {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, null);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, null);
if (removeOnNoStateChange(stateType)) {
iterator.remove();
}
if (thisStatePostProcessor.callbackPreStateProcessor != null) {
thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
}
break;
}
}
}
} finally {
lock.unlock();
stateHolder.returnState(state);
}
return returnEventChunk;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class StreamPreStateProcessor method init.
public void init() {
StreamPreState state = stateHolder.getState();
try {
if (isStartState && (!state.initialized || this.thisStatePostProcessor.nextEveryStatePreProcessor != null || (stateType == StateInputStream.Type.SEQUENCE && this.thisStatePostProcessor.nextStatePreProcessor instanceof AbsentPreStateProcessor))) {
// For 'every' sequence, the 'thisStatePostProcessor.nextEveryStatePreProcessor != null'
// check is not enough
StateEvent stateEvent = stateEventFactory.newInstance();
addState(stateEvent);
state.initialized = true;
}
} finally {
stateHolder.returnState(state);
}
}
Aggregations