Search in sources :

Example 96 with StreamEvent

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

the class StreamPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    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 (Math.abs(stateEvent.getTimestamp() - streamEvent.getTimestamp()) > withinStates) {
        // iterator.remove();
        // //                    switch (stateType) {
        // //                        case PATTERN:
        // //                            stateEvent.setEvent(stateId, null);
        // //                            break;
        // //                        case SEQUENCE:
        // //                            stateEvent.setEvent(stateId, null);
        // //                            iterator.remove();
        // //                            if (thisStatePostProcessor.callbackPreStateProcessor != null) {
        // //                                thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
        // //                            }
        // //                            break;
        // //                    }
        // continue;
        // }
        // }
        stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
        process(stateEvent);
        if (this.thisLastProcessor.isEventReturned()) {
            this.thisLastProcessor.clearProcessedEvent();
            returnEventChunk.add(stateEvent);
        }
        if (stateChanged) {
            iterator.remove();
        } else {
            switch(stateType) {
                case PATTERN:
                    stateEvent.setEvent(stateId, null);
                    break;
                case SEQUENCE:
                    stateEvent.setEvent(stateId, null);
                    iterator.remove();
                    if (thisStatePostProcessor.callbackPreStateProcessor != null) {
                        thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
                    }
                    break;
            }
        }
    }
    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)

Example 97 with StreamEvent

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

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.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 98 with StreamEvent

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

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.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 99 with StreamEvent

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

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.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 100 with StreamEvent

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

the class StreamEventPopulaterFactory method constructEventPopulator.

/**
 * Constructs StreamEventPopulater according to MetaStateEvent and to be mapped attributes
 *
 * @param metaStreamEvent       info for populating the StreamEvent
 * @param streamEventChainIndex StreamEvent chain index
 * @param attributes            mapped attributes
 * @return StateEventPopulater
 */
public static ComplexEventPopulater constructEventPopulator(MetaStreamEvent metaStreamEvent, int streamEventChainIndex, List<Attribute> attributes) {
    List<StreamMappingElement> streamMappingElements = new ArrayList<StreamMappingElement>();
    for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) {
        Attribute attribute = attributes.get(i);
        StreamMappingElement streamMappingElement = new StreamMappingElement();
        streamMappingElement.setFromPosition(i);
        int index = metaStreamEvent.getOutputData().indexOf(attribute);
        if (index > -1) {
            streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, OUTPUT_DATA_INDEX, index });
        } else {
            index = metaStreamEvent.getOnAfterWindowData().indexOf(attribute);
            if (index > -1) {
                streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, ON_AFTER_WINDOW_DATA_INDEX, index });
            } else {
                index = metaStreamEvent.getBeforeWindowData().indexOf(attribute);
                if (index > -1) {
                    streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, BEFORE_WINDOW_DATA_INDEX, index });
                } else {
                    streamMappingElement.setToPosition(null);
                }
            }
        }
        streamMappingElements.add(streamMappingElement);
    }
    return new SelectiveComplexEventPopulater(streamMappingElements);
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList)

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