use of co.cask.cdap.internal.lang.MethodVisitor in project cdap by caskdata.
the class FlowUtils method addConsumerGroup.
/**
* Finds all consumer group for the given queue from the given flowlet.
*/
private static void addConsumerGroup(final QueueSpecification queueSpec, final Type flowletType, final long groupId, final int groupSize, final SchemaGenerator schemaGenerator, final Collection<ConsumerGroupConfig> groupConfigs) {
final Set<FlowletMethod> seenMethods = Sets.newHashSet();
Reflections.visit(null, flowletType, new MethodVisitor() {
@Override
public void visit(Object instance, Type inspectType, Type declareType, Method method) throws Exception {
if (!seenMethods.add(FlowletMethod.create(method, inspectType))) {
// up the class hierarchy.
return;
}
ProcessInput processInputAnnotation = method.getAnnotation(ProcessInput.class);
if (processInputAnnotation == null) {
// Consumer has to be process method
return;
}
Set<String> inputNames = Sets.newHashSet(processInputAnnotation.value());
if (inputNames.isEmpty()) {
// If there is no input name, it would be ANY_INPUT
inputNames.add(FlowletDefinition.ANY_INPUT);
}
TypeToken<?> inspectTypeToken = TypeToken.of(inspectType);
TypeToken<?> dataType = inspectTypeToken.resolveType(method.getGenericParameterTypes()[0]);
// For batch mode and if the parameter is Iterator, need to get the actual data type from the Iterator.
if (method.isAnnotationPresent(Batch.class) && Iterator.class.equals(dataType.getRawType())) {
Preconditions.checkArgument(dataType.getType() instanceof ParameterizedType, "Only ParameterizedType is supported for batch Iterator.");
dataType = inspectTypeToken.resolveType(((ParameterizedType) dataType.getType()).getActualTypeArguments()[0]);
}
Schema schema = schemaGenerator.generate(dataType.getType());
if (queueSpec.getInputSchema().equals(schema) && (inputNames.contains(queueSpec.getQueueName().getSimpleName()) || inputNames.contains(FlowletDefinition.ANY_INPUT))) {
groupConfigs.add(createConsumerGroupConfig(groupId, groupSize, method));
}
}
});
}
Aggregations