use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class FirstGroupByPerTimeOutputRateLimiter method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
complexEventChunk.reset();
RateLimiterState state = stateHolder.getState();
try {
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
Long outputTime = state.groupByOutputTime.get(groupedComplexEvent.getGroupKey());
if (outputTime == null || outputTime + value <= currentTime) {
state.groupByOutputTime.put(groupedComplexEvent.getGroupKey(), currentTime);
outputEventChunk.add(groupedComplexEvent);
}
}
}
} finally {
stateHolder.returnState(state);
}
outputEventChunk.reset();
if (outputEventChunk.hasNext()) {
sendToCallBacks(outputEventChunk);
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class CronWindowProcessor method dispatchEvents.
public void dispatchEvents() {
Map<String, Map<String, WindowState>> allStates = stateHolder.getAllStates();
try {
for (Map.Entry<String, Map<String, WindowState>> allStatesEntry : allStates.entrySet()) {
for (Map.Entry<String, WindowState> stateEntry : allStatesEntry.getValue().entrySet()) {
WindowState windowState = stateEntry.getValue();
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>();
synchronized (windowState) {
if (windowState.currentEventQueue.getFirst() != null) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (windowState.expiredEventQueue.hasNext()) {
StreamEvent expiredEvent = windowState.expiredEventQueue.next();
expiredEvent.setTimestamp(currentTime);
}
if (windowState.expiredEventQueue.getFirst() != null) {
streamEventChunk.add(windowState.expiredEventQueue.getFirst());
}
windowState.expiredEventQueue.clear();
while (windowState.currentEventQueue.hasNext()) {
StreamEvent currentEvent = windowState.currentEventQueue.next();
StreamEvent toExpireEvent = streamEventClonerHolder.getStreamEventCloner().copyStreamEvent(currentEvent);
toExpireEvent.setType(StreamEvent.Type.EXPIRED);
windowState.expiredEventQueue.add(toExpireEvent);
}
streamEventChunk.add(windowState.currentEventQueue.getFirst());
windowState.currentEventQueue.clear();
}
}
SiddhiAppContext.startPartitionFlow(allStatesEntry.getKey());
SiddhiAppContext.startGroupByFlow(stateEntry.getKey());
try {
if (streamEventChunk.getFirst() != null) {
nextProcessor.process(streamEventChunk);
}
} finally {
SiddhiAppContext.stopGroupByFlow();
SiddhiAppContext.stopPartitionFlow();
}
}
}
} finally {
stateHolder.returnAllStates(allStates);
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class QuerySelector method orderEventChunk.
private void orderEventChunk(ComplexEventChunk complexEventChunk) {
ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk();
List<ComplexEvent> eventList = new ArrayList<>();
ComplexEvent.Type currentEventType = null;
complexEventChunk.reset();
if (complexEventChunk.getFirst() != null) {
currentEventType = complexEventChunk.getFirst().getType();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
if (currentEventType == event.getType()) {
eventList.add(event);
} else {
currentEventType = event.getType();
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
eventList.clear();
eventList.add(event);
}
}
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
complexEventChunk.clear();
complexEventChunk.add(orderingComplexEventChunk.getFirst());
}
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class QuerySelector method processGroupBy.
private ComplexEventChunk<ComplexEvent> processGroupBy(ComplexEventChunk complexEventChunk) {
complexEventChunk.reset();
ComplexEventChunk<ComplexEvent> currentComplexEventChunk = new ComplexEventChunk<ComplexEvent>();
synchronized (this) {
int limitCount = 0;
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
switch(event.getType()) {
case CURRENT:
case EXPIRED:
eventPopulator.populateStateEvent(event);
String groupByKey = groupByKeyGenerator.constructEventKey(event);
SiddhiAppContext.startGroupByFlow(groupByKey);
try {
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
complexEventChunk.remove();
if (limit == SiddhiConstants.UNKNOWN_STATE) {
currentComplexEventChunk.add(new GroupedComplexEvent(groupByKey, event));
} else {
if (limitCount < limit) {
currentComplexEventChunk.add(new GroupedComplexEvent(groupByKey, event));
limitCount++;
}
}
}
}
} finally {
SiddhiAppContext.stopGroupByFlow();
}
break;
case TIMER:
break;
case RESET:
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
attributeProcessor.process(event);
}
break;
}
}
}
if (isOrderBy) {
orderEventChunk(complexEventChunk);
}
if (offset != SiddhiConstants.UNKNOWN_STATE) {
offsetEventChunk(complexEventChunk);
}
if (limit != SiddhiConstants.UNKNOWN_STATE) {
limitEventChunk(complexEventChunk);
}
currentComplexEventChunk.reset();
if (currentComplexEventChunk.hasNext()) {
return currentComplexEventChunk;
}
return null;
}
use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.
the class InsertIntoTableCallback method send.
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
if (convertToStreamEvent) {
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<StreamEvent>();
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
StreamEvent borrowEvent = streamEventFactory.newInstance();
streamEventConverter.convertData(complexEvent.getTimestamp(), complexEvent.getOutputData(), complexEvent.getType(), borrowEvent);
streamEventChunk.add(borrowEvent);
}
table.addEvents(streamEventChunk, noOfEvents);
} else {
table.addEvents((ComplexEventChunk<StreamEvent>) complexEventChunk, noOfEvents);
}
}
Aggregations