use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class StreamPreStateProcessor 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 (withinStates.size() > 0) {
if (isExpired(stateEvent, streamEvent.getTimestamp())) {
iterator.remove();
continue;
}
}
// if (Math.abs(stateEvent.getTimestamp() - streamEvent.getTimestamp()) > withinStates) {
// iterator.remove();
// // switch (stateType) {
// // case PATTERN:
// // stateEvent.setEvent(stateId, null);
// // break;
// // case SEQUENCE:
// // stateEvent.setEvent(stateId, null);
// // iterator.remove();
// // if (thisStatePostProcessor.callbackPreStateProcessor != null) {
// // thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
// // }
// // break;
// // }
// continue;
// }
// }
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
returnEventChunk.add(stateEvent);
}
if (stateChanged) {
iterator.remove();
} else {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, null);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, null);
iterator.remove();
if (thisStatePostProcessor.callbackPreStateProcessor != null) {
thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
}
break;
}
}
}
return returnEventChunk;
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class CollectionOperator method tryUpdate.
@Override
public ComplexEventChunk<StreamEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
updatingOrAddingEventChunk.reset();
ComplexEventChunk<StreamEvent> failedEventChunk = new ComplexEventChunk<StreamEvent>(updatingOrAddingEventChunk.isBatch());
while (updatingOrAddingEventChunk.hasNext()) {
StateEvent updateOrAddingEvent = updatingOrAddingEventChunk.next();
try {
boolean updated = false;
if (((Collection<StreamEvent>) storeEvents).size() > 0) {
for (StreamEvent storeEvent : ((Collection<StreamEvent>) storeEvents)) {
updateOrAddingEvent.setEvent(storeEventPosition, storeEvent);
if ((Boolean) expressionExecutor.execute(updateOrAddingEvent)) {
for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
storeEvent.setOutputData(entry.getValue().execute(updateOrAddingEvent), entry.getKey());
}
updated = true;
}
}
}
if (!updated) {
failedEventChunk.add(addingStreamEventExtractor.getAddingStreamEvent(updateOrAddingEvent));
}
} finally {
updateOrAddingEvent.setEvent(storeEventPosition, null);
}
}
return failedEventChunk;
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class EventChunkOperator method contains.
@Override
public boolean contains(StateEvent matchingEvent, Object storeEvents) {
ComplexEventChunk<StreamEvent> storeEventChunk = (ComplexEventChunk<StreamEvent>) storeEvents;
try {
storeEventChunk.reset();
while (storeEventChunk.hasNext()) {
StreamEvent storeEvent = storeEventChunk.next();
matchingEvent.setEvent(storeEventPosition, storeEvent);
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
return true;
}
}
return false;
} finally {
matchingEvent.setEvent(storeEventPosition, null);
}
}
Aggregations