use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class StateStreamRuntime method clone.
@Override
public StreamRuntime clone(String key) {
StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiAppContext, metaStateEvent);
stateStreamRuntime.innerStateRuntime = this.innerStateRuntime.clone(key);
for (SingleStreamRuntime singleStreamRuntime : stateStreamRuntime.getSingleStreamRuntimes()) {
ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
if (processStreamReceiver instanceof SequenceMultiProcessStreamReceiver) {
((SequenceMultiProcessStreamReceiver) processStreamReceiver).setStateStreamRuntime(stateStreamRuntime);
} else if (processStreamReceiver instanceof SequenceSingleProcessStreamReceiver) {
((SequenceSingleProcessStreamReceiver) processStreamReceiver).setStateStreamRuntime(stateStreamRuntime);
}
}
((StreamPreStateProcessor) stateStreamRuntime.innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) stateStreamRuntime.innerStateRuntime.getLastProcessor());
return stateStreamRuntime;
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class ConvertFunctionExecutor method init.
@Override
public void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
if (attributeExpressionExecutors.length != 2) {
throw new SiddhiAppValidationException("convert() must have at 2 parameters, attribute and to be " + "converted type");
}
inputType = attributeExpressionExecutors[0].getReturnType();
if (inputType == Attribute.Type.OBJECT) {
throw new SiddhiAppValidationException("1st parameter of convert() cannot be 'object' as " + "it's not supported, it has to be either of (STRING, " + "INT, LONG, FLOAT, DOUBLE, BOOL), but found " + attributeExpressionExecutors[0].getReturnType());
}
if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
throw new SiddhiAppValidationException("2nd parameter of convert() must be 'string' have constant " + "value either of (STRING, INT, LONG, FLOAT, DOUBLE, " + "BOOL), but found " + attributeExpressionExecutors[0].getReturnType());
}
if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
throw new SiddhiAppValidationException("2nd parameter of convert() must have constant value either " + "of (STRING, INT, LONG, FLOAT, DOUBLE, BOOL), but found " + "a variable expression");
}
String type = (String) attributeExpressionExecutors[1].execute(null);
if (Attribute.Type.STRING.toString().equalsIgnoreCase(type)) {
returnType = Attribute.Type.STRING;
} else if (Attribute.Type.BOOL.toString().equalsIgnoreCase(type)) {
returnType = Attribute.Type.BOOL;
} else if (Attribute.Type.DOUBLE.toString().equalsIgnoreCase(type)) {
returnType = Attribute.Type.DOUBLE;
} else if (Attribute.Type.FLOAT.toString().equalsIgnoreCase(type)) {
returnType = Attribute.Type.FLOAT;
} else if (Attribute.Type.INT.toString().equalsIgnoreCase(type)) {
returnType = Attribute.Type.INT;
} else if (Attribute.Type.LONG.toString().equalsIgnoreCase(type)) {
returnType = Attribute.Type.LONG;
} else {
throw new SiddhiAppValidationException("2nd parameter of convert() must have value either of " + "(STRING, INT, LONG, FLOAT, DOUBLE, BOOL), but found '" + type + "'");
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class FunctionExecutor method initExecutor.
public void initExecutor(ExpressionExecutor[] attributeExpressionExecutors, SiddhiAppContext siddhiAppContext, String queryName, ConfigReader configReader) {
this.configReader = configReader;
try {
this.siddhiAppContext = siddhiAppContext;
this.attributeExpressionExecutors = attributeExpressionExecutors;
attributeSize = attributeExpressionExecutors.length;
this.queryName = queryName;
if (elementId == null) {
elementId = "FunctionExecutor-" + siddhiAppContext.getElementIdGenerator().createNewId();
}
siddhiAppContext.getSnapshotService().addSnapshotable(queryName, this);
init(attributeExpressionExecutors, configReader, siddhiAppContext);
} catch (Throwable t) {
throw new SiddhiAppCreationException(t);
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class AbstractStreamProcessor method initProcessor.
public AbstractDefinition initProcessor(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext, boolean outputExpectsExpiredEvents, String queryName, SiddhiElement siddhiElement) {
this.configReader = configReader;
this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
try {
this.inputDefinition = inputDefinition;
this.attributeExpressionExecutors = attributeExpressionExecutors;
this.siddhiAppContext = siddhiAppContext;
this.attributeExpressionLength = attributeExpressionExecutors.length;
this.queryName = queryName;
if (elementId == null) {
elementId = "AbstractStreamProcessor-" + siddhiAppContext.getElementIdGenerator().createNewId();
}
siddhiAppContext.getSnapshotService().addSnapshotable(queryName, this);
this.additionalAttributes = init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
siddhiAppContext.addEternalReferencedHolder(this);
StreamDefinition outputDefinition = StreamDefinition.id(inputDefinition.getId());
outputDefinition.setQueryContextStartIndex(siddhiElement.getQueryContextStartIndex());
outputDefinition.setQueryContextEndIndex(siddhiElement.getQueryContextEndIndex());
for (Attribute attribute : inputDefinition.getAttributeList()) {
outputDefinition.attribute(attribute.getName(), attribute.getType());
}
for (Attribute attribute : additionalAttributes) {
outputDefinition.attribute(attribute.getName(), attribute.getType());
}
return outputDefinition;
} catch (Throwable t) {
throw new SiddhiAppCreationException(t);
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class ExternalTimeBatchWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
if (outputExpectsExpiredEvents) {
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
this.storeExpiredEvents = true;
}
if (attributeExpressionExecutors.length >= 2 && attributeExpressionExecutors.length <= 5) {
if (!(attributeExpressionExecutors[0] instanceof VariableExpressionExecutor)) {
throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be a" + " variable, but found " + attributeExpressionExecutors[0].getClass());
}
if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.LONG) {
throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be " + "type long, but found " + attributeExpressionExecutors[0].getReturnType());
}
timestampExpressionExecutor = (VariableExpressionExecutor) attributeExpressionExecutors[0];
if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
timeToKeep = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
} else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
timeToKeep = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 2nd parameter windowTime " + "should be either int or long, but found " + attributeExpressionExecutors[1].getReturnType());
}
if (attributeExpressionExecutors.length >= 3) {
isStartTimeEnabled = true;
if ((attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor)) {
if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.INT) {
startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
} else if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.LONG) {
startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter " + "startTime should either be a constant (of type int or long) or an attribute (of type" + " long), but found " + attributeExpressionExecutors[2].getReturnType());
}
} else if (attributeExpressionExecutors[2].getReturnType() != Attribute.Type.LONG) {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter startTime " + "should either be a constant (of type int or long) or an attribute (of type long), but " + "found " + attributeExpressionExecutors[2].getReturnType());
} else {
startTimeAsVariable = attributeExpressionExecutors[2];
}
}
if (attributeExpressionExecutors.length >= 4) {
if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.INT) {
schedulerTimeout = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
} else if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.LONG) {
schedulerTimeout = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 4th parameter timeout " + "should be either int or long, but found " + attributeExpressionExecutors[3].getReturnType());
}
}
if (attributeExpressionExecutors.length == 5) {
if (attributeExpressionExecutors[4].getReturnType() == Attribute.Type.BOOL) {
replaceTimestampWithBatchEndTime = Boolean.parseBoolean(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[4]).getValue()));
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window's 5th parameter " + "replaceTimestampWithBatchEndTime should be bool, but found " + attributeExpressionExecutors[4].getReturnType());
}
}
} else {
throw new SiddhiAppValidationException("ExternalTimeBatch window should only have two to five " + "parameters (<long> timestamp, <int|long|time> windowTime, <long> startTime, <int|long|time> " + "timeout, <bool> replaceTimestampWithBatchEndTime), but found " + attributeExpressionExecutors.length + " input attributes");
}
if (schedulerTimeout > 0) {
if (expiredEventChunk == null) {
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
}
}
}
Aggregations