Search in sources :

Example 16 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent 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 17 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(long timestamp, Object[] data) {
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    streamEventConverter.convertData(timestamp, data, borrowedEvent);
    if (partitionExecutors.size() == 0) {
        send(borrowedEvent);
    } else {
        for (PartitionExecutor partitionExecutor : partitionExecutors) {
            String key = partitionExecutor.execute(borrowedEvent);
            send(key, borrowedEvent);
        }
    }
    eventPool.returnEvents(borrowedEvent);
}
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)

Example 18 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent 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 19 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event event) {
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    streamEventConverter.convertEvent(event, borrowedEvent);
    for (PartitionExecutor partitionExecutor : partitionExecutors) {
        String key = partitionExecutor.execute(borrowedEvent);
        send(key, borrowedEvent);
    }
    if (partitionExecutors.size() == 0) {
        send(borrowedEvent);
    }
    eventPool.returnEvents(borrowedEvent);
}
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)

Example 20 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class AbsentLogicalPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>(false);
    if (!this.active) {
        return returnEventChunk;
    }
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    this.lock.lock();
    try {
        for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            if (withinStates.size() > 0) {
                if (isExpired(stateEvent, streamEvent.getTimestamp())) {
                    iterator.remove();
                    continue;
                }
            }
            if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
                iterator.remove();
                continue;
            }
            StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
            stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
            process(stateEvent);
            if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePerProcessor != null)) {
                // Reset to the original state after processing
                stateEvent.setEvent(stateId, currentStreamEvent);
            }
            if (this.thisLastProcessor.isEventReturned()) {
                this.thisLastProcessor.clearProcessedEvent();
                // The event has passed the filter condition. So remove from being an absent candidate.
                iterator.remove();
                if (stateType == StateInputStream.Type.SEQUENCE) {
                    partnerStatePreProcessor.pendingStateEventList.remove(stateEvent);
                }
            }
            if (!stateChanged) {
                switch(stateType) {
                    case PATTERN:
                        stateEvent.setEvent(stateId, currentStreamEvent);
                        break;
                    case SEQUENCE:
                        stateEvent.setEvent(stateId, currentStreamEvent);
                        iterator.remove();
                        break;
                }
            }
        }
    } finally {
        this.lock.unlock();
    }
    return returnEventChunk;
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)121 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)42 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)41 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)23 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)20 Test (org.testng.annotations.Test)19 Event (org.wso2.siddhi.core.event.Event)16 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)16 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)8 Attribute (org.wso2.siddhi.query.api.definition.Attribute)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)6 HashMap (java.util.HashMap)5