Fixing warnings in the sal sub-project.
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / ComponentActivatorAbstractBase.java
index d04e67b304666c88c840e7733aeeb53d5e29a1d2..969aa630a1519f712e24af8ef0e0cd0025022635 100644 (file)
@@ -32,7 +32,6 @@ import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.ServiceDependency;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,24 +44,25 @@ abstract public class ComponentActivatorAbstractBase implements
         BundleActivator, IContainerAware {
     Logger logger = LoggerFactory
             .getLogger(ComponentActivatorAbstractBase.class);
-    private ServiceRegistration containerAwareRegistration;
     private DependencyManager dm;
     private ConcurrentMap<ImmutablePair<String, Object>, Component> dbInstances = (ConcurrentMap<ImmutablePair<String, Object>, Component>) new ConcurrentHashMap<ImmutablePair<String, Object>, Component>();
     private ConcurrentMap<Object, Component> dbGlobalInstances = (ConcurrentMap<Object, Component>) new ConcurrentHashMap<Object, Component>();
 
     /**
-     * Abstract method that MUST be implemented by the derived class
-     * that wants to activate the Component bundle in a container. Here
-     * customization for the component are expected
+     * Method that should be overriden by the derived class for customization
+     * during activation of the Component bundle in a container.
      */
-    abstract protected void init();
+    protected void init() {
+
+    }
 
     /**
-     * Abstract method that MUST be implemented by the derived class
-     * that wants to DE-activate the Component bundle in a container. Here
-     * customization for the component are expected
+     * Method that should be overriden by the derived class for customization
+     * during DE-activation of the Component bundle in a container.
      */
-    abstract protected void destroy();
+    public void destroy() {
+
+    }
 
     /**
      * Method which tells how many implementations are supported by
@@ -154,6 +154,11 @@ abstract public class ComponentActivatorAbstractBase implements
 
         @Override
         public void stopped(Component component) {
+            // do nothing
+        }
+
+        @Override
+        public void stopping(Component component) {
             if (component == null) {
                 return;
             }
@@ -162,11 +167,6 @@ abstract public class ComponentActivatorAbstractBase implements
                     { Component.class }, {} }, new Object[][] { { component },
                     {} });
         }
-
-        @Override
-        public void stopping(Component component) {
-            // do nothing
-        }
     }
 
     /**
@@ -178,7 +178,7 @@ abstract public class ComponentActivatorAbstractBase implements
     public void containerCreate(String containerName) {
         try {
             Object[] imps = getImplementations();
-            logger.trace("Creating instance " + containerName);
+            logger.trace("Creating instance {}", containerName);
             if (imps != null) {
                 for (int i = 0; i < imps.length; i++) {
                     ImmutablePair<String, Object> key = new ImmutablePair<String, Object>(
@@ -193,15 +193,15 @@ abstract public class ComponentActivatorAbstractBase implements
                         // Set the implementation so the component can manage
                         // its lifecycle
                         if (c.getService() == null) {
-                            logger
-                                    .trace("Setting implementation to:"
-                                            + imps[i]);
+                            logger.trace("Setting implementation to: {}",
+                                          imps[i]);
                             c.setImplementation(imps[i]);
                         }
 
                         //Set the service properties to include the containerName
                         //in the service, that is fundamental for supporting
                         //multiple services just distinguished via a container
+                        @SuppressWarnings("unchecked")
                         Dictionary<String, String> serviceProps = c
                                 .getServiceProperties();
                         if (serviceProps != null) {
@@ -246,7 +246,7 @@ abstract public class ComponentActivatorAbstractBase implements
     public void containerDestroy(String containerName) {
         try {
             Object[] imps = getImplementations();
-            logger.trace("Destroying instance " + containerName);
+            logger.trace("Destroying instance {}", containerName);
             if (imps != null) {
                 for (int i = 0; i < imps.length; i++) {
                     ImmutablePair<String, Object> key = new ImmutablePair<String, Object>(
@@ -288,7 +288,7 @@ abstract public class ComponentActivatorAbstractBase implements
         StringBuffer buffer = new StringBuffer();
 
         for (int i = 0; i < stack.length; i++) {
-            buffer.append("\n\t" + stack[i].toString());
+            buffer.append("\n\t").append(stack[i].toString());
         }
         return buffer.toString();
     }
@@ -330,8 +330,8 @@ abstract public class ComponentActivatorAbstractBase implements
                             // Set the implementation so the component
                             // can manage its lifesycle
                             if (c.getService() == null) {
-                                logger.trace("Setting implementation to:"
-                                        imps[i]);
+                                logger.trace("Setting implementation to: {}",
+                                        imps[i]);
                                 c.setImplementation(imps[i]);
                             }
 
@@ -359,7 +359,7 @@ abstract public class ComponentActivatorAbstractBase implements
             }
 
             // Register with OSGi the provider for the service IContainerAware
-            this.containerAwareRegistration = context.registerService(
+            context.registerService(
                     IContainerAware.class.getName(), this, null);
 
             // Now call the derived class init function
@@ -397,8 +397,8 @@ abstract public class ComponentActivatorAbstractBase implements
                 try {
                     Component c = this.dbInstances.get(key);
                     if (c != null) {
-                        logger.trace("Remove component on container:"
-                                + key.getLeft() + " Object:" + key.getRight());
+                        logger.trace("Remove component on container: {} Object: {}",
+                                key.getLeft(), key.getRight());
                         this.dm.remove(c);
                     }
                 } catch (Exception nex) {
@@ -415,7 +415,7 @@ abstract public class ComponentActivatorAbstractBase implements
                 try {
                     Component c = this.dbGlobalInstances.get(key);
                     if (c != null) {
-                        logger.trace("Remove component for Object:" + key);
+                        logger.trace("Remove component for Object: {}" , key);
                         this.dm.remove(c);
                     }
                 } catch (Exception nex) {