Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / mapping / ModuleInfoBundleTracker.java
index c6597071f734851f2038f0130f828c599fbb8624..cfbd95a39e8d22256c5474cdb4f409c6cba2b2d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -26,10 +26,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry
+ * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed
+ * into ModuleInfoRegistry.
  */
-public final class ModuleInfoBundleTracker implements AutoCloseable,
-        BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
+public final class ModuleInfoBundleTracker
+        implements AutoCloseable, BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
 
@@ -39,7 +40,7 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
 
     private final RefreshingSCPModuleInfoRegistry moduleInfoRegistry;
 
-    private BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> bundleTracker;
+    private BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> tracker;
     private boolean starting;
 
     public ModuleInfoBundleTracker(final RefreshingSCPModuleInfoRegistry moduleInfoRegistry) {
@@ -50,7 +51,7 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
         LOG.debug("ModuleInfoBundleTracker open starting with bundleTracker {}", bundleTracker);
 
         if (bundleTracker != null) {
-            this.bundleTracker = bundleTracker;
+            this.tracker = bundleTracker;
             starting = true;
             bundleTracker.open();
 
@@ -65,13 +66,14 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
 
     @Override
     public void close() {
-        if (bundleTracker != null) {
-            bundleTracker.close();
-            bundleTracker = null;
+        if (tracker != null) {
+            tracker.close();
+            tracker = null;
         }
     }
 
     @Override
+    @SuppressWarnings("IllegalCatch")
     public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(final Bundle bundle, final BundleEvent event) {
         URL resource = bundle.getEntry(YANG_MODULE_INFO_SERVICE_PATH);
         LOG.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource);
@@ -87,12 +89,12 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
                 registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
             }
 
-            if(!starting) {
+            if (!starting) {
                 moduleInfoRegistry.updateService();
             }
-        } catch (IOException e) {
+        } catch (final IOException e) {
             LOG.error("Error while reading {} from bundle {}", resource, bundle, e);
-        } catch (RuntimeException e) {
+        } catch (final RuntimeException e) {
             LOG.error("Failed to process {} for bundle {}", resource, bundle, e);
         }
 
@@ -106,6 +108,7 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
     }
 
     @Override
+    @SuppressWarnings("IllegalCatch")
     public void removedBundle(final Bundle bundle, final BundleEvent event,
             final Collection<ObjectRegistration<YangModuleInfo>> regs) {
         if (regs == null) {
@@ -115,7 +118,7 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
         for (ObjectRegistration<YangModuleInfo> reg : regs) {
             try {
                 reg.close();
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 LOG.error("Unable to unregister YangModuleInfo {}", reg.getInstance(), e);
             }
         }
@@ -127,23 +130,23 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
 
         if (!YangModelBindingProvider.class.isAssignableFrom(clazz)) {
             errorMessage = logMessage("Class {} does not implement {} in bundle {}", clazz,
-                YangModelBindingProvider.class, bundle);
+                    YangModelBindingProvider.class, bundle);
             throw new IllegalStateException(errorMessage);
         }
         final YangModelBindingProvider instance;
         try {
             Object instanceObj = clazz.newInstance();
             instance = YangModelBindingProvider.class.cast(instanceObj);
-        } catch (InstantiationException e) {
+        } catch (final InstantiationException e) {
             errorMessage = logMessage("Could not instantiate {} in bundle {}, reason {}", moduleInfoClass, bundle, e);
             throw new IllegalStateException(errorMessage, e);
-        } catch (IllegalAccessException e) {
+        } catch (final IllegalAccessException e) {
             errorMessage = logMessage("Illegal access during instantiation of class {} in bundle {}, reason {}",
                     moduleInfoClass, bundle, e);
             throw new IllegalStateException(errorMessage, e);
         }
 
-        try{
+        try {
             return instance.getModuleInfo();
         } catch (NoClassDefFoundError | ExceptionInInitializerError e) {
             throw new IllegalStateException("Error while executing getModuleInfo on " + instance, e);
@@ -153,9 +156,9 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
     private static Class<?> loadClass(final String moduleInfoClass, final Bundle bundle) {
         try {
             return bundle.loadClass(moduleInfoClass);
-        } catch (ClassNotFoundException e) {
-            String errorMessage = logMessage("Could not find class {} in bundle {}, reason {}", moduleInfoClass,
-                bundle, e);
+        } catch (final ClassNotFoundException e) {
+            String errorMessage = logMessage("Could not find class {} in bundle {}, reason {}", moduleInfoClass, bundle,
+                    e);
             throw new IllegalStateException(errorMessage);
         }
     }