Bump odlparent to 6.0.0
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / ext / SpecificReferenceListMetadata.java
index 1aef1411290481fc2cbc5133d7def0642ea861ac..0412f00a7afb94132183271f6afdadeb640a4c7a 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.controller.blueprint.ext;
 
-import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
 import com.google.common.io.Resources;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -52,7 +53,7 @@ class SpecificReferenceListMetadata extends AbstractDependentComponentFactoryMet
     private volatile BundleTracker<Bundle> bundleTracker;
     private volatile ServiceTracker<Object, Object> serviceTracker;
 
-    SpecificReferenceListMetadata(String id, String interfaceName) {
+    SpecificReferenceListMetadata(final String id, final String interfaceName) {
         super(id);
         this.interfaceName = interfaceName;
         serviceResourcePath = "META-INF/services/" + interfaceName;
@@ -60,72 +61,74 @@ class SpecificReferenceListMetadata extends AbstractDependentComponentFactoryMet
 
     @Override
     protected void startTracking() {
-        BundleTrackerCustomizer<Bundle> bundleListener = new BundleTrackerCustomizer<Bundle>() {
+        BundleTrackerCustomizer<Bundle> bundleListener = new BundleTrackerCustomizer<>() {
             @Override
-            public Bundle addingBundle(Bundle bundle, BundleEvent event) {
+            public Bundle addingBundle(final Bundle bundle, final BundleEvent event) {
                 bundleAdded(bundle);
                 return bundle;
             }
 
             @Override
-            public void modifiedBundle(Bundle bundle, BundleEvent event, Bundle object) {
+            public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Bundle object) {
             }
 
             @Override
-            public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) {
+            public void removedBundle(final Bundle bundle, final BundleEvent event, final Bundle object) {
             }
         };
 
-        bundleTracker = new BundleTracker<>(container().getBundleContext(), Bundle.RESOLVED | Bundle.STARTING |
-                Bundle.STOPPING | Bundle.ACTIVE, bundleListener);
+        bundleTracker = new BundleTracker<>(container().getBundleContext(), Bundle.RESOLVED | Bundle.STARTING
+                Bundle.STOPPING | Bundle.ACTIVE, bundleListener);
 
         // This will get the list of all current RESOLVED+ bundles.
         bundleTracker.open();
 
-        if(expectedServiceTypes.isEmpty()) {
+        if (expectedServiceTypes.isEmpty()) {
             setSatisfied();
             return;
         }
 
-        ServiceTrackerCustomizer<Object, Object> serviceListener = new ServiceTrackerCustomizer<Object, Object>() {
+        ServiceTrackerCustomizer<Object, Object> serviceListener = new ServiceTrackerCustomizer<>() {
             @Override
-            public Object addingService(ServiceReference<Object> reference) {
+            public Object addingService(final ServiceReference<Object> reference) {
                 return serviceAdded(reference);
             }
 
             @Override
-            public void modifiedService(ServiceReference<Object> reference, Object service) {
+            public void modifiedService(final ServiceReference<Object> reference, final Object service) {
             }
 
             @Override
-            public void removedService(ServiceReference<Object> reference, Object service) {
+            public void removedService(final ServiceReference<Object> reference, final Object service) {
                 container().getBundleContext().ungetService(reference);
             }
         };
 
-        setDependendencyDesc(interfaceName + " services with types " + expectedServiceTypes);
+        setDependencyDesc(interfaceName + " services with types " + expectedServiceTypes);
 
         serviceTracker = new ServiceTracker<>(container().getBundleContext(), interfaceName, serviceListener);
         serviceTracker.open();
     }
 
-    private void bundleAdded(Bundle bundle) {
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
+    private void bundleAdded(final Bundle bundle) {
         URL resource = bundle.getEntry(serviceResourcePath);
-        if(resource == null) {
+        if (resource == null) {
             return;
         }
 
         LOG.debug("{}: Found {} resource in bundle {}", logName(), resource, bundle.getSymbolicName());
 
         try {
-            for(String line : Resources.readLines(resource, Charsets.UTF_8)) {
+            for (String line : Resources.readLines(resource, StandardCharsets.UTF_8)) {
                 int ci = line.indexOf('#');
-                if(ci >= 0) {
+                if (ci >= 0) {
                     line = line.substring(0, ci);
                 }
 
                 line = line.trim();
-                if(line.isEmpty()) {
+                if (line.isEmpty()) {
                     continue;
                 }
 
@@ -133,49 +136,51 @@ class SpecificReferenceListMetadata extends AbstractDependentComponentFactoryMet
                 LOG.debug("{}: Retrieved service type {}", logName(), serviceType);
                 expectedServiceTypes.add(serviceType);
             }
-        } catch(IOException e) {
+        } catch (final IOException e) {
             setFailure(String.format("%s: Error reading resource %s from bundle %s", logName(), resource,
                     bundle.getSymbolicName()), e);
         }
     }
 
-    private Object serviceAdded(ServiceReference<Object> reference) {
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
+    private Object serviceAdded(final ServiceReference<Object> reference) {
         Object service = container().getBundleContext().getService(reference);
-        Object serviceType = reference.getProperty(OpendaylightNamespaceHandler.TYPE_ATTR);
+        String serviceType = (String) reference.getProperty(OpendaylightNamespaceHandler.TYPE_ATTR);
 
         LOG.debug("{}: Service type {} added from bundle {}", logName(), serviceType,
                 reference.getBundle().getSymbolicName());
 
-        if(serviceType == null) {
+        if (serviceType == null) {
             LOG.error("{}: Missing OSGi service property '{}' for service interface {} in bundle {}", logName(),
                     OpendaylightNamespaceHandler.TYPE_ATTR, interfaceName,  reference.getBundle().getSymbolicName());
             return service;
         }
 
-        if(!expectedServiceTypes.contains(serviceType)) {
-            LOG.error("{}: OSGi service property '{}' for service interface {} in bundle {} was not found in the " +
-                    "expected service types {} obtained via {} bundle resources. Is the bundle resource missing or the service type misspelled?",
-                    logName(), OpendaylightNamespaceHandler.TYPE_ATTR, interfaceName, reference.getBundle().getSymbolicName(),
-                    expectedServiceTypes, serviceResourcePath);
+        if (!expectedServiceTypes.contains(serviceType)) {
+            LOG.error("{}: OSGi service property '{}' for service interface {} in bundle {} was not found in the "
+                    + "expected service types {} obtained via {} bundle resources. Is the bundle resource missing or "
+                    + "the service type misspelled?", logName(), OpendaylightNamespaceHandler.TYPE_ATTR, interfaceName,
+                    reference.getBundle().getSymbolicName(), expectedServiceTypes, serviceResourcePath);
             return service;
         }
 
         // If already satisfied, meaning we got all initial services, then a new bundle must've been
         // dynamically installed or a prior service's blueprint container was restarted, in which case we
         // restart our container.
-        if(isSatisfied()) {
+        if (isSatisfied()) {
             restartContainer();
         } else {
-            retrievedServiceTypes.add(serviceType.toString());
+            retrievedServiceTypes.add(serviceType);
             retrievedServices.add(service);
 
-            if(retrievedServiceTypes.equals(expectedServiceTypes)) {
+            if (retrievedServiceTypes.equals(expectedServiceTypes)) {
                 LOG.debug("{}: Got all expected service types", logName());
                 setSatisfied();
             } else {
                 Set<String> remaining = new HashSet<>(expectedServiceTypes);
                 remaining.removeAll(retrievedServiceTypes);
-                setDependendencyDesc(interfaceName + " services with types " + remaining);
+                setDependencyDesc(interfaceName + " services with types " + remaining);
             }
         }
 
@@ -190,21 +195,21 @@ class SpecificReferenceListMetadata extends AbstractDependentComponentFactoryMet
 
         LOG.debug("{}: create returning service list {}", logName(), retrievedServices);
 
-        synchronized(retrievedServices) {
+        synchronized (retrievedServices) {
             return ImmutableList.copyOf(retrievedServices);
         }
     }
 
     @Override
-    public void destroy(Object instance) {
+    public void destroy(final Object instance) {
         super.destroy(instance);
 
-        if(bundleTracker != null) {
+        if (bundleTracker != null) {
             bundleTracker.close();
             bundleTracker = null;
         }
 
-        if(serviceTracker != null) {
+        if (serviceTracker != null) {
             serviceTracker.close();
             serviceTracker = null;
         }