Search in sources :

Example 76 with StreamEvent

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

the class PartitionStreamReceiver method receive.

@Override
public void receive(long timestamp, Object[] data) {
    StreamEvent newEvent = streamEventFactory.newInstance();
    streamEventConverter.convertData(timestamp, data, newEvent);
    if (partitionExecutors.size() == 0) {
        send(newEvent);
    } else {
        for (PartitionExecutor partitionExecutor : partitionExecutors) {
            String key = partitionExecutor.execute(newEvent);
            send(key, newEvent);
        }
    }
}
Also used : PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 77 with StreamEvent

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

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event event) {
    StreamEvent newEvent = streamEventFactory.newInstance();
    streamEventConverter.convertEvent(event, newEvent);
    for (PartitionExecutor partitionExecutor : partitionExecutors) {
        String key = partitionExecutor.execute(newEvent);
        send(key, newEvent);
    }
    if (partitionExecutors.size() == 0) {
        send(newEvent);
    }
}
Also used : PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 78 with StreamEvent

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

the class PartitionStreamReceiver method receive.

@Override
public void receive(List<Event> events) {
    if (partitionExecutors.size() == 0) {
        StreamEvent firstEvent = null;
        StreamEvent currentEvent = null;
        for (Event event : events) {
            StreamEvent nextEvent = streamEventFactory.newInstance();
            streamEventConverter.convertEvent(event, nextEvent);
            if (firstEvent == null) {
                firstEvent = nextEvent;
            } else {
                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)

Example 79 with StreamEvent

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

the class OutputCallback method constructMatchingStateEventChunk.

protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventFactory stateEventFactory, int matchingStreamIndex, StreamEventFactory streamEventFactory, StreamEventConverter streamEventConverter) {
    ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<>();
    while (matchingComplexEventChunk.hasNext()) {
        ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
        matchingComplexEventChunk.remove();
        StateEvent stateEvent = stateEventFactory.newInstance();
        if (convertToStreamEvent) {
            StreamEvent borrowEvent = streamEventFactory.newInstance();
            streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
            stateEvent.addEvent(matchingStreamIndex, borrowEvent);
        } else {
            stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
        }
        stateEventChunk.add(stateEvent);
    }
    return stateEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 80 with StreamEvent

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

the class CountPostStateProcessor method process.

protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    int streamEvents = 1;
    while (streamEvent.getNext() != null) {
        streamEvents++;
        streamEvent = streamEvent.getNext();
    }
    ((CountPreStateProcessor) thisStatePreProcessor).successCondition();
    stateEvent.setTimestamp(streamEvent.getTimestamp());
    if (streamEvents >= minCount) {
        if (thisStatePreProcessor.stateType == StateInputStream.Type.SEQUENCE) {
            if (nextStatePreProcessor != null) {
                nextStatePreProcessor.addState(stateEvent);
            }
            if (streamEvents != maxCount) {
                thisStatePreProcessor.addState(stateEvent);
            }
        } else if (streamEvents == minCount) {
            processMinCountReached(stateEvent, complexEventChunk);
        }
        if (streamEvents == maxCount) {
            thisStatePreProcessor.stateChanged();
        }
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (io.siddhi.core.event.stream.StreamEvent)203 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)92 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)74 StateEvent (io.siddhi.core.event.state.StateEvent)52 ComplexEvent (io.siddhi.core.event.ComplexEvent)33 ArrayList (java.util.ArrayList)27 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)26 Map (java.util.Map)24 Event (io.siddhi.core.event.Event)23 Test (org.testng.annotations.Test)23 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)20 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Attribute (io.siddhi.query.api.definition.Attribute)17 HashMap (java.util.HashMap)17 Operation (io.siddhi.core.event.stream.Operation)12 LinkedList (java.util.LinkedList)12 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)11 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)10 HashSet (java.util.HashSet)10 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)8