Search in sources :

Example 16 with StreamEventCloner

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

the class StreamFunctionProcessor method processEventChunk.

@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
    while (streamEventChunk.hasNext()) {
        ComplexEvent complexEvent = streamEventChunk.next();
        Object[] outputData;
        switch(attributeExpressionLength) {
            case 0:
                outputData = process((Object) null);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            case 1:
                outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            default:
                Object[] inputData = new Object[attributeExpressionLength];
                for (int i = 0; i < attributeExpressionLength; i++) {
                    inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
                }
                outputData = process(inputData);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 17 with StreamEventCloner

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

the class CronWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            currentEventChunk.add(clonedStreamEvent);
            streamEventChunk.remove();
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 18 with StreamEventCloner

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

the class ExternalTimeBatchWindowProcessor method flushToOutputChunk.

private void flushToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents) {
    ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<StreamEvent>(true);
    if (outputExpectsExpiredEvents) {
        if (expiredEventChunk.getFirst() != null) {
            // mark the timestamp for the expiredType event
            expiredEventChunk.reset();
            while (expiredEventChunk.hasNext()) {
                StreamEvent expiredEvent = expiredEventChunk.next();
                expiredEvent.setTimestamp(currentTime);
            }
            // add expired event to newEventChunk.
            newEventChunk.add(expiredEventChunk.getFirst());
        }
    }
    if (expiredEventChunk != null) {
        expiredEventChunk.clear();
    }
    if (currentEventChunk.getFirst() != null) {
        // add reset event in front of current events
        resetEvent.setTimestamp(currentTime);
        newEventChunk.add(resetEvent);
        resetEvent = null;
        // move to expired events
        if (preserveCurrentEvents || storeExpiredEvents) {
            currentEventChunk.reset();
            while (currentEventChunk.hasNext()) {
                StreamEvent currentEvent = currentEventChunk.next();
                StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                expiredEventChunk.add(toExpireEvent);
            }
        }
        // add current event chunk to next processor
        newEventChunk.add(currentEventChunk.getFirst());
    }
    currentEventChunk.clear();
    if (newEventChunk.getFirst() != null) {
        complexEventChunks.add(newEventChunk);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 19 with StreamEventCloner

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

the class ExternalTimeBatchWindowProcessor method cloneAppend.

private void cloneAppend(StreamEventCloner streamEventCloner, StreamEvent currStreamEvent) {
    StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(currStreamEvent);
    if (replaceTimestampWithBatchEndTime) {
        clonedStreamEvent.setAttribute(endTime, timestampExpressionExecutor.getPosition());
    }
    currentEventChunk.add(clonedStreamEvent);
    if (resetEvent == null) {
        resetEvent = streamEventCloner.copyStreamEvent(currStreamEvent);
        resetEvent.setType(ComplexEvent.Type.RESET);
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 20 with StreamEventCloner

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

the class ExternalTimeWindowProcessor method process.

@Override
protected synchronized void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            long currentTime = (Long) timeStampVariableExpressionExecutor.execute(streamEvent);
            StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedEvent.setType(StreamEvent.Type.EXPIRED);
            // reset expiredEventChunk to make sure all of the expired events get removed,
            // otherwise lastReturned.next will always return null and here while check is always false
            expiredEventChunk.reset();
            while (expiredEventChunk.hasNext()) {
                StreamEvent expiredEvent = expiredEventChunk.next();
                long expiredEventTime = (Long) timeStampVariableExpressionExecutor.execute(expiredEvent);
                long timeDiff = expiredEventTime - currentTime + timeToKeep;
                if (timeDiff <= 0) {
                    expiredEventChunk.remove();
                    expiredEvent.setTimestamp(currentTime);
                    streamEventChunk.insertBeforeCurrent(expiredEvent);
                } else {
                    expiredEventChunk.reset();
                    break;
                }
            }
            if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
                this.expiredEventChunk.add(clonedEvent);
            }
            expiredEventChunk.reset();
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)23 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)11 ArrayList (java.util.ArrayList)5 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)4 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)4 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)2 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)2 StateEventCloner (org.wso2.siddhi.core.event.state.StateEventCloner)2 SchedulingProcessor (org.wso2.siddhi.core.query.processor.SchedulingProcessor)2 Attribute (org.wso2.siddhi.query.api.definition.Attribute)2 Collection (java.util.Collection)1 StateEventPool (org.wso2.siddhi.core.event.state.StateEventPool)1 ComplexEventPopulater (org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater)1 ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)1 JoinProcessor (org.wso2.siddhi.core.query.input.stream.join.JoinProcessor)1 EntryValveProcessor (org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor)1 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)1 Processor (org.wso2.siddhi.core.query.processor.Processor)1 AbstractStreamProcessor (org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor)1