use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class TimeBatchWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
this.siddhiAppContext = siddhiAppContext;
if (outputExpectsExpiredEvents) {
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
}
if (attributeExpressionExecutors.length == 1) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else if (attributeExpressionExecutors.length == 2) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
// start time
isStartTimeEnabled = true;
if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
} else {
startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
}
} else {
throw new SiddhiAppValidationException("Time window should only have one or two parameters. " + "(<int|long|time> windowTime), but found " + attributeExpressionExecutors.length + " input " + "attributes");
}
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class TimeLengthWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.siddhiAppContext = siddhiAppContext;
expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
if (attributeExpressionExecutors.length == 2) {
length = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("TimeLength window's first parameter attribute should " + "be either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("TimeLength window should have constant parameter " + "attributes but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else {
throw new SiddhiAppValidationException("TimeLength window should only have two parameters (<int> " + "windowTime,<int> windowLength), but found " + attributeExpressionExecutors.length + " input " + "attributes");
}
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class TimeWindowProcessor method init.
@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
this.siddhiAppContext = siddhiAppContext;
this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
if (attributeExpressionExecutors.length == 1) {
if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
} else {
throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
}
} else {
throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
}
} else {
throw new SiddhiAppValidationException("Time window should only have one parameter (<int|long|time> " + "windowTime), but found " + attributeExpressionExecutors.length + " input attributes");
}
}
use of org.wso2.balana.ctx.Attribute 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);
}
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class CountIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
Attribute count;
Expression countInitialValue;
// Since we set the initial value of count, we can simply set it as long
// However, since count is summed internally (in avg incremental calculation),
// ensure that either double or long is used here (since return value of sum is long or
// double. Long is chosen here)
count = new Attribute("AGG_COUNT", Attribute.Type.LONG);
countInitialValue = Expression.value(1L);
this.baseAttributes = new Attribute[] { count };
this.baseAttributesInitialValues = new Expression[] { countInitialValue };
assert baseAttributes.length == baseAttributesInitialValues.length;
}
Aggregations