use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class ExternalTimeWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
synchronized (state) {
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
long currentTime = (Long) timeStampVariableExpressionExecutor.execute(streamEvent);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
// reset expiredEventQueue to make sure all of the expired events get removed,
// otherwise lastReturned.next will always return null and here while check is always false
state.expiredEventQueue.reset();
while (state.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = state.expiredEventQueue.next();
long expiredEventTime = (Long) timeStampVariableExpressionExecutor.execute(expiredEvent);
long timeDiff = expiredEventTime - currentTime + timeToKeep;
if (timeDiff <= 0) {
state.expiredEventQueue.remove();
expiredEvent.setTimestamp(currentTime);
streamEventChunk.insertBeforeCurrent(expiredEvent);
} else {
state.expiredEventQueue.reset();
break;
}
}
if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
state.expiredEventQueue.add(clonedEvent);
}
state.expiredEventQueue.reset();
}
}
nextProcessor.process(streamEventChunk);
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class FrequentWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
synchronized (this) {
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEvent != null) {
StreamEvent next = streamEvent.getNext();
streamEvent.setNext(null);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
String key = generateKey(streamEvent);
StreamEvent oldEvent = state.map.put(key, clonedEvent);
if (oldEvent != null) {
state.countMap.put(key, state.countMap.get(key) + 1);
streamEventChunk.add(streamEvent);
} else {
// This is a new event
if (state.map.size() > mostFrequentCount) {
List<String> keys = new ArrayList<String>(state.countMap.keySet());
for (int i = 0; i < mostFrequentCount; i++) {
int count = state.countMap.get(keys.get(i)) - 1;
if (count == 0) {
state.countMap.remove(keys.get(i));
StreamEvent expiredEvent = state.map.remove(keys.get(i));
expiredEvent.setTimestamp(currentTime);
streamEventChunk.add(expiredEvent);
} else {
state.countMap.put(keys.get(i), count);
}
}
// now we have tried to remove one for newly added item
if (state.map.size() > mostFrequentCount) {
// nothing happend by the attempt to remove one from the
// map so we are ignoring this event
state.map.remove(key);
// Here we do nothing just drop the message
} else {
// we got some space, event is already there in map object
// we just have to add it to the countMap
state.countMap.put(key, 1);
streamEventChunk.add(streamEvent);
}
} else {
state.countMap.put(generateKey(streamEvent), 1);
streamEventChunk.add(streamEvent);
}
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class GroupingWindowProcessor method processEventChunk.
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();
processEventChunk(streamEventChunk, nextProcessor, streamEventCloner, groupingKeyPopulator, state);
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class LengthBatchWindowProcessor method processStreamCurrentEvents.
private void processStreamCurrentEvents(StreamEvent streamEvent, ComplexEventChunk<StreamEvent> outputStreamEventChunk, long currentTime, WindowState state, StreamEventCloner streamEventCloner) {
state.count++;
if (state.count == length + 1) {
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;
}
state.count = 1;
}
outputStreamEventChunk.add(streamEvent);
if (state.expiredEventQueue != null) {
StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedStreamEvent.setType(StreamEvent.Type.EXPIRED);
state.expiredEventQueue.add(clonedStreamEvent);
}
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class LengthBatchWindowProcessor method processLengthZeroBatch.
private void processLengthZeroBatch(StreamEvent streamEvent, ComplexEventChunk<StreamEvent> outputStreamEventChunk, long currentTime, StreamEventCloner streamEventCloner) {
outputStreamEventChunk.add(streamEvent);
if (outputExpectsExpiredEvents) {
StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
expiredEvent.setType(ComplexEvent.Type.EXPIRED);
expiredEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(expiredEvent);
}
StreamEvent resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
resetEvent.setType(ComplexEvent.Type.RESET);
resetEvent.setTimestamp(currentTime);
outputStreamEventChunk.add(resetEvent);
}
Aggregations