Author: pderop
Date: Wed Feb 24 08:46:15 2016
New Revision: 1732038

URL: http://svn.apache.org/viewvc?rev=1732038&view=rev
Log:
FELIX-4689: added a "withCnf(Class<?> configurationType)" method in 
ComponentBuilder.

Modified:
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java

Modified: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java?rev=1732038&r1=1732037&r2=1732038&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
 (original)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
 Wed Feb 24 08:46:15 2016
@@ -43,13 +43,14 @@ public class Activator extends Dependenc
             
         // Creates a Service Consumer. we depend on LogService, EventAdmin and 
on our ServiceProvider.
         // (LogService and EventAdmin are declared in one single method call).
-        // We also depend on a configuration. Our ServiceConsumer.updated 
method takes as argument a "Configuration" interface
-        // which is used to wrap the actual properties behind a dynamic proxy 
for our "Configuration" interface that is implemented by Dependency Manager.
-        // (the pid is assumed to be by default the fqdn of our Configuration 
interface).
+        // We also depend on a configuration. the configuration callback is 
assumed to be the "ServiceConsumer.updated" method which 
+        // takes as argument a "Configuration" interface. This interface is 
used to wrap the actual properties behind a dynamic proxy 
+        // that is implemented by Dependency Manager.
+        // The pid is assumed to be by default the fqdn of the specified 
Configuration interface 
("org.apache.felix.dm.lambda.samples.hello.Configuration").
         component(comp -> comp.impl(ServiceConsumer.class)
             .withSvc(LogService.class, EventAdmin.class)
             .withSvc(ServiceProvider.class, srv -> srv.filter("(p1=v1)")) 
-            .withCnf(cnf -> cnf.update(Configuration.class, 
ServiceConsumer::updated))); 
+            .withCnf(Configuration.class));  // shortcut for 
"withCnf(Configuration.class, cnf -> cnf.updated(Configuration.class, 
ServiceConsumer::updated)"
         
         // Creates a component that populates some properties in the 
Configuration Admin.
         // Here, we inject the CM (Configuration Admin) service dependency 
using a method reference:

Modified: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java?rev=1732038&r1=1732037&r2=1732038&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
 (original)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
 Wed Feb 24 08:46:15 2016
@@ -32,7 +32,7 @@ public class ServiceConsumer {
     volatile EventAdmin eventAdmin;
 
     public void updated(Configuration conf) {
-        // conf.getFoo() returns "bar"
+        System.out.println(conf.getFoo()); 
     }
     
     public void start() {

Modified: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java?rev=1732038&r1=1732037&r2=1732038&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
 (original)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
 Wed Feb 24 08:46:15 2016
@@ -400,6 +400,16 @@ public interface ComponentBuilder<B exte
     }
     
     /**
+     * Adds a configuration dependency using a configuration type. The 
configuration is injected in an updated callback which takes in argument
+     * an implementation of the specified configuration type.
+     * @return this builder
+     * @see ConfigurationDependencyBuilder
+     */
+    default B withCnf(Class<?> configType) {
+        return withCnf(cnf -> cnf.update(configType, "updated"));
+    }
+    
+    /**
      * Adds a bundle dependency.
      * @param consumer the lambda used to build the bundle dependency.
      * @return this builder.


Reply via email to