Search in sources :

Example 1 with HashPartition

use of co.cask.cdap.api.annotation.HashPartition in project cdap by caskdata.

the class FlowUtils method createConsumerGroupConfig.

/**
   * Creates a {@link ConsumerGroupConfig} by inspecting the given process method.
   */
public static ConsumerGroupConfig createConsumerGroupConfig(long groupId, int groupSize, Method processMethod) {
    // Determine input queue partition type
    HashPartition hashPartition = processMethod.getAnnotation(HashPartition.class);
    RoundRobin roundRobin = processMethod.getAnnotation(RoundRobin.class);
    DequeueStrategy strategy = DequeueStrategy.FIFO;
    String hashKey = null;
    Preconditions.checkArgument(!(hashPartition != null && roundRobin != null), "Only one strategy allowed for process() method: %s", processMethod.getName());
    if (hashPartition != null) {
        strategy = DequeueStrategy.HASH;
        hashKey = hashPartition.value();
        Preconditions.checkArgument(!hashKey.isEmpty(), "Partition key cannot be empty: %s", processMethod.getName());
    } else if (roundRobin != null) {
        strategy = DequeueStrategy.ROUND_ROBIN;
    }
    return new ConsumerGroupConfig(groupId, groupSize, strategy, hashKey);
}
Also used : DequeueStrategy(co.cask.cdap.data2.queue.DequeueStrategy) RoundRobin(co.cask.cdap.api.annotation.RoundRobin) HashPartition(co.cask.cdap.api.annotation.HashPartition) ConsumerGroupConfig(co.cask.cdap.data2.queue.ConsumerGroupConfig)

Aggregations

HashPartition (co.cask.cdap.api.annotation.HashPartition)1 RoundRobin (co.cask.cdap.api.annotation.RoundRobin)1 ConsumerGroupConfig (co.cask.cdap.data2.queue.ConsumerGroupConfig)1 DequeueStrategy (co.cask.cdap.data2.queue.DequeueStrategy)1