use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class LengthBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
synchronized (this) {
ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<StreamEvent>(true);
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
currentEventChunk.add(clonedStreamEvent);
count++;
if (count == length) {
if (outputExpectsExpiredEvents) {
if (expiredEventChunk.getFirst() != null) {
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
outputStreamEventChunk.add(expiredEventChunk.getFirst());
}
}
if (expiredEventChunk != null) {
expiredEventChunk.clear();
}
if (currentEventChunk.getFirst() != null) {
// add reset event in front of current events
outputStreamEventChunk.add(resetEvent);
resetEvent = null;
if (expiredEventChunk != null) {
currentEventChunk.reset();
while (currentEventChunk.hasNext()) {
StreamEvent currentEvent = currentEventChunk.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
expiredEventChunk.add(toExpireEvent);
}
}
resetEvent = streamEventCloner.copyStreamEvent(currentEventChunk.getFirst());
resetEvent.setType(ComplexEvent.Type.RESET);
outputStreamEventChunk.add(currentEventChunk.getFirst());
}
currentEventChunk.clear();
count = 0;
if (outputStreamEventChunk.getFirst() != null) {
streamEventChunks.add(outputStreamEventChunk);
}
}
}
}
for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
nextProcessor.process(outputStreamEventChunk);
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class LengthWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
if (count < length) {
count++;
this.expiredEventChunk.add(clonedEvent);
} else {
StreamEvent firstEvent = this.expiredEventChunk.poll();
if (firstEvent != null) {
firstEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(firstEvent);
this.expiredEventChunk.add(clonedEvent);
} else {
StreamEvent resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
resetEvent.setType(ComplexEvent.Type.RESET);
// adding resetEvent and clonedEvent event to the streamEventChunk
// since we are using insertAfterCurrent(), the final order will be
// currentEvent > clonedEvent (or expiredEvent) > resetEvent
streamEventChunk.insertAfterCurrent(resetEvent);
streamEventChunk.insertAfterCurrent(clonedEvent);
// since we manually added resetEvent and clonedEvent in earlier step
// we have to skip those two events from getting processed in the next
// iteration. Hence, calling next() twice.
streamEventChunk.next();
streamEventChunk.next();
}
}
}
}
nextProcessor.process(streamEventChunk);
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class SortWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
while (streamEvent != null) {
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
StreamEvent next = streamEvent.getNext();
streamEvent.setNext(null);
streamEventChunk.add(streamEvent);
sortedWindow.add(clonedEvent);
if (sortedWindow.size() > lengthToKeep) {
Collections.sort(sortedWindow, eventComparator);
StreamEvent expiredEvent = sortedWindow.remove(sortedWindow.size() - 1);
expiredEvent.setTimestamp(currentTime);
streamEventChunk.add(expiredEvent);
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.
the class CronWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
currentEventChunk.add(clonedStreamEvent);
streamEventChunk.remove();
}
}
}
use of org.ballerinalang.siddhi.core.event.stream.StreamEvent 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);
}
}
Aggregations