Search in sources :

Example 6 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event event, boolean endOfBatch) {
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    streamEventConverter.convertEvent(event, borrowedEvent);
    streamEventChunk.add(borrowedEvent);
    if (endOfBatch) {
        ComplexEvent complexEvent = streamEventChunk.getFirst();
        streamEventChunk.clear();
        receive(complexEvent);
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 7 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(ComplexEvent complexEvent) {
    if (partitionExecutors.size() == 0) {
        StreamEvent borrowedEvent = eventPool.borrowEvent();
        streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
        send(borrowedEvent);
    } else {
        if (complexEvent.getNext() == null) {
            for (PartitionExecutor partitionExecutor : partitionExecutors) {
                StreamEvent borrowedEvent = eventPool.borrowEvent();
                streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
                String key = partitionExecutor.execute(borrowedEvent);
                send(key, borrowedEvent);
            }
        } else {
            ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<ComplexEvent>(false);
            complexEventChunk.add(complexEvent);
            String currentKey = null;
            while (complexEventChunk.hasNext()) {
                ComplexEvent aEvent = complexEventChunk.next();
                complexEventChunk.remove();
                StreamEvent borrowedEvent = eventPool.borrowEvent();
                streamEventConverter.convertComplexEvent(aEvent, borrowedEvent);
                boolean currentEventMatchedPrevPartitionExecutor = false;
                for (PartitionExecutor partitionExecutor : partitionExecutors) {
                    String key = partitionExecutor.execute(borrowedEvent);
                    if (key != null) {
                        if (currentKey == null) {
                            currentKey = key;
                        } else if (!currentKey.equals(key)) {
                            if (!currentEventMatchedPrevPartitionExecutor) {
                                ComplexEvent firstEvent = streamEventChunk.getFirst();
                                send(currentKey, firstEvent);
                                currentKey = key;
                                streamEventChunk.clear();
                            } else {
                                ComplexEvent firstEvent = streamEventChunk.getFirst();
                                send(currentKey, firstEvent);
                                currentKey = key;
                                streamEventChunk.clear();
                                StreamEvent cloneEvent = eventPool.borrowEvent();
                                streamEventConverter.convertComplexEvent(aEvent, cloneEvent);
                                streamEventChunk.add(cloneEvent);
                            }
                        }
                        if (!currentEventMatchedPrevPartitionExecutor) {
                            streamEventChunk.add(borrowedEvent);
                        }
                        currentEventMatchedPrevPartitionExecutor = true;
                    }
                }
            }
            send(currentKey, streamEventChunk.getFirst());
            streamEventChunk.clear();
        }
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) PartitionExecutor(org.wso2.siddhi.core.partition.executor.PartitionExecutor) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 8 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent 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 9 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent 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 10 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent 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)

Aggregations

ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)59 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)29 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)26 ArrayList (java.util.ArrayList)21 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)17 Event (org.wso2.siddhi.core.event.Event)16 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)13 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)13 Test (org.testng.annotations.Test)12 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)12 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)10 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)5 Map (java.util.Map)4 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)4 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)3 Iterator (java.util.Iterator)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 Attribute (org.wso2.siddhi.query.api.definition.Attribute)2 HashMap (java.util.HashMap)1