Search in sources :

Example 11 with LockWrapper

use of org.wso2.siddhi.core.util.lock.LockWrapper in project siddhi by wso2.

the class QueryRuntime method clone.

public QueryRuntime clone(String key, ConcurrentMap<String, StreamJunction> localStreamJunctionMap) {
    LockWrapper lockWrapper = null;
    if (synchronised) {
        lockWrapper = new LockWrapper("");
        lockWrapper.setLock(new ReentrantLock());
    }
    StreamRuntime clonedStreamRuntime = this.streamRuntime.clone(key);
    QuerySelector clonedSelector = this.selector.clone(key);
    OutputRateLimiter clonedOutputRateLimiter = outputRateLimiter.clone(key);
    clonedOutputRateLimiter.init(siddhiAppContext, lockWrapper, queryId);
    QueryRuntime queryRuntime = new QueryRuntime(query, siddhiAppContext, clonedStreamRuntime, clonedSelector, clonedOutputRateLimiter, outputCallback, this.metaComplexEvent, synchronised, this.queryId + key);
    QueryParserHelper.initStreamRuntime(clonedStreamRuntime, metaComplexEvent, lockWrapper, queryId);
    queryRuntime.setToLocalStream(toLocalStream);
    if (!toLocalStream) {
        queryRuntime.outputRateLimiter.setOutputCallback(outputCallback);
        queryRuntime.outputCallback = this.outputCallback;
    } else {
        OutputCallback clonedQueryOutputCallback = OutputParser.constructOutputCallback(query.getOutputStream(), key, localStreamJunctionMap, outputStreamDefinition, siddhiAppContext, queryId);
        queryRuntime.outputRateLimiter.setOutputCallback(clonedQueryOutputCallback);
        queryRuntime.outputCallback = clonedQueryOutputCallback;
    }
    return queryRuntime;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) OutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter) QuerySelector(org.wso2.siddhi.core.query.selector.QuerySelector) LockWrapper(org.wso2.siddhi.core.util.lock.LockWrapper) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime) OutputCallback(org.wso2.siddhi.core.query.output.callback.OutputCallback)

Example 12 with LockWrapper

use of org.wso2.siddhi.core.util.lock.LockWrapper in project siddhi by wso2.

the class OutputRateLimiter method sendToCallBacks.

protected void sendToCallBacks(ComplexEventChunk complexEventChunk) {
    if (siddhiAppContext.isStatsEnabled() && latencyTracker != null) {
        latencyTracker.markOut();
    }
    if (lockWrapper != null) {
        lockWrapper.unlock();
    }
    if (!queryCallbacks.isEmpty()) {
        for (QueryCallback callback : queryCallbacks) {
            callback.receiveStreamEvent(complexEventChunk);
        }
    }
    if (outputCallback != null && complexEventChunk.getFirst() != null) {
        complexEventChunk.reset();
        int noOfEvents = 0;
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                complexEvent.setType(ComplexEvent.Type.CURRENT);
                noOfEvents++;
            } else if (complexEvent.getType() == ComplexEvent.Type.RESET) {
                complexEventChunk.remove();
            } else {
                noOfEvents++;
            }
        }
        if (complexEventChunk.getFirst() != null) {
            outputCallback.send(complexEventChunk, noOfEvents);
        }
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback)

Example 13 with LockWrapper

use of org.wso2.siddhi.core.util.lock.LockWrapper in project siddhi by wso2.

the class AllPerTimeOutputRateLimiter method start.

@Override
public void start() {
    scheduler = SchedulerParser.parse(scheduledExecutorService, this, siddhiAppContext);
    scheduler.setStreamEventPool(new StreamEventPool(0, 0, 0, 5));
    scheduler.init(lockWrapper, queryName);
    long currentTime = System.currentTimeMillis();
    scheduledTime = currentTime + value;
    scheduler.notifyAt(scheduledTime);
}
Also used : StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool)

Example 14 with LockWrapper

use of org.wso2.siddhi.core.util.lock.LockWrapper in project siddhi by wso2.

the class FirstPerTimeOutputRateLimiter method start.

@Override
public void start() {
    scheduler = SchedulerParser.parse(scheduledExecutorService, this, siddhiAppContext);
    scheduler.setStreamEventPool(new StreamEventPool(0, 0, 0, 5));
    scheduler.init(lockWrapper, queryName);
    long currentTime = System.currentTimeMillis();
    scheduledTime = currentTime + value;
    scheduler.notifyAt(scheduledTime);
}
Also used : StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool)

Example 15 with LockWrapper

use of org.wso2.siddhi.core.util.lock.LockWrapper in project siddhi by wso2.

the class LastGroupByPerTimeOutputRateLimiter method start.

@Override
public void start() {
    scheduler = SchedulerParser.parse(scheduledExecutorService, this, siddhiAppContext);
    scheduler.setStreamEventPool(new StreamEventPool(0, 0, 0, 5));
    scheduler.init(lockWrapper, queryName);
    long currentTime = System.currentTimeMillis();
    scheduledTime = currentTime + value;
    scheduler.notifyAt(scheduledTime);
}
Also used : StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool)

Aggregations

StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)13 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)3 StreamRuntime (org.wso2.siddhi.core.query.input.stream.StreamRuntime)3 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 LockWrapper (org.wso2.siddhi.core.util.lock.LockWrapper)3 ArrayList (java.util.ArrayList)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 OutputCallback (org.wso2.siddhi.core.query.output.callback.OutputCallback)2 OutputRateLimiter (org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter)2 QuerySelector (org.wso2.siddhi.core.query.selector.QuerySelector)2 LatencyTracker (org.wso2.siddhi.core.util.statistics.LatencyTracker)2 Element (org.wso2.siddhi.query.api.annotation.Element)2 AggregationRuntime (org.wso2.siddhi.core.aggregation.AggregationRuntime)1 IncrementalAggregationProcessor (org.wso2.siddhi.core.aggregation.IncrementalAggregationProcessor)1 IncrementalExecutor (org.wso2.siddhi.core.aggregation.IncrementalExecutor)1 RecreateInMemoryData (org.wso2.siddhi.core.aggregation.RecreateInMemoryData)1 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)1 StateEventCloner (org.wso2.siddhi.core.event.state.StateEventCloner)1