use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class SumIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
Attribute sum;
Expression sumInitialValue;
if (attributeName == null) {
throw new SiddhiAppCreationException("Sum incremental attribute aggregation cannot be executed " + "when no parameters are given");
}
if (attributeType.equals(Attribute.Type.FLOAT) || attributeType.equals(Attribute.Type.DOUBLE)) {
sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.DOUBLE);
sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("double"));
returnType = Attribute.Type.DOUBLE;
} else if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG)) {
sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.LONG);
sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("long"));
returnType = Attribute.Type.LONG;
} else {
throw new SiddhiAppRuntimeException("Sum aggregation cannot be executed on attribute type " + attributeType.toString());
}
this.baseAttributes = new Attribute[] { sum };
// Original attribute names
this.baseAttributesInitialValues = new Expression[] { sumInitialValue };
assert baseAttributes.length == baseAttributesInitialValues.length;
}
use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class PassThroughSourceMapper method mapAndProcess.
@Override
protected void mapAndProcess(Object eventObject, InputEventHandler inputEventHandler) throws InterruptedException {
if (eventObject != null) {
if (eventObject instanceof Event[]) {
inputEventHandler.sendEvents((Event[]) eventObject);
} else if (eventObject instanceof Event) {
inputEventHandler.sendEvent((Event) eventObject);
} else if (eventObject instanceof Object[]) {
Event event = new Event(-1, (Object[]) eventObject);
inputEventHandler.sendEvent(event);
} else {
throw new SiddhiAppRuntimeException("Event object must be either Event[], Event or Object[] " + "but found " + eventObject.getClass().getCanonicalName());
}
}
}
use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class IncrementalAggregationProcessor method process.
@Override
public void process(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<>(complexEventChunk.isBatch());
try {
int noOfEvents = 0;
if (latencyTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
latencyTrackerInsert.markIn();
}
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
StreamEvent borrowedEvent = streamEventPool.borrowEvent();
for (int i = 0; i < incomingExpressionExecutors.size(); i++) {
ExpressionExecutor expressionExecutor = incomingExpressionExecutors.get(i);
Object outputData = expressionExecutor.execute(complexEvent);
if (expressionExecutor instanceof IncrementalUnixTimeFunctionExecutor && outputData == null) {
throw new SiddhiAppRuntimeException("Cannot retrieve the timestamp of event");
}
borrowedEvent.setOutputData(outputData, i);
}
streamEventChunk.add(borrowedEvent);
noOfEvents++;
}
incrementalExecutor.execute(streamEventChunk);
if (throughputTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
throughputTrackerInsert.eventsIn(noOfEvents);
}
} finally {
if (latencyTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
latencyTrackerInsert.markOut();
}
}
}
use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class IncrementalExecutor method execute.
@Override
public void execute(ComplexEventChunk streamEventChunk) {
LOG.debug("Event Chunk received by " + this.duration + " incremental executor: " + streamEventChunk.toString());
streamEventChunk.reset();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = (StreamEvent) streamEventChunk.next();
streamEventChunk.remove();
String timeZone = getTimeZone(streamEvent);
long timestamp = getTimestamp(streamEvent, timeZone);
startTimeOfAggregates = IncrementalTimeConverterUtil.getStartTimeOfAggregates(timestamp, duration, timeZone);
if (isRootAndLoadedFromTable) {
// arise when replaying data.
if (timestamp < nextEmitTime) {
continue;
} else {
isRootAndLoadedFromTable = false;
}
}
if (bufferSize > 0 && isRoot) {
try {
mutex.acquire();
dispatchBufferedAggregateEvents(startTimeOfAggregates);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SiddhiAppRuntimeException("Error when dispatching events from buffer", e);
} finally {
mutex.release();
}
if (streamEvent.getType() == ComplexEvent.Type.CURRENT) {
if (!eventOlderThanBuffer) {
processAggregates(streamEvent);
} else if (!ignoreEventsOlderThanBuffer) {
// Incoming event is older than buffer
startTimeOfAggregates = minTimestampInBuffer;
processAggregates(streamEvent);
}
}
} else {
if (timestamp >= nextEmitTime) {
nextEmitTime = IncrementalTimeConverterUtil.getNextEmitTime(timestamp, duration, timeZone);
dispatchAggregateEvents(startTimeOfAggregates);
if (!isProcessingOnExternalTime) {
sendTimerEvent(timeZone);
}
}
if (streamEvent.getType() == ComplexEvent.Type.CURRENT) {
if (nextEmitTime == IncrementalTimeConverterUtil.getNextEmitTime(timestamp, duration, timeZone)) {
// This condition checks whether incoming event belongs to current processing event's time slot
processAggregates(streamEvent);
} else if (!ignoreEventsOlderThanBuffer) {
// Incoming event is older than current processing event.
startTimeOfAggregates = minTimestampInBuffer;
processAggregates(streamEvent);
}
}
}
}
}
use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.
the class TableWindowProcessor method cloneProcessor.
@Override
public Processor cloneProcessor(String key) {
try {
TableWindowProcessor streamProcessor = new TableWindowProcessor(table);
streamProcessor.inputDefinition = inputDefinition;
ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
for (int i = 0; i < attributeExpressionLength; i++) {
innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
}
streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
streamProcessor.attributeExpressionLength = attributeExpressionLength;
streamProcessor.additionalAttributes = additionalAttributes;
streamProcessor.complexEventPopulater = complexEventPopulater;
streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
streamProcessor.start();
return streamProcessor;
} catch (Exception e) {
throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
}
}
Aggregations