FELIX-1841 Improve service bind update by creating a special "update" method which directly calls the invokeBindMethod(ServiceReference) method instead of going through the regular bind() method, which may not call the correct bind method at all (or too many methods)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@884427 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
index c590812..542c1ac 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
@@ -125,10 +125,10 @@
                                  m_dependencyMetadata.getInterface()
         );
         m_unbind = new UnbindMethod( m_componentManager,
-                                     m_dependencyMetadata.getUnbind(),
-                                     m_componentInstance.getClass(),
-                                     m_dependencyMetadata.getName(),
-                                     m_dependencyMetadata.getInterface()
+            m_dependencyMetadata.getUnbind(),
+            m_componentInstance.getClass(),
+            m_dependencyMetadata.getName(),
+            m_dependencyMetadata.getInterface()
         );
     }
 
@@ -208,11 +208,10 @@
                     m_size--;
                     serviceRemoved( ref );
                 }
-                else if ( "true".equalsIgnoreCase( m_componentManager.getBundle().getBundleContext().getProperty(
-                    "ds.rebind.enabled" ) ) )
+                else
                 {
-                    // service is bound, bind again to update reference properties
-                    bind();
+                    // update the service binding due to the new properties
+                    update( ref );
                 }
 
                 break;
@@ -921,6 +920,33 @@
 
 
     /**
+     * Handles an update in the service reference properties of a bound service.
+     * <p>
+     * For now this just calls the bind method with the service again if
+     * the <code>ds.rebind.enabled</code> configuration property is set to
+     * <code>true</code>. If the property is not set to <code>true</code> this
+     * method does nothing.
+     *
+     * @param ref The <code>ServiceReference</code> representing the updated
+     *      service.
+     */
+    private void update( final ServiceReference ref )
+    {
+        //        if ( m_componentManager.getActivator().getConfiguration().isRebindEnabled() )
+        if ( "true".equalsIgnoreCase( m_componentManager.getBundle().getBundleContext().getProperty(
+            "ds.rebind.enabled" ) ) )
+        {
+            // The updated method is only invoked if the implementation object is not
+            // null. This is valid for both immediate and delayed components
+            if ( m_dependencyMetadata.getBind() != null )
+            {
+                invokeBindMethod( ref );
+            }
+        }
+    }
+
+
+    /**
      * Revoke the given bindings. This method cannot throw an exception since
      * it must try to complete all that it can
      */