Search in sources :

Example 1 with ElephantFetcher

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);
        }
    }
}
Also used : FetcherConfiguration(com.linkedin.drelephant.configurations.fetcher.FetcherConfiguration) Document(org.w3c.dom.Document) FetcherConfigurationData(com.linkedin.drelephant.configurations.fetcher.FetcherConfigurationData) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) ElephantFetcher(com.linkedin.drelephant.analysis.ElephantFetcher)

Aggregations

ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)1 ElephantFetcher (com.linkedin.drelephant.analysis.ElephantFetcher)1 FetcherConfiguration (com.linkedin.drelephant.configurations.fetcher.FetcherConfiguration)1 FetcherConfigurationData (com.linkedin.drelephant.configurations.fetcher.FetcherConfigurationData)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Document (org.w3c.dom.Document)1