use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
if (expressionStringExecutor == null && !init) {
MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEvent, metaStreamEvent });
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
init = true;
}
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
if (expressionStringExecutor != null) {
String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
if (!expressionStringNew.equals(expressionString)) {
expressionString = expressionStringNew;
processAllExpiredEvents(streamEventCloner, state, currentTime, streamEventChunks);
}
}
if (!streamInputEvents) {
processStreamEvent(state, currentTime, streamEvent, streamEventCloner, streamEventChunks);
} else {
processStreamEventAsStream(state, currentTime, streamEvent, streamEventCloner, streamEventChunks, true);
}
}
}
for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
nextProcessor.process(outputStreamEventChunk);
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method flushToOutputChunk.
private void flushToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents, WindowState state) {
ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<>();
if (outputExpectsExpiredEvents) {
if (state.expiredEventChunk.getFirst() != null) {
// mark the timestamp for the expiredType event
state.expiredEventChunk.reset();
while (state.expiredEventChunk.hasNext()) {
StreamEvent expiredEvent = state.expiredEventChunk.next();
expiredEvent.setTimestamp(currentTime);
}
// add expired event to newEventChunk.
newEventChunk.add(state.expiredEventChunk.getFirst());
}
}
if (state.expiredEventChunk != null) {
state.expiredEventChunk.clear();
}
if (state.currentEventChunk.getFirst() != null) {
// add reset event in front of current events
state.resetEvent.setTimestamp(currentTime);
newEventChunk.add(state.resetEvent);
state.resetEvent = null;
// move to expired events
if (preserveCurrentEvents || state.expiredEventChunk != null) {
state.currentEventChunk.reset();
while (state.currentEventChunk.hasNext()) {
StreamEvent currentEvent = state.currentEventChunk.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
state.expiredEventChunk.add(toExpireEvent);
}
}
// add current event chunk to next processor
newEventChunk.add(state.currentEventChunk.getFirst());
}
state.currentEventChunk.clear();
if (newEventChunk.getFirst() != null) {
complexEventChunks.add(newEventChunk);
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class LengthBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
synchronized (state) {
ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<>();
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
if (length == 0) {
processLengthZeroBatch(streamEvent, outputStreamEventChunk, currentTime, streamEventCloner);
} else {
if (state.resetEvent == null) {
state.resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
state.resetEvent.setType(ComplexEvent.Type.RESET);
}
if (isStreamCurrentEvents) {
processStreamCurrentEvents(streamEvent, outputStreamEventChunk, currentTime, state, streamEventCloner);
} else {
processFullBatchEvents(streamEvent, outputStreamEventChunk, currentTime, state, streamEventCloner);
}
}
if (outputStreamEventChunk.getFirst() != null) {
streamEventChunks.add(outputStreamEventChunk);
outputStreamEventChunk = new ComplexEventChunk<>();
}
}
}
for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
nextProcessor.process(outputStreamEventChunk);
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class AbstractStreamProcessor method process.
@Override
public void process(List<ComplexEventChunk> complexEventChunks) {
ComplexEventChunk complexEventChunk = new ComplexEventChunk();
for (ComplexEventChunk streamEventChunk : complexEventChunks) {
complexEventChunk.addAll(streamEventChunk);
}
process(complexEventChunk);
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class LastGroupByPerEventOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
complexEventChunk.remove();
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
state.allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
if (++state.counter == value) {
state.counter = 0;
if (state.allGroupByKeyEvents.size() != 0) {
for (ComplexEvent complexEvent : state.allGroupByKeyEvents.values()) {
outputEventChunk.add(complexEvent);
}
state.allGroupByKeyEvents.clear();
}
}
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
Aggregations