You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2014/10/18 22:07:00 UTC

svn commit: r1632835 - in /felix/sandbox/pderop/dependencymanager-prototype: org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ org.apache.felix.dependencymanager/src/org/apache/felix/dm/ org.apache.felix.dependencymanager/src/org/...

Author: pderop
Date: Sat Oct 18 20:07:00 2014
New Revision: 1632835

URL: http://svn.apache.org/r1632835
Log:
FELIX-2706: Support callback delegation for Configuration Dependecies.

Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ConfigurationDependencyTest.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ConfigurationDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ConfigurationDependencyTest.java?rev=1632835&r1=1632834&r2=1632835&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ConfigurationDependencyTest.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/ConfigurationDependencyTest.java Sat Oct 18 20:07:00 2014
@@ -48,7 +48,31 @@ public class ConfigurationDependencyTest
         m.add(s1);
         m.add(s2);
         m.add(s3);
-        e.waitForStep(4, 5000);
+        e.waitForStep(4, 50000000);
+        m.remove(s1);
+        m.remove(s2);
+        m.remove(s3);
+        // ensure we executed all steps inside the component instance
+        e.step(6);
+    }
+    
+    public void testComponentWithRequiredConfigurationAndCallbackInstanceAndServicePropertyPropagation() {
+        DependencyManager m = getDM();
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        // create a service provider and consumer
+        ConfigurationConsumerCallbackInstance callbackInstance = new ConfigurationConsumerCallbackInstance(e);
+        Component s1 = m.createComponent().setImplementation(new ConfigurationConsumerWithCallbackInstance(e))
+            .setInterface(Runnable.class.getName(), null)
+            .add(m.createConfigurationDependency().setPid(PID).setPropagate(true).setCallback(callbackInstance, "updateConfiguration"));
+        Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e))
+            .add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
+        Component s3 = m.createComponent().setImplementation(new ConfiguredServiceConsumer(e))
+            .add(m.createServiceDependency().setService(Runnable.class, ("(testkey=testvalue)")).setRequired(true));
+        m.add(s1);
+        m.add(s2);
+        m.add(s3);
+        e.waitForStep(4, 50000000);
         m.remove(s1);
         m.remove(s2);
         m.remove(s3);
@@ -134,6 +158,35 @@ public class ConfigurationDependencyTest
             m_ensure.step(4);
         }
     }
+    
+    static class ConfigurationConsumerCallbackInstance {
+        private final Ensure m_ensure;
+
+        public ConfigurationConsumerCallbackInstance(Ensure e) {
+            m_ensure = e;
+        }
+        
+        public void updateConfiguration(Dictionary props) throws Exception {
+            if (props != null) {
+                m_ensure.step(2);
+                if (!"testvalue".equals(props.get("testkey"))) {
+                    Assert.fail("Could not find the configured property.");
+                }
+            } 
+        }
+    }
+    
+    static class ConfigurationConsumerWithCallbackInstance implements Runnable {
+        private final Ensure m_ensure;
+
+        public ConfigurationConsumerWithCallbackInstance(Ensure e) {
+            m_ensure = e;
+        }
+        
+        public void run() {
+            m_ensure.step(4);
+        }
+    }
 
     static class ConfiguredServiceConsumer {
         private final Ensure m_ensure;

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java?rev=1632835&r1=1632834&r2=1632835&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ConfigurationDependency.java Sat Oct 18 20:07:00 2014
@@ -47,6 +47,16 @@ public interface ConfigurationDependency
 	ConfigurationDependency setCallback(String callback);
 
     /**
+     * Sets the name of the callback method that should be invoked when a configuration
+     * is available. The contract for this method is identical to that of
+     * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>.
+     * 
+     * @param instance the instance to call the callbacks on
+     * @param callback the name of the callback method
+     */
+    ConfigurationDependency setCallback(Object instance, String callback);
+
+    /**
      * Sets the <code>service.pid</code> of the configuration you are depending
      * on.
      */

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java?rev=1632835&r1=1632834&r2=1632835&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java Sat Oct 18 20:07:00 2014
@@ -37,7 +37,6 @@ import org.osgi.service.cm.ManagedServic
 
 public class ConfigurationDependencyImpl extends AbstractDependency<ConfigurationDependency> implements ConfigurationDependency, ManagedService {
     private Dictionary<String, Object> m_settings;
-    private String m_callback = "updated";
 	private final Logger m_logger;
 	private String m_pid;
 	private ServiceRegistration m_registration;
@@ -52,12 +51,12 @@ public class ConfigurationDependencyImpl
     	super(false /* not autoconfig */, context);
     	m_logger = logger;
         setRequired(true);
+        setCallback("updated");
     }
     
 	public ConfigurationDependencyImpl(ConfigurationDependencyImpl prototype) {
 	    super(prototype);
 	    m_pid = prototype.m_pid;
-	    m_callback = prototype.m_callback;
 	    m_logger = prototype.m_logger;
         m_metaType = prototype.m_metaType != null ? new MetaTypeProviderImpl(prototype.m_metaType, this, null) : null;
 	}
@@ -68,7 +67,12 @@ public class ConfigurationDependencyImpl
 	}
 
     public ConfigurationDependencyImpl setCallback(String callback) {
-        m_callback = callback;
+        super.setCallbacks(callback, null);
+        return this;
+    }
+    
+    public ConfigurationDependencyImpl setCallback(Object instance, String callback) {
+        super.setCallbacks(instance, callback, null);
         return this;
     }
 
@@ -234,12 +238,12 @@ public class ConfigurationDependencyImpl
     
     private void invokeUpdated(Dictionary<?,?> settings) throws ConfigurationException {
     	if (m_updateInvokedCache.compareAndSet(false, true)) {
-			Object[] instances = m_component.getInstances();
+			Object[] instances = super.getInstances(); // either the callback instance or the component instances
 			if (instances != null) {
 				for (int i = 0; i < instances.length; i++) {
 					try {
 						InvocationUtil.invokeCallbackMethod(instances[i],
-								m_callback, new Class[][] {
+								m_add, new Class[][] {
 										{ Dictionary.class }, {} },
 								new Object[][] { { settings }, {} });
 					}