Switch to StandardCharsets
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / ModuleFactoryBundleTracker.java
index cd72a73ecf3455365c35ae1a74b71d62654f9763..83d144d4aeae3adb4160c7bd86c0b2a1588cb8d0 100644 (file)
@@ -9,10 +9,10 @@ package org.opendaylight.controller.config.manager.impl.osgi;
 
 import static java.lang.String.format;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
 import com.google.common.io.Resources;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleEvent;
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
  * the services are unregistered automatically.
  * Code based on http://www.toedter.com/blog/?p=236
  */
-public class ModuleFactoryBundleTracker implements BundleTrackerCustomizer<Object> {
+public class ModuleFactoryBundleTracker implements BundleTrackerCustomizer<Boolean> {
     private final BlankTransactionServiceTracker blankTransactionServiceTracker;
     private static final Logger LOG = LoggerFactory.getLogger(ModuleFactoryBundleTracker.class);
 
@@ -39,32 +39,37 @@ public class ModuleFactoryBundleTracker implements BundleTrackerCustomizer<Objec
     }
 
     @Override
-    public Object addingBundle(Bundle bundle, BundleEvent event) {
+    public Boolean addingBundle(Bundle bundle, BundleEvent event) {
         URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
         LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}",
                 bundle, resource, event);
         if (resource != null) {
             try {
-                for (String factoryClassName : Resources.readLines(resource, Charsets.UTF_8)) {
+                for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
                     registerFactory(factoryClassName, bundle);
                 }
+
+                return Boolean.TRUE;
             } catch (IOException e) {
                 LOG.error("Error while reading {}", resource, e);
                 throw new RuntimeException(e);
             }
         }
-        return bundle;
+
+        return Boolean.FALSE;
     }
 
     @Override
-    public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
+    public void modifiedBundle(Bundle bundle, BundleEvent event, Boolean hasFactory) {
         // NOOP
     }
 
     @Override
-    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
-        // workaround for service tracker not getting removed service event
-        blankTransactionServiceTracker.blankTransaction();
+    public void removedBundle(Bundle bundle, BundleEvent event, Boolean hasFactory) {
+        if(hasFactory) {
+            // workaround for service tracker not getting removed service event
+            blankTransactionServiceTracker.blankTransactionSync();
+        }
     }
 
     @VisibleForTesting