use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AggregationWindowedPerSnapshotOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
AggregationRateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event, state);
} else {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event, state);
if (event.getType() == ComplexEvent.Type.CURRENT) {
state.eventList.add(event);
for (Integer position : aggregateAttributePositionList) {
state.aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
} else if (event.getType() == ComplexEvent.Type.EXPIRED) {
for (Iterator<ComplexEvent> iterator = state.eventList.iterator(); iterator.hasNext(); ) {
ComplexEvent complexEvent = iterator.next();
if (comparator.compare(event, complexEvent) == 0) {
iterator.remove();
for (Integer position : aggregateAttributePositionList) {
state.aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
}
break;
}
}
} else if (event.getType() == ComplexEvent.Type.RESET) {
state.eventList.clear();
state.aggregateAttributeValueMap.clear();
}
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class PerSnapshotOutputRateLimiter 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 if (event.getType() == ComplexEvent.Type.CURRENT) {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event, state);
state.lastEvent = event;
} else {
tryFlushEvents(outputEventChunks, event, state);
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class WindowedPerSnapshotOutputRateLimiter 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 instanceof GroupedComplexEvent) {
event = ((GroupedComplexEvent) event).getComplexEvent();
}
if (event.getType() == ComplexEvent.Type.TIMER) {
tryFlushEvents(outputEventChunks, event, state);
} else if (event.getType() == ComplexEvent.Type.CURRENT) {
complexEventChunk.remove();
tryFlushEvents(outputEventChunks, event, state);
state.eventList.add(event);
} else if (event.getType() == ComplexEvent.Type.EXPIRED) {
tryFlushEvents(outputEventChunks, event, state);
for (Iterator<ComplexEvent> iterator = state.eventList.iterator(); iterator.hasNext(); ) {
ComplexEvent currentEvent = iterator.next();
if (comparator.compare(currentEvent, event) == 0) {
iterator.remove();
break;
}
}
} else if (event.getType() == ComplexEvent.Type.RESET) {
tryFlushEvents(outputEventChunks, event, state);
state.eventList.clear();
}
}
}
} finally {
stateHolder.returnState(state);
}
sendToCallBacks(outputEventChunks);
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class WindowedPerSnapshotOutputRateLimiter method tryFlushEvents.
private void tryFlushEvents(List<ComplexEventChunk> outputEventChunks, ComplexEvent event, RateLimiterState state) {
if (event.getTimestamp() >= state.scheduledTime) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
for (ComplexEvent complexEvent : state.eventList) {
outputEventChunk.add(cloneComplexEvent(complexEvent));
}
outputEventChunks.add(outputEventChunk);
state.scheduledTime = state.scheduledTime + value;
scheduler.notifyAt(state.scheduledTime);
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class AllPerTimeOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
if (event.getType() == ComplexEvent.Type.TIMER) {
if (event.getTimestamp() >= state.scheduledTime) {
ComplexEvent first = state.allComplexEventChunk.getFirst();
if (first != null) {
state.allComplexEventChunk.clear();
outputEventChunk.add(first);
}
state.scheduledTime = state.scheduledTime + value;
scheduler.notifyAt(state.scheduledTime);
}
} else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
complexEventChunk.remove();
state.allComplexEventChunk.add(event);
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
Aggregations