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);
}
Aggregations