use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class OutputCallback method constructMatchingStateEventChunk.
protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventPool stateEventPool, int matchingStreamIndex, StreamEventPool streamEventPool, StreamEventConverter streamEventConverter) {
ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<StateEvent>(matchingComplexEventChunk.isBatch());
while (matchingComplexEventChunk.hasNext()) {
ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
matchingComplexEventChunk.remove();
StateEvent stateEvent = stateEventPool.borrowEvent();
if (convertToStreamEvent) {
StreamEvent borrowEvent = streamEventPool.borrowEvent();
streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
stateEvent.addEvent(matchingStreamIndex, borrowEvent);
} else {
stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
}
stateEventChunk.add(stateEvent);
}
return stateEventChunk;
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class OutputRateLimiter method sendToCallBacks.
protected void sendToCallBacks(ComplexEventChunk complexEventChunk) {
if (siddhiAppContext.isStatsEnabled() && latencyTracker != null) {
latencyTracker.markOut();
}
if (lockWrapper != null) {
lockWrapper.unlock();
}
if (!queryCallbacks.isEmpty()) {
for (QueryCallback callback : queryCallbacks) {
callback.receiveStreamEvent(complexEventChunk);
}
}
if (outputCallback != null && complexEventChunk.getFirst() != null) {
complexEventChunk.reset();
int noOfEvents = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
noOfEvents++;
} else if (complexEvent.getType() == ComplexEvent.Type.RESET) {
complexEventChunk.remove();
} else {
noOfEvents++;
}
}
if (complexEventChunk.getFirst() != null) {
outputCallback.send(complexEventChunk, noOfEvents);
}
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class AllPerEventOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
synchronized (this) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
complexEventChunk.remove();
allComplexEventChunk.add(event);
counter++;
if (counter == value) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
outputEventChunk.add(allComplexEventChunk.getFirst());
allComplexEventChunk.clear();
counter = 0;
outputEventChunks.add(outputEventChunk);
}
}
}
}
for (ComplexEventChunk eventChunk : outputEventChunks) {
sendToCallBacks(eventChunk);
}
}
Aggregations