Search in sources :

Example 6 with PartitionExecutor

use of org.wso2.siddhi.core.partition.executor.PartitionExecutor in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event[] events) {
    if (partitionExecutors.size() == 0) {
        StreamEvent currentEvent;
        StreamEvent firstEvent = eventPool.borrowEvent();
        streamEventConverter.convertEvent(events[0], firstEvent);
        currentEvent = firstEvent;
        for (int i = 1; i < events.length; i++) {
            StreamEvent nextEvent = eventPool.borrowEvent();
            streamEventConverter.convertEvent(events[i], nextEvent);
            currentEvent.setNext(nextEvent);
            currentEvent = nextEvent;
        }
        send(firstEvent);
        eventPool.returnEvents(firstEvent);
    } else {
        String key = null;
        StreamEvent firstEvent = null;
        StreamEvent currentEvent = null;
        for (Event event : events) {
            StreamEvent nextEvent = eventPool.borrowEvent();
            streamEventConverter.convertEvent(event, nextEvent);
            for (PartitionExecutor partitionExecutor : partitionExecutors) {
                String currentKey = partitionExecutor.execute(nextEvent);
                if (currentKey != null) {
                    if (key == null) {
                        key = currentKey;
                        firstEvent = nextEvent;
                    } else if (!currentKey.equals(key)) {
                        send(key, firstEvent);
                        eventPool.returnEvents(firstEvent);
                        key = currentKey;
                        firstEvent = nextEvent;
                    } else {
                        currentEvent.setNext(nextEvent);
                    }
                    currentEvent = nextEvent;
                }
            }
        }
        send(key, firstEvent);
        eventPool.returnEvents(firstEvent);
    }
}
Also used : PartitionExecutor(org.wso2.siddhi.core.partition.executor.PartitionExecutor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event)

Aggregations

PartitionExecutor (org.wso2.siddhi.core.partition.executor.PartitionExecutor)5 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)4 ArrayList (java.util.ArrayList)2 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)2 List (java.util.List)1 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)1 Event (org.wso2.siddhi.core.event.Event)1 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)1 RangePartitionExecutor (org.wso2.siddhi.core.partition.executor.RangePartitionExecutor)1 ValuePartitionExecutor (org.wso2.siddhi.core.partition.executor.ValuePartitionExecutor)1 JoinStreamRuntime (org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime)1 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 StateStreamRuntime (org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)1 PartitionType (org.wso2.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (org.wso2.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (org.wso2.siddhi.query.api.execution.partition.ValuePartitionType)1 Query (org.wso2.siddhi.query.api.execution.query.Query)1 CountStateElement (org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement)1 EveryStateElement (org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement)1