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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations