/** * Extracts the declared Hadoop configuration method (methods with * {@literal @}HadoopConf annotations) from a class. * * @param clazz The class to extract conf method declarations from. * @param includeParentClasses If true, also includes declared methods in the super classes. * @return The list of configuration methods declared. */ public static List<ConfigurationMethod> extractDeclaredMethods( Class<?> clazz, boolean includeParentClasses) { final List<ConfigurationMethod> methods = new ArrayList<ConfigurationMethod>(); do { for (Method method : clazz.getDeclaredMethods()) { final HadoopConf annotation = method.getAnnotation(HadoopConf.class); if (null != annotation) { methods.add(new ConfigurationMethod(method, annotation)); } } clazz = clazz.getSuperclass(); } while (includeParentClasses && null != clazz); return methods; } }
final String key = getKey(); if (null == key) { throw new HadoopConfigurationException("Missing 'key' attribute of @HadoopConf on " try { if (boolean.class == parameterType) { mMethod.invoke(instance, conf.getBoolean(key, Boolean.parseBoolean(getDefault()))); } else if (float.class == parameterType) { mMethod.invoke(instance, conf.getFloat(key, Float.parseFloat(getDefault()))); } else if (double.class == parameterType) { mMethod.invoke(instance, conf.getFloat(key, Float.parseFloat(getDefault()))); } else if (int.class == parameterType) { mMethod.invoke(instance, conf.getInt(key, Integer.parseInt(getDefault()))); } else if (long.class == parameterType) { mMethod.invoke(instance, conf.getLong(key, Long.parseLong(getDefault()))); } else if (parameterType.isAssignableFrom(String.class)) { mMethod.invoke(instance, conf.get(key, getDefault())); } else if (parameterType.isAssignableFrom(Collection.class)) { mMethod.invoke(instance, conf.getStringCollection(key)); mMethod.invoke(instance, getDefault());
for (ConfigurationMethod method : methods) { try { method.call(instance, conf); } catch (IllegalAccessException e) { throw new HadoopConfigurationException(e);