Refactor shutdown-impl: add parameter to RPC, remove secret validation and masking.
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / ExtenderBundleTracker.java
index 22a1216959f5879624eb74923316ee910f0d6352..b55f3135d26cfbf1d583c0d7259905b6e9380d31 100644 (file)
@@ -18,38 +18,35 @@ import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.util.tracker.BundleTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * OSGi extender that listens for bundle activation events. Reads file
  * META-INF/services/org.opendaylight.controller.config.spi.ModuleFactory, each
  * line should contain an implementation of ModuleFactory interface. Creates new
  * instance with default constructor and registers it into OSGi service
  * registry. There is no need for listening for implementing removedBundle as
- * the services are unregistered automatically. Code based on
- * http://www.toedter.com/blog/?p=236
+ * the services are unregistered automatically.
+ * Code based on http://www.toedter.com/blog/?p=236
  */
-
 public class ExtenderBundleTracker extends BundleTracker<Object> {
+    private final BlankTransactionServiceTracker blankTransactionServiceTracker;
+    private static final Logger logger = LoggerFactory.getLogger(ExtenderBundleTracker.class);
 
-    private static final Logger logger = LoggerFactory
-            .getLogger(ExtenderBundleTracker.class);
-
-    public ExtenderBundleTracker(BundleContext context) {
+    public ExtenderBundleTracker(BundleContext context, BlankTransactionServiceTracker blankTransactionServiceTracker) {
         super(context, Bundle.ACTIVE, null);
+        this.blankTransactionServiceTracker = blankTransactionServiceTracker;
         logger.trace("Registered as extender with context {}", context);
     }
 
     @Override
     public Object addingBundle(Bundle bundle, BundleEvent event) {
-        URL resource = bundle.getEntry("META-INF/services/"
-                + ModuleFactory.class.getName());
-        logger.trace(
-                "Got addingBundle event of bundle {}, resource {}, event {}",
+        URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
+        logger.trace("Got addingBundle event of bundle {}, resource {}, event {}",
                 bundle, resource, event);
         if (resource != null) {
             try (InputStream inputStream = resource.openStream()) {
@@ -58,29 +55,22 @@ public class ExtenderBundleTracker extends BundleTracker<Object> {
                     registerFactory(factoryClassName, bundle);
                 }
             } catch (Exception e) {
-                logger.error("Error while reading {}, stopping bundle {}",
-                        resource, bundle, e);
-                stopBundleQuietly(bundle);
+                logger.error("Error while reading {}", resource, e);
                 throw new RuntimeException(e);
             }
-
         }
         return bundle;
     }
 
-    private static void stopBundleQuietly(Bundle bundle) {
-        try {
-            bundle.stop();
-        } catch (BundleException e2) {
-            logger.warn(
-                    "Ignoring fact that bundle.stop failed on {}, reason {}",
-                    bundle, e2.toString());
-        }
+    @Override
+    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
+        super.removedBundle(bundle,event,object);
+        // workaround for service tracker not getting removed service event
+        blankTransactionServiceTracker.blankTransaction();
     }
 
     // TODO:test
-    private static ServiceRegistration<?> registerFactory(
-            String factoryClassName, Bundle bundle) {
+    private static ServiceRegistration<?> registerFactory(String factoryClassName, Bundle bundle) {
         String errorMessage;
         try {
             Class<?> clazz = bundle.loadClass(factoryClassName);