use of org.wso2.carbon.apimgt.core.models.Event in project siddhi by wso2.
the class StreamPostStateProcessor method process.
/**
* Process the handed StreamEvent
*
* @param complexEventChunk event chunk to be processed
*/
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
if (complexEventChunk.hasNext()) {
// one one event will be coming
StateEvent stateEvent = (StateEvent) complexEventChunk.next();
process(stateEvent, complexEventChunk);
}
complexEventChunk.clear();
}
use of org.wso2.carbon.apimgt.core.models.Event in project siddhi by wso2.
the class InsertIntoWindowCallback method send.
/**
* Add the event into the {@link Window}
*
* @param complexEventChunk the event to add
* @param noOfEvents number of events
*/
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
// If events are inserted directly from another window, expired events can arrive
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
}
}
window.add(complexEventChunk);
}
use of org.wso2.carbon.apimgt.core.models.Event in project siddhi by wso2.
the class QueryCallback method receiveStreamEvent.
public void receiveStreamEvent(ComplexEventChunk complexEventChunk) {
Event[] currentEvents = null;
Event[] expiredEvents = null;
long timestamp = -1;
List<Event> currentEventBuffer = new ArrayList<Event>();
List<Event> expiredEventBuffer = new ArrayList<Event>();
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent streamEvent = complexEventChunk.next();
if (streamEvent.getType() == StreamEvent.Type.EXPIRED) {
bufferEvent(streamEvent, expiredEventBuffer);
} else if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
bufferEvent(streamEvent, currentEventBuffer);
}
timestamp = streamEvent.getTimestamp();
}
if (!currentEventBuffer.isEmpty()) {
currentEvents = currentEventBuffer.toArray(new Event[currentEventBuffer.size()]);
currentEventBuffer.clear();
}
if (!expiredEventBuffer.isEmpty()) {
expiredEvents = expiredEventBuffer.toArray(new Event[expiredEventBuffer.size()]);
expiredEventBuffer.clear();
}
send(timestamp, currentEvents, expiredEvents);
}
use of org.wso2.carbon.apimgt.core.models.Event in project siddhi by wso2.
the class FrequentWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
long currentTime = siddhiAppContext.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 = map.put(key, clonedEvent);
if (oldEvent != null) {
countMap.put(key, countMap.get(key) + 1);
streamEventChunk.add(streamEvent);
} else {
// This is a new event
if (map.size() > mostFrequentCount) {
List<String> keys = new ArrayList<String>(countMap.keySet());
for (int i = 0; i < mostFrequentCount; i++) {
int count = countMap.get(keys.get(i)) - 1;
if (count == 0) {
countMap.remove(keys.get(i));
StreamEvent expiredEvent = map.remove(keys.get(i));
expiredEvent.setTimestamp(currentTime);
streamEventChunk.add(expiredEvent);
} else {
countMap.put(keys.get(i), count);
}
}
// now we have tried to remove one for newly added item
if (map.size() > mostFrequentCount) {
// nothing happend by the attempt to remove one from the
// map so we are ignoring this event
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
countMap.put(key, 1);
streamEventChunk.add(streamEvent);
}
} else {
countMap.put(generateKey(streamEvent), 1);
streamEventChunk.add(streamEvent);
}
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.carbon.apimgt.core.models.Event in project siddhi by wso2.
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);
}
}
Aggregations