use of org.ballerinalang.siddhi.core.event.stream.StreamEvent 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.stream.StreamEvent 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.stream.StreamEvent in project ballerina by ballerina-lang.
the class InsertIntoTableCallback method send.
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
if (convertToStreamEvent) {
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>(complexEventChunk.isBatch());
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
StreamEvent borrowEvent = streamEventPool.borrowEvent();
streamEventConverter.convertData(complexEvent.getTimestamp(), complexEvent.getOutputData(), complexEvent.getType(), borrowEvent);
streamEventChunk.add(borrowEvent);
}
table.addEvents(streamEventChunk, noOfEvents);
} else {
table.addEvents((ComplexEventChunk<StreamEvent>) complexEventChunk, noOfEvents);
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent 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.stream.StreamEvent in project ballerina by ballerina-lang.
the class QueryCallback method receiveStreamEvent.
public void receiveStreamEvent(ComplexEventChunk complexEventChunk) {
Event[] currentEvents = null;
Event[] expiredEvents = null;
long timestamp = -1;
List<Event> currentEventBuffer = new ArrayList<Event>();
List<Event> expiredEventBuffer = new ArrayList<Event>();
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent streamEvent = complexEventChunk.next();
if (streamEvent.getType() == StreamEvent.Type.EXPIRED) {
bufferEvent(streamEvent, expiredEventBuffer);
} else if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
bufferEvent(streamEvent, currentEventBuffer);
}
timestamp = streamEvent.getTimestamp();
}
if (!currentEventBuffer.isEmpty()) {
currentEvents = currentEventBuffer.toArray(new Event[currentEventBuffer.size()]);
currentEventBuffer.clear();
}
if (!expiredEventBuffer.isEmpty()) {
expiredEvents = expiredEventBuffer.toArray(new Event[expiredEventBuffer.size()]);
expiredEventBuffer.clear();
}
send(timestamp, currentEvents, expiredEvents);
}
Aggregations