Search in sources :

Example 16 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class FirstPerEventOutputRateLimiter 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) {
                if (counter == 0) {
                    complexEventChunk.remove();
                    ComplexEventChunk<ComplexEvent> firstPerEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                    firstPerEventChunk.add(event);
                    outputEventChunks.add(firstPerEventChunk);
                }
                if (++counter == value) {
                    counter = 0;
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 17 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class LastGroupByPerEventOutputRateLimiter 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();
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
                if (++counter == value) {
                    counter = 0;
                    if (allGroupByKeyEvents.size() != 0) {
                        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        for (ComplexEvent complexEvent : allGroupByKeyEvents.values()) {
                            outputEventChunk.add(complexEvent);
                        }
                        allGroupByKeyEvents.clear();
                        outputEventChunks.add(outputEventChunk);
                    }
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Example 18 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        complexEventChunk.reset();
        String currentGroupByKey = null;
        Map<Integer, Object> currentAggregateAttributeValueMap = null;
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
                    currentGroupByKey = groupedComplexEvent.getGroupKey();
                    currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
                    if (currentAggregateAttributeValueMap == null) {
                        currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
                        groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
                    }
                }
                if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
                    eventList.add(groupedComplexEvent);
                    for (Integer position : aggregateAttributePositionList) {
                        currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                    }
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    for (Iterator<GroupedComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
                        GroupedComplexEvent currentEvent = iterator.next();
                        if (comparator.compare(currentEvent.getComplexEvent(), groupedComplexEvent.getComplexEvent()) == 0) {
                            iterator.remove();
                            for (Integer position : aggregateAttributePositionList) {
                                currentAggregateAttributeValueMap.put(position, groupedComplexEvent.getOutputData()[position]);
                            }
                            break;
                        }
                    }
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
                    eventList.clear();
                    groupByAggregateAttributeValueMap.clear();
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Example 19 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                LastEventHolder lastEventHolder = groupByKeyEvents.get(groupedComplexEvent.getGroupKey());
                if (lastEventHolder == null) {
                    lastEventHolder = new LastEventHolder();
                    groupByKeyEvents.put(groupedComplexEvent.getGroupKey(), lastEventHolder);
                }
                if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
                    lastEventHolder.addLastInEvent(groupedComplexEvent.getComplexEvent());
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    lastEventHolder.removeLastInEvent(groupedComplexEvent.getComplexEvent());
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
                    groupByKeyEvents.clear();
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Example 20 with Event

use of org.wso2.eventing.Event in project siddhi by wso2.

the class AllAggregationPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                tryFlushEvents(outputEventChunks, event);
                if (event.getType() == ComplexEvent.Type.CURRENT) {
                    complexEventChunk.remove();
                    lastEvent = event;
                } else {
                    lastEvent = null;
                }
            }
        }
    }
    for (ComplexEventChunk<ComplexEvent> eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1146 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1145 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1119 Event (org.wso2.siddhi.core.event.Event)855 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)587 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 ArrayList (java.util.ArrayList)68 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 HashMap (java.util.HashMap)14 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13