use of com.linkedin.drelephant.analysis.ElephantFetcher in project dr-elephant by linkedin.
the class ElephantContext method loadFetchers.
/**
* Load all the fetchers configured in FetcherConf.xml
*/
private void loadFetchers() {
Document document = Utils.loadXMLDoc(FETCHERS_CONF);
_fetchersConfData = new FetcherConfiguration(document.getDocumentElement()).getFetchersConfigurationData();
for (FetcherConfigurationData data : _fetchersConfData) {
try {
Class<?> fetcherClass = Class.forName(data.getClassName());
Object instance = fetcherClass.getConstructor(FetcherConfigurationData.class).newInstance(data);
if (!(instance instanceof ElephantFetcher)) {
throw new IllegalArgumentException("Class " + fetcherClass.getName() + " is not an implementation of " + ElephantFetcher.class.getName());
}
ApplicationType type = data.getAppType();
if (_typeToFetcher.get(type) == null) {
_typeToFetcher.put(type, (ElephantFetcher) instance);
}
logger.info("Load Fetcher : " + data.getClassName());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not find class " + data.getClassName(), e);
} catch (InstantiationException e) {
throw new RuntimeException("Could not instantiate class " + data.getClassName(), e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not access constructor for class" + data.getClassName(), e);
} catch (RuntimeException e) {
throw new RuntimeException(data.getClassName() + " is not a valid Fetcher class.", e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Could not invoke class " + data.getClassName(), e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Could not find constructor for class " + data.getClassName(), e);
}
}
}
Aggregations