Search in sources :

Example 16 with StateEvent

use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.

the class FindStoreQueryRuntime method executeSelector.

private Event[] executeSelector(StreamEvent streamEvents, MetaStreamEvent.EventType eventType) {
    ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>(true);
    while (streamEvents != null) {
        StreamEvent streamEvent = streamEvents;
        streamEvents = streamEvents.getNext();
        streamEvent.setNext(null);
        StateEvent stateEvent = stateEventPool.borrowEvent();
        if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
            stateEvent.addEvent(1, streamEvent);
        } else {
            stateEvent.addEvent(0, streamEvent);
        }
        complexEventChunk.add(stateEvent);
    }
    ComplexEventChunk outputComplexEventChunk = selector.execute(complexEventChunk);
    if (outputComplexEventChunk != null) {
        List<Event> events = new ArrayList<>();
        outputComplexEventChunk.reset();
        while (outputComplexEventChunk.hasNext()) {
            ComplexEvent complexEvent = outputComplexEventChunk.next();
            events.add(new Event(complexEvent.getTimestamp(), complexEvent.getOutputData()));
        }
        return events.toArray(new Event[0]);
    } else {
        return null;
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList) Event(org.ballerinalang.siddhi.core.event.Event) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 17 with StateEvent

use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.

the class StateMultiProcessStreamReceiver method processAndClear.

protected void processAndClear(int processIndex, StreamEvent streamEvent) {
    ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(batchProcessingAllowed);
    ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent, batchProcessingAllowed);
    ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) nextProcessors[processIndex]).processAndReturn(currentStreamEventChunk);
    if (eventChunk.getFirst() != null) {
        retEventChunk.add(eventChunk.getFirst());
    }
    eventChunk.clear();
    if (querySelector != null) {
        while (retEventChunk.hasNext()) {
            StateEvent stateEvent = retEventChunk.next();
            retEventChunk.remove();
            querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, batchProcessingAllowed));
        }
    }
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 18 with StateEvent

use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.

the class JoinProcessor method joinEventBuilder.

/**
 * Join the given two event streams.
 *
 * @param leftStream  event left stream
 * @param rightStream event right stream
 * @param type        complex event type
 * @return StateEvent state event
 */
public StateEvent joinEventBuilder(StreamEvent leftStream, StreamEvent rightStream, ComplexEvent.Type type) {
    StateEvent returnEvent = stateEventPool.borrowEvent();
    returnEvent.setEvent(0, leftStream);
    returnEvent.setEvent(1, rightStream);
    returnEvent.setType(type);
    if (!leftJoinProcessor) {
        returnEvent.setTimestamp(rightStream.getTimestamp());
    } else {
        returnEvent.setTimestamp(leftStream.getTimestamp());
    }
    return returnEvent;
}
Also used : StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 19 with StateEvent

use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.

the class FindStoreQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventPool.borrowEvent();
    if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
        stateEvent.addEvent(1, streamEvent);
    } else {
        stateEvent.addEvent(0, streamEvent);
    }
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>(true);
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 20 with StateEvent

use of org.ballerinalang.siddhi.core.event.state.StateEvent in project ballerina by ballerina-lang.

the class SelectStoreQueryRuntime method execute.

public Event[] execute() {
    try {
        StateEvent stateEvent = new StateEvent(1, 0);
        StreamEvent streamEvents = queryableProcessor.query(stateEvent, compiledCondition, compiledSelection);
        if (streamEvents == null) {
            return null;
        } else {
            List<Event> events = new ArrayList<Event>();
            while (streamEvents != null) {
                events.add(new Event(streamEvents.getTimestamp(), streamEvents.getOutputData()));
                streamEvents = streamEvents.getNext();
            }
            return events.toArray(new Event[0]);
        }
    } catch (Throwable t) {
        throw new StoreQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
    }
}
Also used : StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StoreQueryRuntimeException(org.ballerinalang.siddhi.core.exception.StoreQueryRuntimeException) ArrayList(java.util.ArrayList) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) Event(org.ballerinalang.siddhi.core.event.Event) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Aggregations

StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)34 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)19 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)19 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)5 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)4 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)4 HashMap (java.util.HashMap)3 Event (org.ballerinalang.siddhi.core.event.Event)3 StoreQueryRuntimeException (org.ballerinalang.siddhi.core.exception.StoreQueryRuntimeException)2 Collection (java.util.Collection)1 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)1 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)1 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)1 AndConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor)1 BoolConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.BoolConditionExpressionExecutor)1 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)1 InConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.InConditionExpressionExecutor)1