FELIX-4689: added a "withCnf(Class<?> configurationType)" method in ComponentBuilder.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1732038 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java b/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
index 98c970b..8281f14 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/Activator.java
@@ -43,13 +43,14 @@
// 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:
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java b/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
index 1127173..ef5cc8c 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/ServiceConsumer.java
@@ -32,7 +32,7 @@
volatile EventAdmin eventAdmin;
public void updated(Configuration conf) {
- // conf.getFoo() returns "bar"
+ System.out.println(conf.getFoo());
}
public void start() {
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
index 40ba0c5..21919ab 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
@@ -400,6 +400,16 @@
}
/**
+ * 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.