Search in sources :

Example 21 with StreamEventCloner

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

the class WrappedSnapshotOutputRateLimiter method init.

public void init(int outPutAttributeSize, List<AttributeProcessor> attributeProcessorList, MetaComplexEvent metaComplexEvent) {
    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
        if (attributeProcessor.getExpressionExecutor() instanceof AbstractAggregationAttributeExecutor) {
            aggregateAttributePositionList.add(attributeProcessor.getOutputPosition());
        }
    }
    if (windowed) {
        if (groupBy) {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationGroupByWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, aggregateAttributePositionList, this, siddhiAppContext, queryName);
            } else {
                // No aggregation
                // GroupBy is same as Non GroupBy
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            }
        } else {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, aggregateAttributePositionList, this, siddhiAppContext, queryName);
            } else {
                // No aggregation
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            }
        }
    } else {
        if (groupBy) {
            outputRateLimiter = new GroupByPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
        } else {
            outputRateLimiter = new PerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
        }
    }
    if (metaComplexEvent instanceof MetaStateEvent) {
        StateEventPool stateEventPool = new StateEventPool((MetaStateEvent) metaComplexEvent, 5);
        outputRateLimiter.setStateEventCloner(new StateEventCloner((MetaStateEvent) metaComplexEvent, stateEventPool));
    } else {
        StreamEventPool streamEventPool = new StreamEventPool((MetaStreamEvent) metaComplexEvent, 5);
        outputRateLimiter.setStreamEventCloner(new StreamEventCloner((MetaStreamEvent) metaComplexEvent, streamEventPool));
    }
}
Also used : AbstractAggregationAttributeExecutor(org.wso2.siddhi.core.query.selector.attribute.processor.executor.AbstractAggregationAttributeExecutor) StateEventPool(org.wso2.siddhi.core.event.state.StateEventPool) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.wso2.siddhi.core.event.stream.StreamEventCloner) AttributeProcessor(org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor) StateEventCloner(org.wso2.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 22 with StreamEventCloner

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

the class LengthWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedEvent.setType(StreamEvent.Type.EXPIRED);
            if (count < length) {
                count++;
                this.expiredEventChunk.add(clonedEvent);
            } else {
                StreamEvent firstEvent = this.expiredEventChunk.poll();
                if (firstEvent != null) {
                    firstEvent.setTimestamp(currentTime);
                    streamEventChunk.insertBeforeCurrent(firstEvent);
                    this.expiredEventChunk.add(clonedEvent);
                } else {
                    StreamEvent resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
                    resetEvent.setType(ComplexEvent.Type.RESET);
                    // adding resetEvent and clonedEvent event to the streamEventChunk
                    // since we are using insertAfterCurrent(), the final order will be
                    // currentEvent > clonedEvent (or expiredEvent) > resetEvent
                    streamEventChunk.insertAfterCurrent(resetEvent);
                    streamEventChunk.insertAfterCurrent(clonedEvent);
                    // since we manually added resetEvent and clonedEvent in earlier step
                    // we have to skip those two events from getting processed in the next
                    // iteration. Hence, calling next() twice.
                    streamEventChunk.next();
                    streamEventChunk.next();
                }
            }
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 23 with StreamEventCloner

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

the class LossyFrequentWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        StreamEvent streamEvent = streamEventChunk.getFirst();
        streamEventChunk.clear();
        while (streamEvent != null) {
            StreamEvent next = streamEvent.getNext();
            streamEvent.setNext(null);
            StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedEvent.setType(StreamEvent.Type.EXPIRED);
            totalCount++;
            if (totalCount != 1) {
                currentBucketId = Math.ceil(totalCount / windowWidth);
            }
            String currentKey = generateKey(streamEvent);
            StreamEvent oldEvent = map.put(currentKey, clonedEvent);
            if (oldEvent != null) {
                // this event is already in the store
                countMap.put(currentKey, countMap.get(currentKey).incrementCount());
            } else {
                // This is a new event
                LossyCount lCount;
                lCount = new LossyCount(1, (int) currentBucketId - 1);
                countMap.put(currentKey, lCount);
            }
            // calculating all the events in the system which match the
            // requirement provided by the user
            List<String> keys = new ArrayList<String>();
            keys.addAll(countMap.keySet());
            for (String key : keys) {
                LossyCount lossyCount = countMap.get(key);
                if (lossyCount.getCount() >= ((support - error) * totalCount)) {
                    // among the selected events, if the newly arrive event is there we mark it as an inEvent
                    if (key.equals(currentKey)) {
                        streamEventChunk.add(streamEvent);
                    }
                }
            }
            if (totalCount % windowWidth == 0) {
                // its time to run the data-structure prune code
                keys = new ArrayList<String>();
                keys.addAll(countMap.keySet());
                for (String key : keys) {
                    LossyCount lossyCount = countMap.get(key);
                    if (lossyCount.getCount() + lossyCount.getBucketId() <= currentBucketId) {
                        log.info("Removing the Event: " + key + " from the window");
                        countMap.remove(key);
                        StreamEvent expirtedEvent = map.remove(key);
                        expirtedEvent.setTimestamp(currentTime);
                        streamEventChunk.add(expirtedEvent);
                    }
                }
            }
            streamEvent = next;
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Example 24 with StreamEventCloner

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

the class TimeLengthWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            expiredEventChunk.reset();
            while (expiredEventChunk.hasNext()) {
                StreamEvent expiredEvent = expiredEventChunk.next();
                long timeDiff = expiredEvent.getTimestamp() - currentTime + timeInMilliSeconds;
                if (timeDiff <= 0) {
                    expiredEventChunk.remove();
                    count--;
                    expiredEvent.setTimestamp(currentTime);
                    streamEventChunk.insertBeforeCurrent(expiredEvent);
                } else {
                    break;
                }
            }
            expiredEventChunk.reset();
            if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
                StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
                clonedEvent.setType(StreamEvent.Type.EXPIRED);
                if (count < length) {
                    count++;
                    this.expiredEventChunk.add(clonedEvent);
                } else {
                    StreamEvent firstEvent = this.expiredEventChunk.poll();
                    if (firstEvent != null) {
                        firstEvent.setTimestamp(currentTime);
                        streamEventChunk.insertBeforeCurrent(firstEvent);
                        this.expiredEventChunk.add(clonedEvent);
                    }
                }
                scheduler.notifyAt(clonedEvent.getTimestamp() + timeInMilliSeconds);
            } else {
                streamEventChunk.remove();
            }
        }
    }
    streamEventChunk.reset();
    if (streamEventChunk.hasNext()) {
        nextProcessor.process(streamEventChunk);
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 25 with StreamEventCloner

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

the class CollectionOperator method find.

@Override
public StreamEvent find(StateEvent matchingEvent, Object storeEvents, StreamEventCloner storeEventCloner) {
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
    for (StreamEvent storeEvent : (Collection<StreamEvent>) storeEvents) {
        matchingEvent.setEvent(storeEventPosition, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
        }
        matchingEvent.setEvent(storeEventPosition, null);
    }
    return returnEventChunk.getFirst();
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Collection(java.util.Collection)

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