use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class SingleProcessStreamReceiver method processAndClear.
protected void processAndClear(ComplexEventChunk<StreamEvent> streamEventChunk) {
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(false);
synchronized (lockKey) {
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
stabilizeStates();
currentStreamEventChunk.add(streamEvent);
ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) next).processAndReturn(currentStreamEventChunk);
if (eventChunk.getFirst() != null) {
retEventChunk.add(eventChunk.getFirst());
}
eventChunk.clear();
currentStreamEventChunk.clear();
}
}
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, false));
}
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class JoinProcessor method process.
/**
* Process the handed StreamEvent.
*
* @param complexEventChunk event chunk to be processed
*/
@Override
public void process(ComplexEventChunk complexEventChunk) {
if (trigger) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(true);
StateEvent joinStateEvent = new StateEvent(2, 0);
StreamEvent nextEvent = (StreamEvent) complexEventChunk.getFirst();
complexEventChunk.clear();
while (nextEvent != null) {
StreamEvent streamEvent = nextEvent;
nextEvent = streamEvent.getNext();
streamEvent.setNext(null);
joinLockWrapper.lock();
try {
ComplexEvent.Type eventType = streamEvent.getType();
if (eventType == ComplexEvent.Type.TIMER) {
continue;
} else if (eventType == ComplexEvent.Type.RESET) {
if (!leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
} else {
returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
}
} else {
joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
StreamEvent foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
joinStateEvent.setEvent(matchingStreamIndex, null);
if (foundStreamEvent == null) {
if (outerJoinProcessor && !leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
} else if (outerJoinProcessor && leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
}
} else {
while (foundStreamEvent != null) {
StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
foundStreamEvent.setNext(null);
if (!leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(foundStreamEvent, streamEvent, eventType));
} else {
returnEventChunk.add(joinEventBuilder(streamEvent, foundStreamEvent, eventType));
}
foundStreamEvent = nextFoundStreamEvent;
}
}
}
} finally {
joinLockWrapper.unlock();
}
if (returnEventChunk.getFirst() != null) {
selector.process(returnEventChunk);
returnEventChunk.clear();
}
}
} else {
if (preJoinProcessor) {
joinLockWrapper.lock();
try {
nextProcessor.process(complexEventChunk);
} finally {
joinLockWrapper.unlock();
}
}
}
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class OutputCallback method constructMatchingStateEventChunk.
protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventPool stateEventPool, int matchingStreamIndex, StreamEventPool streamEventPool, StreamEventConverter streamEventConverter) {
ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<StateEvent>(matchingComplexEventChunk.isBatch());
while (matchingComplexEventChunk.hasNext()) {
ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
matchingComplexEventChunk.remove();
StateEvent stateEvent = stateEventPool.borrowEvent();
if (convertToStreamEvent) {
StreamEvent borrowEvent = streamEventPool.borrowEvent();
streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
stateEvent.addEvent(matchingStreamIndex, borrowEvent);
} else {
stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
}
stateEventChunk.add(stateEvent);
}
return stateEventChunk;
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.
the class AbsentLogicalPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>(false);
if (!this.active) {
return returnEventChunk;
}
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
this.lock.lock();
try {
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 (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
iterator.remove();
continue;
}
StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePerProcessor != null)) {
// Reset to the original state after processing
stateEvent.setEvent(stateId, currentStreamEvent);
}
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
// The event has passed the filter condition. So remove from being an absent candidate.
iterator.remove();
if (stateType == StateInputStream.Type.SEQUENCE) {
partnerStatePreProcessor.pendingStateEventList.remove(stateEvent);
}
}
if (!stateChanged) {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, currentStreamEvent);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, currentStreamEvent);
iterator.remove();
break;
}
}
}
} finally {
this.lock.unlock();
}
return returnEventChunk;
}
use of org.ballerinalang.siddhi.core.event.state.StateEvent 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;
}
Aggregations