use of io.siddhi.core.event.ComplexEvent 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 io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AllPerEventOutputRateLimiter 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();
state.allComplexEventChunk.add(event);
state.counter++;
if (state.counter == value) {
outputEventChunk.add(state.allComplexEventChunk.getFirst());
state.allComplexEventChunk.clear();
state.counter = 0;
}
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class LastPerEventOutputRateLimiter 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) {
if (++state.counter == value) {
complexEventChunk.remove();
outputEventChunk.add(event);
state.counter = 0;
}
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AggregationWindowedPerSnapshotOutputRateLimiter method tryFlushEvents.
private void tryFlushEvents(List<ComplexEventChunk> outputEventChunks, ComplexEvent event, AggregationRateLimiterState state) {
if (event.getTimestamp() >= state.scheduledTime) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
for (ComplexEvent originalComplexEvent : state.eventList) {
ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent);
for (Integer position : aggregateAttributePositionList) {
eventCopy.getOutputData()[position] = state.aggregateAttributeValueMap.get(position);
}
outputEventChunk.add(eventCopy);
}
outputEventChunks.add(outputEventChunk);
state.scheduledTime += value;
scheduler.notifyAt(state.scheduledTime);
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AllAggregationPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event, state);
} else {
tryFlushEvents(outputEventChunks, event, state);
if (event.getType() == ComplexEvent.Type.CURRENT) {
complexEventChunk.remove();
state.lastEvent = event;
} else {
state.lastEvent = null;
}
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
Aggregations