Search in sources :

Example 11 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class NotCollectionExecutor method delete.

@Override
public void delete(StateEvent deletingEvent, IndexedEventHolder indexedEventHolder) {
    Collection<StreamEvent> notStreamEvents = notCollectionExecutor.findEvents(deletingEvent, indexedEventHolder);
    if (notStreamEvents == null) {
        exhaustiveCollectionExecutor.delete(deletingEvent, indexedEventHolder);
    } else if (notStreamEvents.size() == 0) {
        indexedEventHolder.deleteAll();
    } else if (notStreamEvents.size() != indexedEventHolder.getAllEvents().size()) {
        Collection<StreamEvent> allEvents = indexedEventHolder.getAllEvents();
        Set<StreamEvent> returnSet = new HashSet<StreamEvent>();
        for (StreamEvent aEvent : allEvents) {
            if (!notStreamEvents.contains(aEvent)) {
                returnSet.add(aEvent);
            }
        }
        indexedEventHolder.deleteAll(returnSet);
    }
}
Also used : StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) HashSet(java.util.HashSet)

Example 12 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class ConversionStreamEventChunk method convertAndAdd.

public void convertAndAdd(Event event) {
    StreamEvent borrowedEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertEvent(event, borrowedEvent);
    if (first == null) {
        first = borrowedEvent;
        last = first;
    } else {
        last.setNext(borrowedEvent);
        last = borrowedEvent;
    }
}
Also used : MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 13 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class ConversionStreamEventChunk method convertAndAssign.

// @Override
// public void convertAndAssignFirst(StreamEvent streamEvent) {
// StreamEvent borrowedEvent = streamEventPool.borrowEvent();
// eventConverter.convertComplexEvent(streamEvent, borrowedEvent);
// first = borrowedEvent;
// last = first;
// }
public void convertAndAssign(Event[] events) {
    StreamEvent firstEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertEvent(events[0], firstEvent);
    StreamEvent currentEvent = firstEvent;
    for (int i = 1, eventsLength = events.length; i < eventsLength; i++) {
        StreamEvent nextEvent = streamEventPool.borrowEvent();
        streamEventConverter.convertEvent(events[i], nextEvent);
        currentEvent.setNext(nextEvent);
        currentEvent = nextEvent;
    }
    first = firstEvent;
    last = currentEvent;
}
Also used : MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 14 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class ConversionStreamEventChunk method convertAndAssign.

public void convertAndAssign(long timestamp, Object[] data) {
    StreamEvent borrowedEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertData(timestamp, data, borrowedEvent);
    first = borrowedEvent;
    last = first;
}
Also used : MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 15 with StreamEvent

use of org.ballerinalang.siddhi.core.event.stream.StreamEvent in project ballerina by ballerina-lang.

the class StateEvent method getStreamEvent.

public StreamEvent getStreamEvent(int[] position) {
    StreamEvent streamEvent = streamEvents[position[STREAM_EVENT_CHAIN_INDEX]];
    if (streamEvent == null) {
        return null;
    }
    int streamEventIndex = position[STREAM_EVENT_INDEX_IN_CHAIN];
    if (streamEventIndex >= 0) {
        for (int i = 1; i <= position[STREAM_EVENT_INDEX_IN_CHAIN]; i++) {
            streamEvent = streamEvent.getNext();
            if (streamEvent == null) {
                return null;
            }
        }
    } else if (streamEventIndex == CURRENT) {
        while (streamEvent.getNext() != null) {
            streamEvent = streamEvent.getNext();
        }
    } else if (streamEventIndex == LAST) {
        if (streamEvent.getNext() == null) {
            return null;
        }
        while (streamEvent.getNext().getNext() != null) {
            streamEvent = streamEvent.getNext();
        }
    } else {
        List<StreamEvent> stateEventList = new ArrayList<StreamEvent>();
        while (streamEvent != null) {
            stateEventList.add(streamEvent);
            streamEvent = streamEvent.getNext();
        }
        int index = stateEventList.size() + streamEventIndex;
        if (index < 0) {
            return null;
        } else {
            streamEvent = stateEventList.get(index);
        }
    }
    return streamEvent;
}
Also used : StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Aggregations

StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)117 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)41 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)40 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)19 Test (org.testng.annotations.Test)18 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)17 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)16 Event (org.ballerinalang.siddhi.core.event.Event)15 ArrayList (java.util.ArrayList)11 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)8 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)8 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)7 ConversionStreamEventChunk (org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)5 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)5