Search in sources :

Example 6 with PartitionExecutor

use of io.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 = streamEventFactory.newInstance();
        streamEventConverter.convertEvent(events[0], firstEvent);
        currentEvent = firstEvent;
        for (int i = 1; i < events.length; i++) {
            StreamEvent nextEvent = streamEventFactory.newInstance();
            streamEventConverter.convertEvent(events[i], nextEvent);
            currentEvent.setNext(nextEvent);
            currentEvent = nextEvent;
        }
        send(firstEvent);
    } else {
        String key = null;
        StreamEvent firstEvent = null;
        StreamEvent currentEvent = null;
        for (Event event : events) {
            StreamEvent nextEvent = streamEventFactory.newInstance();
            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);
                        key = currentKey;
                        firstEvent = nextEvent;
                    } else {
                        currentEvent.setNext(nextEvent);
                    }
                    currentEvent = nextEvent;
                }
            }
        }
        send(key, firstEvent);
    }
}
Also used : PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

PartitionExecutor (io.siddhi.core.partition.executor.PartitionExecutor)6 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)5 StreamEvent (io.siddhi.core.event.stream.StreamEvent)5 ComplexEvent (io.siddhi.core.event.ComplexEvent)3 Event (io.siddhi.core.event.Event)2 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)1 ConditionExpressionExecutor (io.siddhi.core.executor.condition.ConditionExpressionExecutor)1 RangePartitionExecutor (io.siddhi.core.partition.executor.RangePartitionExecutor)1 ValuePartitionExecutor (io.siddhi.core.partition.executor.ValuePartitionExecutor)1 PartitionType (io.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (io.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (io.siddhi.query.api.execution.partition.ValuePartitionType)1 ArrayList (java.util.ArrayList)1