use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
if (!this.active) {
// Every keyword is not used and already a pattern is processed
return;
}
boolean notProcessed = true;
long currentTime = complexEventChunk.getFirst().getTimestamp();
if (currentTime >= this.lastArrivalTime + waitingTime) {
synchronized (this) {
// If the process method is called, it is guaranteed that the waitingTime is passed
boolean initialize;
initialize = isStartState && newAndEveryStateEventList.isEmpty() && pendingStateEventList.isEmpty();
if (initialize && stateType == StateInputStream.Type.SEQUENCE && thisStatePostProcessor.nextEveryStatePerProcessor == null && this.lastArrivalTime > 0) {
// Sequence with no every but an event arrived
initialize = false;
}
if (initialize) {
// This is the first processor and no events received so far
StateEvent stateEvent = stateEventPool.borrowEvent();
addState(stateEvent);
} else if (stateType == StateInputStream.Type.SEQUENCE && !newAndEveryStateEventList.isEmpty()) {
this.resetState();
}
this.updateState();
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>(false);
Iterator<StateEvent> iterator = pendingStateEventList.iterator();
while (iterator.hasNext()) {
StateEvent event = iterator.next();
// Remove expired events based on within
if (withinStates.size() > 0) {
if (isExpired(event, currentTime)) {
iterator.remove();
continue;
}
}
// Collect the events that came before the waiting time
if (currentTime >= event.getTimestamp() + waitingTime) {
iterator.remove();
event.setTimestamp(currentTime);
retEventChunk.add(event);
}
}
notProcessed = retEventChunk.getFirst() == null;
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
sendEvent(stateEvent);
}
}
this.lastArrivalTime = 0;
}
if (thisStatePostProcessor.nextEveryStatePerProcessor == this || (notProcessed && isStartState)) {
// If every or (notProcessed and startState), schedule again
long nextBreak;
if (lastArrivalTime == 0) {
nextBreak = currentTime + waitingTime;
} else {
nextBreak = lastArrivalTime + waitingTime;
}
this.scheduler.notifyAt(nextBreak);
}
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbsentStreamPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
if (!this.active) {
return new ComplexEventChunk<>(false);
}
ComplexEventChunk<StateEvent> event = super.processAndReturn(complexEventChunk);
StateEvent firstEvent = event.getFirst();
if (firstEvent != null) {
event = new ComplexEventChunk<>(false);
}
// Always return an empty event
return event;
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class CountPostStateProcessor method process.
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
int streamEvents = 1;
while (streamEvent.getNext() != null) {
streamEvents++;
streamEvent = streamEvent.getNext();
}
((CountPreStateProcessor) thisStatePreProcessor).successCondition();
stateEvent.setTimestamp(streamEvent.getTimestamp());
if (streamEvents >= minCount) {
if (thisStatePreProcessor.stateType == StateInputStream.Type.SEQUENCE) {
if (nextStatePerProcessor != null) {
nextStatePerProcessor.addState(stateEvent);
}
if (streamEvents != maxCount) {
thisStatePreProcessor.addState(stateEvent);
}
} else if (streamEvents == minCount) {
processMinCountReached(stateEvent, complexEventChunk);
}
if (streamEvents == maxCount) {
thisStatePreProcessor.stateChanged();
}
}
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class CountPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 1)) {
continue;
}
if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 2)) {
continue;
}
stateEvent.addEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
successCondition = false;
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (stateChanged) {
iterator.remove();
}
if (!successCondition) {
switch(stateType) {
case PATTERN:
stateEvent.removeLastEvent(stateId);
break;
case SEQUENCE:
stateEvent.removeLastEvent(stateId);
iterator.remove();
break;
}
}
}
return returnEventChunk;
}
use of org.wso2.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class LogicalPreStateProcessor method addEveryState.
@Override
public void addEveryState(StateEvent stateEvent) {
StateEvent clonedEvent = stateEventCloner.copyStateEvent(stateEvent);
clonedEvent.setEvent(stateId, null);
newAndEveryStateEventList.add(clonedEvent);
if (partnerStatePreProcessor != null) {
clonedEvent.setEvent(partnerStatePreProcessor.stateId, null);
partnerStatePreProcessor.newAndEveryStateEventList.add(clonedEvent);
}
}
Aggregations