use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class LengthBatchWindowProcessor method processFullBatchEvents.
private void processFullBatchEvents(StreamEvent streamEvent, ComplexEventChunk<StreamEvent> outputStreamEventChunk, long currentTime, WindowState state, StreamEventCloner streamEventCloner) {
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
state.currentEventQueue.add(clonedStreamEvent);
state.count++;
if (state.count == length) {
if (outputExpectsExpiredEvents && state.expiredEventQueue.getFirst() != null) {
while (state.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = state.expiredEventQueue.next();
expiredEvent.setTimestamp(currentTime);
}
outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
state.expiredEventQueue.clear();
}
if (state.resetEvent != null) {
state.resetEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(state.resetEvent);
state.resetEvent = null;
}
if (state.currentEventQueue.getFirst() != null) {
if (state.expiredEventQueue != null) {
state.currentEventQueue.reset();
while (state.currentEventQueue.hasNext()) {
StreamEvent currentEvent = state.currentEventQueue.next();
StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
state.expiredEventQueue.add(toExpireEvent);
}
}
outputStreamEventChunk.add(state.currentEventQueue.getFirst());
state.currentEventQueue.clear();
}
state.count = 0;
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class CronWindowProcessor method dispatchEvents.
public void dispatchEvents() {
Map<String, Map<String, WindowState>> allStates = stateHolder.getAllStates();
try {
for (Map.Entry<String, Map<String, WindowState>> allStatesEntry : allStates.entrySet()) {
for (Map.Entry<String, WindowState> stateEntry : allStatesEntry.getValue().entrySet()) {
WindowState windowState = stateEntry.getValue();
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>();
synchronized (windowState) {
if (windowState.currentEventQueue.getFirst() != null) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (windowState.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = windowState.expiredEventQueue.next();
expiredEvent.setTimestamp(currentTime);
}
if (windowState.expiredEventQueue.getFirst() != null) {
streamEventChunk.add(windowState.expiredEventQueue.getFirst());
}
windowState.expiredEventQueue.clear();
while (windowState.currentEventQueue.hasNext()) {
StreamEvent currentEvent = windowState.currentEventQueue.next();
StreamEvent toExpireEvent = streamEventClonerHolder.getStreamEventCloner().copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
windowState.expiredEventQueue.add(toExpireEvent);
}
streamEventChunk.add(windowState.currentEventQueue.getFirst());
windowState.currentEventQueue.clear();
}
}
SiddhiAppContext.startPartitionFlow(allStatesEntry.getKey());
SiddhiAppContext.startGroupByFlow(stateEntry.getKey());
try {
if (streamEventChunk.getFirst() != null) {
nextProcessor.process(streamEventChunk);
}
} finally {
SiddhiAppContext.stopGroupByFlow();
SiddhiAppContext.stopPartitionFlow();
}
}
}
} finally {
stateHolder.returnAllStates(allStates);
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
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.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
StreamEvent borrowEvent = streamEventFactory.newInstance();
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 io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class SlidingWindowProcessor method processEventChunk.
@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater, S state) {
streamEventChunk.reset();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEvent.setBeforeWindowData(null);
}
streamEventChunk.reset();
process(streamEventChunk, nextProcessor, streamEventCloner, state);
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class TimeLengthWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
state.expiredEventQueue.reset();
while (state.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = state.expiredEventQueue.next();
long timeDiff = expiredEvent.getTimestamp() - currentTime + timeInMilliSeconds;
if (timeDiff <= 0) {
state.expiredEventQueue.remove();
state.count--;
expiredEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(expiredEvent);
} else {
break;
}
}
state.expiredEventQueue.reset();
if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
if (state.count < length) {
state.count++;
state.expiredEventQueue.add(clonedEvent);
} else {
StreamEvent firstEvent = state.expiredEventQueue.poll();
if (firstEvent != null) {
firstEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(firstEvent);
state.expiredEventQueue.add(clonedEvent);
}
}
scheduler.notifyAt(clonedEvent.getTimestamp() + timeInMilliSeconds);
} else {
streamEventChunk.remove();
}
}
}
streamEventChunk.reset();
if (streamEventChunk.hasNext()) {
nextProcessor.process(streamEventChunk);
}
}
Aggregations