use of org.wso2.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.
the class StreamFunctionProcessor method processEventChunk.
@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
while (streamEventChunk.hasNext()) {
ComplexEvent complexEvent = streamEventChunk.next();
Object[] outputData;
switch(attributeExpressionLength) {
case 0:
outputData = process((Object) null);
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
break;
case 1:
outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
break;
default:
Object[] inputData = new Object[attributeExpressionLength];
for (int i = 0; i < attributeExpressionLength; i++) {
inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
}
outputData = process(inputData);
complexEventPopulater.populateComplexEvent(complexEvent, outputData);
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.
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.wso2.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method flushToOutputChunk.
private void flushToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents) {
ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<StreamEvent>(true);
if (outputExpectsExpiredEvents) {
if (expiredEventChunk.getFirst() != null) {
// mark the timestamp for the expiredType event
expiredEventChunk.reset();
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
// add expired event to newEventChunk.
newEventChunk.add(expiredEventChunk.getFirst());
}
}
if (expiredEventChunk != null) {
expiredEventChunk.clear();
}
if (currentEventChunk.getFirst() != null) {
// add reset event in front of current events
resetEvent.setTimestamp(currentTime);
newEventChunk.add(resetEvent);
resetEvent = null;
// move to expired events
if (preserveCurrentEvents || storeExpiredEvents) {
currentEventChunk.reset();
while (currentEventChunk.hasNext()) {
StreamEvent currentEvent = currentEventChunk.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
expiredEventChunk.add(toExpireEvent);
}
}
// add current event chunk to next processor
newEventChunk.add(currentEventChunk.getFirst());
}
currentEventChunk.clear();
if (newEventChunk.getFirst() != null) {
complexEventChunks.add(newEventChunk);
}
}
use of org.wso2.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method cloneAppend.
private void cloneAppend(StreamEventCloner streamEventCloner, StreamEvent currStreamEvent) {
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(currStreamEvent);
if (replaceTimestampWithBatchEndTime) {
clonedStreamEvent.setAttribute(endTime, timestampExpressionExecutor.getPosition());
}
currentEventChunk.add(clonedStreamEvent);
if (resetEvent == null) {
resetEvent = streamEventCloner.copyStreamEvent(currStreamEvent);
resetEvent.setType(ComplexEvent.Type.RESET);
}
}
use of org.wso2.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.
the class ExternalTimeWindowProcessor method process.
@Override
protected synchronized void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
long currentTime = (Long) timeStampVariableExpressionExecutor.execute(streamEvent);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
// reset expiredEventChunk to make sure all of the expired events get removed,
// otherwise lastReturned.next will always return null and here while check is always false
expiredEventChunk.reset();
while (expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = expiredEventChunk.next();
long expiredEventTime = (Long) timeStampVariableExpressionExecutor.execute(expiredEvent);
long timeDiff = expiredEventTime - currentTime + timeToKeep;
if (timeDiff <= 0) {
expiredEventChunk.remove();
expiredEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(expiredEvent);
} else {
expiredEventChunk.reset();
break;
}
}
if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
this.expiredEventChunk.add(clonedEvent);
}
expiredEventChunk.reset();
}
}
nextProcessor.process(streamEventChunk);
}
Aggregations