@@ -0,0 +1,2806 @@
+/*%0A * Copyright 2015 Rackspace%0A *%0A *    Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *    you may not use this file except in compliance with the License.%0A *    You may obtain a copy of the License at%0A *%0A *        http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *    Unless required by applicable law or agreed to in writing, software%0A *    distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *    See the License for the specific language governing permissions and%0A *    limitations under the License.%0A */%0A%0Apackage com.rackspacecloud.blueflood.utils;%0A%0Aimport com.rackspacecloud.blueflood.io.DiscoveryIO;%0Aimport com.rackspacecloud.blueflood.service.Configuration;%0Aimport com.rackspacecloud.blueflood.service.CoreConfig;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.util.List;%0A%0Apublic class DiscoveryModuleLoader %7B%0A    private static final Logger log = LoggerFactory.getLogger(DiscoveryModuleLoader.class);%0A    private static DiscoveryIO discoveryInstance;%0A%0A%0A    public static synchronized void loadDiscoveryModule() %7B%0A        if (discoveryInstance != null) %7B%0A            log.warn(%22Discovery module %25s already loaded%22, discoveryInstance.getClass());%0A            return;%0A        %7D%0A        List%3CString%3E modules = Configuration.getInstance().getListProperty(CoreConfig.DISCOVERY_MODULES);%0A%0A        if (!modules.isEmpty() && modules.size() != 1) %7B%0A            throw new RuntimeException(%22Cannot load query service with more than one discovery module%22);%0A        %7D%0A%0A        ClassLoader classLoader = DiscoveryIO.class.getClassLoader();%0A        for (String module : modules) %7B%0A            log.info(%22Loading metric discovery module %22 + module);%0A            try %7B%0A                Class discoveryClass = classLoader.loadClass(module);%0A                discoveryInstance = (DiscoveryIO) discoveryClass.newInstance();%0A                log.info(%22Registering metric discovery module %22 + module);%0A            %7D catch (InstantiationException e) %7B%0A                log.error(%22Unable to create instance of metric discovery class for: %22 + module, e);%0A            %7D catch (IllegalAccessException e) %7B%0A                log.error(%22Error starting metric discovery module: %22 + module, e);%0A            %7D catch (ClassNotFoundException e) %7B%0A                log.error(%22Unable to locate metric discovery module: %22 + module, e);%0A            %7D catch (RuntimeException e) %7B%0A                log.error(%22Error starting metric discovery module: %22 + module, e);%0A            %7D catch (Throwable e) %7B%0A                log.error(%22Error starting metric discovery module: %22 + module, e);%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A    public static DiscoveryIO getDiscoveryInstance() %7B%0A        return discoveryInstance;%0A    %7D%0A%7D%0A

Move discovery module loader to core, to avoid cyclic dependencies