Search in sources :

Example 1 with Option

use of org.ballerinalang.siddhi.core.util.transport.Option in project ballerina by ballerina-lang.

the class DefinitionParserHelper method constructOutputGroupDeterminer.

private static OutputGroupDeterminer constructOutputGroupDeterminer(OptionHolder transportOptHolder, OptionHolder distributedOptHolder, StreamDefinition streamDef, int destinationCount) {
    OutputGroupDeterminer groupDeterminer = null;
    if (distributedOptHolder != null) {
        String strategy = distributedOptHolder.validateAndGetStaticValue(SiddhiConstants.DISTRIBUTION_STRATEGY_KEY);
        if (strategy.equalsIgnoreCase(SiddhiConstants.DISTRIBUTION_STRATEGY_PARTITIONED)) {
            String partitionKeyField = distributedOptHolder.validateAndGetStaticValue(SiddhiConstants.PARTITION_KEY_FIELD_KEY);
            int partitioningFieldIndex = streamDef.getAttributePosition(partitionKeyField);
            groupDeterminer = new PartitionedGroupDeterminer(partitioningFieldIndex, destinationCount);
        }
    }
    if (groupDeterminer == null) {
        List<Option> dynamicTransportOptions = new ArrayList<Option>(transportOptHolder.getDynamicOptionsKeys().size());
        for (String option : transportOptHolder.getDynamicOptionsKeys()) {
            dynamicTransportOptions.add(transportOptHolder.validateAndGetOption(option));
        }
        if (dynamicTransportOptions.size() > 0) {
            groupDeterminer = new DynamicOptionGroupDeterminer(dynamicTransportOptions);
        }
    }
    return groupDeterminer;
}
Also used : PartitionedGroupDeterminer(org.ballerinalang.siddhi.core.stream.output.sink.PartitionedGroupDeterminer) ArrayList(java.util.ArrayList) Option(org.ballerinalang.siddhi.core.util.transport.Option) OutputGroupDeterminer(org.ballerinalang.siddhi.core.stream.output.sink.OutputGroupDeterminer) DynamicOptionGroupDeterminer(org.ballerinalang.siddhi.core.stream.output.sink.DynamicOptionGroupDeterminer)

Example 2 with Option

use of org.ballerinalang.siddhi.core.util.transport.Option in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.query.api.exception.AttributeNotExistException) SiddhiAppValidationException(org.ballerinalang.siddhi.query.api.exception.SiddhiAppValidationException) Option(org.ballerinalang.siddhi.core.util.transport.Option)

Aggregations

Option (org.ballerinalang.siddhi.core.util.transport.Option)2 ArrayList (java.util.ArrayList)1 DynamicOptionGroupDeterminer (org.ballerinalang.siddhi.core.stream.output.sink.DynamicOptionGroupDeterminer)1 OutputGroupDeterminer (org.ballerinalang.siddhi.core.stream.output.sink.OutputGroupDeterminer)1 PartitionedGroupDeterminer (org.ballerinalang.siddhi.core.stream.output.sink.PartitionedGroupDeterminer)1 AttributeNotExistException (org.ballerinalang.siddhi.query.api.exception.AttributeNotExistException)1 SiddhiAppValidationException (org.ballerinalang.siddhi.query.api.exception.SiddhiAppValidationException)1