use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method processStreamEventAsStream.
private void processStreamEventAsStream(WindowState state, long currentTime, StreamEvent streamEvent, StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> streamEventChunks, boolean output) {
StateEvent stateEventCurrent = new StateEvent(3, 0);
stateEventCurrent.setEvent(0, streamEvent);
if (state.expiredEventQueue.getFirst() != null) {
stateEventCurrent.setEvent(1, state.expiredEventQueue.getFirst());
} else {
stateEventCurrent.setEvent(1, streamEvent);
}
stateEventCurrent.setEvent(2, streamEvent);
ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<>();
if (output && state.currentEventQueue.getFirst() != null) {
outputStreamEventChunk.add(state.currentEventQueue.getFirst());
state.currentEventQueue.clear();
}
if (!(Boolean) expressionExecutor.execute(stateEventCurrent)) {
stateEventCurrent.setType(ComplexEvent.Type.RESET);
expressionExecutor.execute(stateEventCurrent);
stateEventCurrent.setType(ComplexEvent.Type.CURRENT);
expressionExecutor.execute(stateEventCurrent);
state.expiredEventQueue.reset();
if (state.expiredEventQueue.getFirst() != null) {
while (state.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = state.expiredEventQueue.next();
expiredEvent.setTimestamp(currentTime);
}
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
if (includeTriggeringEventExecutor != null && (Boolean) includeTriggeringEventExecutor.execute(streamEvent) || includeTriggeringEvent) {
outputStreamEventChunk.add(streamEvent);
if (output) {
outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
expiredEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(expiredEvent);
} else {
state.currentEventQueue.add(state.expiredEventQueue.getFirst());
state.currentEventQueue.add(expiredEvent);
}
state.expiredEventQueue.clear();
} else {
if (output) {
outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
} else {
state.currentEventQueue.add(state.expiredEventQueue.getFirst());
}
outputStreamEventChunk.add(streamEvent);
state.expiredEventQueue.clear();
state.expiredEventQueue.add(expiredEvent);
}
} else if (output) {
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
expiredEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(expiredEvent);
streamEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(streamEvent);
} else {
state.currentEventQueue.add(streamEvent);
}
if (output) {
streamEventChunks.add(outputStreamEventChunk);
}
} else {
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
state.expiredEventQueue.add(expiredEvent);
if (output) {
outputStreamEventChunk.add(streamEvent);
streamEventChunks.add(outputStreamEventChunk);
}
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method processStreamEvent.
private void processStreamEvent(WindowState state, long currentTime, StreamEvent streamEvent, StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> streamEventChunks) {
StateEvent stateEventCurrent = new StateEvent(3, 0);
stateEventCurrent.setEvent(0, streamEvent);
if (state.currentEventQueue.getFirst() != null) {
stateEventCurrent.setEvent(1, state.currentEventQueue.getFirst());
} else {
stateEventCurrent.setEvent(1, streamEvent);
}
stateEventCurrent.setEvent(2, streamEvent);
if (!(Boolean) expressionExecutor.execute(stateEventCurrent)) {
stateEventCurrent.setType(ComplexEvent.Type.RESET);
expressionExecutor.execute(stateEventCurrent);
stateEventCurrent.setType(ComplexEvent.Type.CURRENT);
expressionExecutor.execute(stateEventCurrent);
ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<>();
state.expiredEventQueue.reset();
if (state.expiredEventQueue.getFirst() != null) {
while (state.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = state.expiredEventQueue.next();
expiredEvent.setTimestamp(currentTime);
}
outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
state.expiredEventQueue.clear();
}
if (state.currentEventQueue.getFirst() != null) {
while (state.currentEventQueue.hasNext()) {
StreamEvent currentEvent = state.currentEventQueue.next();
currentEvent.setTimestamp(currentTime);
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(currentEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
state.expiredEventQueue.add(expiredEvent);
}
outputStreamEventChunk.add(state.currentEventQueue.getFirst());
state.currentEventQueue.clear();
if (includeTriggeringEventExecutor != null && (Boolean) includeTriggeringEventExecutor.execute(streamEvent) || includeTriggeringEvent) {
outputStreamEventChunk.add(streamEvent);
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setTimestamp(currentTime);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
state.expiredEventQueue.add(expiredEvent);
} else {
state.currentEventQueue.add(streamEvent);
}
} else {
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
expiredEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(expiredEvent);
streamEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(streamEvent);
}
streamEventChunks.add(outputStreamEventChunk);
} else {
state.currentEventQueue.add(streamEvent);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class IncrementalDataPurger method createStreamEvent.
/**
* creating stream event method
*/
private StateEvent createStreamEvent(Object[] values, Long timestamp) {
StreamEvent streamEvent = streamEventFactory.newInstance();
streamEvent.setTimestamp(timestamp);
streamEvent.setOutputData(values);
StateEvent stateEvent = new StateEvent(2, 1);
stateEvent.addEvent(0, streamEvent);
return stateEvent;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class SnapshotableEventQueueOperator method delete.
@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
deletingEventChunk.reset();
while (deletingEventChunk.hasNext()) {
StateEvent deletingEvent = deletingEventChunk.next();
try {
storeEventQueue.reset();
while (storeEventQueue.hasNext()) {
StreamEvent storeEvent = storeEventQueue.next();
deletingEvent.setEvent(storeEventPosition, storeEvent);
if ((Boolean) expressionExecutor.execute(deletingEvent)) {
storeEventQueue.remove();
}
}
} finally {
deletingEvent.setEvent(storeEventPosition, null);
}
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class TestStoreForCacheMiss method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(int outputDataSize, StateEventFactory stateEventFactory) {
StreamEvent streamEvent = new StreamEvent(outputDataSize, 0, outputDataSize);
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
stateEvent.addEvent(0, streamEvent);
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
Aggregations