X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2Fmapping%2FModuleInfoBundleTracker.java;h=56535e797b46bb7b6be4005f2fe8705c83d51fa3;hb=651de0e48b806dd76e656aa01b929205994cceec;hp=7680f72612cd40468f3758d8030b55b6a6908afc;hpb=9c22929489a127eb844546238d0c9ee2ac8ba89a;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java index 7680f72612..56535e797b 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java @@ -8,17 +8,15 @@ package org.opendaylight.controller.config.manager.impl.osgi.mapping; import static java.lang.String.format; - -import java.io.InputStream; +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.LinkedList; import java.util.List; - -import org.apache.commons.io.IOUtils; import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry; import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.osgi.framework.Bundle; @@ -28,50 +26,47 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Tracks bundles and attempts to retrieve YangModuleInfo. + * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry */ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer>> { - private static final Logger logger = LoggerFactory.getLogger(ModuleInfoBundleTracker.class); - public static final String GET_MODULE_INFO_METHOD = "getModuleInfo"; + private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class); public static final String MODULE_INFO_PROVIDER_PATH_PREFIX = "META-INF/services/"; - private final ModuleInfoBackedContext moduleInfoLoadingStrategy = ModuleInfoBackedContext.create(); - public GeneratedClassLoadingStrategy getModuleInfoLoadingStrategy() { - return moduleInfoLoadingStrategy; + private final ModuleInfoRegistry moduleInfoRegistry; + + public ModuleInfoBundleTracker(ModuleInfoRegistry moduleInfoRegistry) { + this.moduleInfoRegistry = moduleInfoRegistry; } @Override public Collection> addingBundle(Bundle bundle, BundleEvent event) { URL resource = bundle.getEntry(MODULE_INFO_PROVIDER_PATH_PREFIX + YangModelBindingProvider.class.getName()); - + LOG.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource); if(resource==null) { return null; } - List> registrations = new LinkedList<>(); - try (InputStream inputStream = resource.openStream()) { - List lines = IOUtils.readLines(inputStream); - for (String moduleInfoName : lines) { + try { + for (String moduleInfoName : Resources.readLines(resource, Charsets.UTF_8)) { + LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle); YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle); - registrations.add(moduleInfoLoadingStrategy.registerModuleInfo(moduleInfo)); + registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo)); } - - - } catch (Exception e) { - logger.error("Error while reading {}", resource, e); + } catch (IOException e) { + LOG.error("Error while reading {}", resource, e); throw new RuntimeException(e); } + LOG.trace("Got following registrations {}", registrations); return registrations; } @Override public void modifiedBundle(Bundle bundle, BundleEvent event, Collection> object) { - // NOOP } @Override @@ -105,7 +100,7 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer