use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class FirstPerTimeOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
complexEventChunk.reset();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
if (event.getTimestamp() >= scheduledTime) {
if (firstEvent != null) {
firstEvent = null;
}
scheduledTime += value;
scheduler.notifyAt(scheduledTime);
}
} else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
if (firstEvent == null) {
complexEventChunk.remove();
firstEvent = event;
ComplexEventChunk<ComplexEvent> firstPerEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
firstPerEventChunk.add(event);
outputEventChunks.add(firstPerEventChunk);
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class LastPerTimeOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
complexEventChunk.reset();
synchronized (this) {
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
if (event.getTimestamp() >= scheduledTime) {
if (lastEvent != null) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
outputEventChunk.add(lastEvent);
lastEvent = null;
outputEventChunks.add(outputEventChunk);
}
scheduledTime = scheduledTime + value;
scheduler.notifyAt(scheduledTime);
}
} else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
complexEventChunk.remove();
lastEvent = event;
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.
the class CronWindowProcessor method dispatchEvents.
public void dispatchEvents() {
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>(false);
synchronized (this) {
if (currentEventChunk.getFirst() != null) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
if (expiredEventChunk.getFirst() != null) {
streamEventChunk.add(expiredEventChunk.getFirst());
}
expiredEventChunk.clear();
while (currentEventChunk.hasNext()) {
StreamEvent currentEvent = currentEventChunk.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
expiredEventChunk.add(toExpireEvent);
}
streamEventChunk.add(currentEventChunk.getFirst());
currentEventChunk.clear();
}
}
if (streamEventChunk.getFirst() != null) {
nextProcessor.process(streamEventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEventChunk 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.ComplexEventChunk 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();
}
}
}
}
Aggregations