Search in sources :

Example 11 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class LengthBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
    synchronized (this) {
        ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<StreamEvent>(true);
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            currentEventChunk.add(clonedStreamEvent);
            count++;
            if (count == length) {
                if (outputExpectsExpiredEvents) {
                    if (expiredEventChunk.getFirst() != null) {
                        while (expiredEventChunk.hasNext()) {
                            StreamEvent expiredEvent = expiredEventChunk.next();
                            expiredEvent.setTimestamp(currentTime);
                        }
                        outputStreamEventChunk.add(expiredEventChunk.getFirst());
                    }
                }
                if (expiredEventChunk != null) {
                    expiredEventChunk.clear();
                }
                if (currentEventChunk.getFirst() != null) {
                    // add reset event in front of current events
                    outputStreamEventChunk.add(resetEvent);
                    resetEvent = null;
                    if (expiredEventChunk != null) {
                        currentEventChunk.reset();
                        while (currentEventChunk.hasNext()) {
                            StreamEvent currentEvent = currentEventChunk.next();
                            StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                            toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                            expiredEventChunk.add(toExpireEvent);
                        }
                    }
                    resetEvent = streamEventCloner.copyStreamEvent(currentEventChunk.getFirst());
                    resetEvent.setType(ComplexEvent.Type.RESET);
                    outputStreamEventChunk.add(currentEventChunk.getFirst());
                }
                currentEventChunk.clear();
                count = 0;
                if (outputStreamEventChunk.getFirst() != null) {
                    streamEventChunks.add(outputStreamEventChunk);
                }
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
        nextProcessor.process(outputStreamEventChunk);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Example 12 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class TimeBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        if (nextEmitTime == -1) {
            long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
            if (isStartTimeEnabled) {
                nextEmitTime = getNextEmitTime(currentTime);
            } else {
                nextEmitTime = siddhiAppContext.getTimestampGenerator().currentTime() + timeInMilliSeconds;
            }
            scheduler.notifyAt(nextEmitTime);
        }
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        boolean sendEvents;
        if (currentTime >= nextEmitTime) {
            nextEmitTime += timeInMilliSeconds;
            scheduler.notifyAt(nextEmitTime);
            sendEvents = true;
        } else {
            sendEvents = false;
        }
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            if (streamEvent.getType() != ComplexEvent.Type.CURRENT) {
                continue;
            }
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            currentEventChunk.add(clonedStreamEvent);
        }
        streamEventChunk.clear();
        if (sendEvents) {
            if (outputExpectsExpiredEvents) {
                if (expiredEventChunk.getFirst() != null) {
                    while (expiredEventChunk.hasNext()) {
                        StreamEvent expiredEvent = expiredEventChunk.next();
                        expiredEvent.setTimestamp(currentTime);
                    }
                    streamEventChunk.add(expiredEventChunk.getFirst());
                }
            }
            if (expiredEventChunk != null) {
                expiredEventChunk.clear();
            }
            if (currentEventChunk.getFirst() != null) {
                // add reset event in front of current events
                streamEventChunk.add(resetEvent);
                resetEvent = null;
                if (expiredEventChunk != null) {
                    currentEventChunk.reset();
                    while (currentEventChunk.hasNext()) {
                        StreamEvent currentEvent = currentEventChunk.next();
                        StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                        toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                        expiredEventChunk.add(toExpireEvent);
                    }
                }
                resetEvent = streamEventCloner.copyStreamEvent(currentEventChunk.getFirst());
                resetEvent.setType(ComplexEvent.Type.RESET);
                streamEventChunk.add(currentEventChunk.getFirst());
            }
            currentEventChunk.clear();
        }
    }
    if (streamEventChunk.getFirst() != null) {
        streamEventChunk.setBatch(true);
        nextProcessor.process(streamEventChunk);
        streamEventChunk.setBatch(false);
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 13 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class StreamJunction method sendData.

private void sendData(long timeStamp, Object[] data) {
    // Set timestamp to system if Siddhi is in playback mode
    if (siddhiAppContext.isPlayback()) {
        ((EventTimeBasedMillisTimestampGenerator) this.siddhiAppContext.getTimestampGenerator()).setCurrentTimestamp(timeStamp);
    }
    if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
        throughputTracker.eventIn();
    }
    if (disruptor != null) {
        long sequenceNo = ringBuffer.next();
        try {
            Event existingEvent = ringBuffer.get(sequenceNo);
            existingEvent.setTimestamp(timeStamp);
            existingEvent.setIsExpired(false);
            System.arraycopy(data, 0, existingEvent.getData(), 0, data.length);
        } finally {
            ringBuffer.publish(sequenceNo);
        }
    } else {
        for (Receiver receiver : receivers) {
            receiver.receive(timeStamp, data);
        }
    }
}
Also used : EventTimeBasedMillisTimestampGenerator(org.wso2.siddhi.core.util.timestamp.EventTimeBasedMillisTimestampGenerator) Event(org.wso2.siddhi.core.event.Event) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 14 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class AttributeAggregator method cloneAggregator.

public AttributeAggregator cloneAggregator(String key) {
    try {
        AttributeAggregator attributeAggregator = this.getClass().newInstance();
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeSize];
        for (int i = 0; i < attributeSize; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors[i].cloneExecutor(key);
        }
        attributeAggregator.elementId = elementId + "-" + key;
        attributeAggregator.initAggregator(innerExpressionExecutors, siddhiAppContext, configReader);
        return attributeAggregator;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException)

Example 15 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class PartitionedDistributionStrategy method init.

/**
 * Initialize the Distribution strategy with the information it will require to make decisions.
 *  @param streamDefinition         The stream attached to the sink this DistributionStrategy is used in
 * @param transportOptionHolder    Sink options of the sink which uses this DistributionStrategy
 * @param destinationOptionHolders The list of options under @destination of the relevant sink.
 * @param configReader This hold the {@link PartitionedDistributionStrategy} configuration reader.
 */
@Override
public void init(StreamDefinition streamDefinition, OptionHolder transportOptionHolder, OptionHolder distributionOptionHolder, List<OptionHolder> destinationOptionHolders, ConfigReader configReader) {
    totalDestinationCount = destinationOptionHolders.size();
    String partitionKey = distributionOptionHolder.validateAndGetStaticValue(SiddhiConstants.PARTITION_KEY_FIELD_KEY);
    if (partitionKey == null || partitionKey.isEmpty()) {
        throw new SiddhiAppValidationException("PartitionKey is required for partitioned distribution " + "strategy.");
    }
    try {
        int partitionKeyFieldPosition = streamDefinition.getAttributePosition(partitionKey);
        partitionOption = new Option(partitionKeyFieldPosition);
    } catch (AttributeNotExistException e) {
        throw new SiddhiAppValidationException("Could not find partition key attribute", e);
    }
}
Also used : AttributeNotExistException(org.wso2.siddhi.query.api.exception.AttributeNotExistException) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) Option(org.wso2.siddhi.core.util.transport.Option)

Aggregations

Test (org.testng.annotations.Test)281 Event (org.wso2.siddhi.core.event.Event)187 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)186 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)186 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)182 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)160 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)153 ArrayList (java.util.ArrayList)148 HashMap (java.util.HashMap)118 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)103 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)81 IOException (java.io.IOException)57 Map (java.util.Map)54 API (org.wso2.carbon.apimgt.core.models.API)52 SQLException (java.sql.SQLException)48 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)46 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)39 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)37 File (java.io.File)35 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)34