Applied feedbacks that Jan Willem sent to me about the new dm-lambda library:
- renamed the DependencyManagerActivator.activate() method to init(BundleContext ctx, DependencyManager dm)
- Removed abbreviated names like "cb()" or "cbi" methods, and replaced them with niced method names like "add()/changed()/removed()" ...
- Added a system property "org.apache.felix.dependencymanager.lambda.dependencymode" that allows to control the default
mode of dependency (still to be discussed).
- added full support or new configuration types.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1731147 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java
index 8a393a1..a120738 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java
@@ -1,9 +1,9 @@
package org.apache.felix.dm.lambda;
import org.apache.felix.dm.lambda.callbacks.CbBundle;
-import org.apache.felix.dm.lambda.callbacks.CbComponentBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentBundle;
+import org.apache.felix.dm.lambda.callbacks.CbBundleComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent;
/**
* Builds a Dependency Manager bundle adapter. The adapter created by this builder will be applied to any bundle that matches the specified
@@ -12,12 +12,14 @@
* you supply here. The bundle is injected by reflection in adapter class fields having a Bundle type, or using a callback method that you can
* specify.
*
+ * You can specify reflection based (using method names), or java8 method references for callbacks.
+ *
* <p> Example which creates a BundleAdapter service for each started bundle (the bundle is added by reflection on
* a class field that has a "Bundle" type):
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* bundleAdapter(adapt -> adapt
* .impl(BundleAdapterImpl.class)
* .provides(BundleAdapter.class)
@@ -30,12 +32,12 @@
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* bundleAdapter(adapt -> adapt
* .impl(BundleAdapterImpl.class)
* .provides(BundleAdapter.class)
* .mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE)
- * .cb(BundleAdapterImpl::setBundle));
+ * .add(BundleAdapterImpl::setBundle));
* }
* }
* }</pre>
@@ -44,12 +46,12 @@
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* bundleAdapter(adapt -> adapt
* .impl(BundleAdapterImpl.class)
* .provides(BundleAdapter.class)
* .mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE)
- * .cb("setBundle"));
+ * .add("setBundle"));
* }
* }
* }</pre>
@@ -92,152 +94,187 @@
BundleAdapterBuilder propagate();
/**
- * Sets some <code>callbacks</code> invoked on the component implementation instances. When a bundle state matches the bundle
- * adapter filter, then the bundle is injected using the specified callback methods. When you specify one callback, it stands for the "add" callback.
- * When you specify two callbacks, the first one corresponds to the "add" callback, and the second one to the "remove" callback. When you specify three
- * callbacks, the first one stands for the "add" callback, the second one for the "change" callback, and the third one for the "remove" callback.
+ * Sets a "add" callback name invoked on the component implementation instance(s).
+ * The callback can be used as hooks whenever the dependency is added. When you specify a callback,
+ * the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.
*
- * @param callbacks a list of callbacks (1 param : "add", 2 params : "add"/remove", 3 params : "add"/"change"/"remove").
- * @return this builder
+ * @param callback the method to call when a bundle was added
+ *
+ * The following method signature are supported:
+ * <pre>{@code
+ * callback(Bundle b)
+ * callback(Component c, Bundle b)
+ * }</pre>
+ *
+ * @param callback the callback name
+ * @return this builder.
*/
- BundleAdapterBuilder cb(String ... callbacks);
+ BundleAdapterBuilder add(String callback);
/**
- * Sets some <code>callback instance</code> methods invoked on a given Object instance. When a bundle state matches the bundle
- * adapter filter, then the bundle is injected using the specified callback methods. When you specify one callback, it stands for the "add" callback.
- * When you specify two callbacks, the first one corresponds to the "add" callback, and the second one to the "remove" callback.
- * When you specify three callbacks, the first one stands for the "add" callback, the second one for the "change" callback, and the third one for
- * the "remove" callback.
+ * Sets a "change" callback name invoked on the component implementation instance(s).
+ * The callback can be used as hooks whenever the dependency is changed. When you specify a callback,
+ * the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.
*
- * @param callbackInstance the Object instance where the callbacks are invoked on
- * @param callbacks a list of callbacks (1 param : "add", 2 params : "add"/remove", 3 params : "add"/"change"/"remove").
- * @return this builder
+ * @param callback the method to call when a bundle was changed
+ *
+ * The following method signature are supported:
+ * <pre>{@code
+ * callback(Bundle b)
+ * callback(Component c, Bundle b)
+ * }</pre>
+ *
+ * @param callback the callback name
+ * @return this builder.
*/
- BundleAdapterBuilder cbi(Object callbackInstance, String ... callbacks);
+ BundleAdapterBuilder change(String callback);
+
+ /**
+ * Sets a "remove" callback name invoked on the component implementation instance(s).
+ * The callback can be used as hooks whenever the dependency is removed. When you specify a callback,
+ * the auto configuration feature is automatically turned off, because we're assuming you don't need it in this case.
+ *
+ * @param callback the method to call when a bundle was removed
+ *
+ * The following method signature are supported:
+ * <pre>{@code
+ * callback(Bundle b)
+ * callback(Component c, Bundle b)
+ * }</pre>
+ *
+ * @param callback the callback name
+ * @return this builder.
+ */
+ BundleAdapterBuilder remove(String callback);
+
+ /**
+ * Sets a callback instance to use when invoking reflection based callbacks.
+ *
+ * @param callbackInstance the instance to call the reflection based callbacks on
+ * @return this builder.
+ * @see #add(String)
+ * @see #change(String)
+ * @see #remove(String)
+ */
+ BundleAdapterBuilder callbackInstance(Object callbackInstance);
/**
- * Sets a <code>callback</code> invoked on a component implementation instance when a bundle is added.
- * The method reference must point to a Component implementation class method, and take as argument a Bundle.
+ * Sets a reference to a callback method invoked on one of the component implementation classes.
+ * The method reference must point to a Component implementation class method, it is called when the bundle is added
+ * and takes as argument a Bundle.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- <T> BundleAdapterBuilder cb(CbTypeBundle<T> add);
+ <T> BundleAdapterBuilder add(CbBundle<T> add);
/**
- * Sets some <code>callbacks</code> invoked on a component implementation instance when a bundle is added/removed.
- * The method references must point to a Component implementation class method, and take as argument a Bundle.
+ * Sets a reference to a callback method invoked on one of the component implementation classes.
+ * The method reference must point to a Component implementation class method, it is called when the bundle is changed
+ * and takes as argument a Bundle.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a bundle is added.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- <T> BundleAdapterBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> remove);
-
- /**
- * Sets some <code>callbacks</code> invoked on a component implementation instance when a bundle is added, changed or removed.
- * The method references must point to a Component implementation class method, and take as argument a Bundle.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a bundle is added.
* @param change the method reference invoked when a bundle has changed.
+ * @return this builder
+ */
+ <T> BundleAdapterBuilder change(CbBundle<T> change);
+
+ /**
+ * Sets a reference to a callback method invoked on one of the component implementation classes.
+ * The method reference must point to a Component implementation class method, it is called when the bundle is removed
+ * and takes as argument a Bundle.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- <T> BundleAdapterBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> change, CbTypeBundle<T> remove);
+ <T> BundleAdapterBuilder remove(CbBundle<T> remove);
/**
- * Sets a <code>callback</code> invoked on a component implementation instance when a bundle is added.
- * The method reference must point to a Component implementation class method, and take as argument a Component and a Bundle.
+ * Sets a reference to a callback method invoked on one of the component implementation classes.
+ * The method reference must point to a Component implementation class method, it is called when the bundle is added
+ * and takes as argument a Bundle and a Component.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- <T> BundleAdapterBuilder cb(CbTypeComponentBundle<T> add);
+ <T> BundleAdapterBuilder add(CbBundleComponent<T> add);
/**
- * Sets some <code>callbacks</code> invoked on a component implementation instance when a bundle is added, or removed.
- * The method references must point to a Component implementation class method, and take as argument a Component and a Bundle.
+ * Sets a reference to a callback method invoked on one of the component implementation classes.
+ * The method reference must point to a Component implementation class method, it is called when the bundle is changed
+ * and takes as argument a Bundle and a Component.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a bundle is added.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- <T> BundleAdapterBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> remove);
-
- /**
- * Sets some <code>callbacks</code> invoked on a component implementation instance when a bundle is added, changed or removed.
- * The method references must point to a Component implementation class method, and take as argument a Component and a Bundle.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a bundle is added.
* @param change the method reference invoked when a bundle has changed.
+ * @return this builder
+ */
+ <T> BundleAdapterBuilder change(CbBundleComponent<T> change);
+
+ /**
+ * Sets a reference to a callback method invoked on one of the component implementation classes.
+ * The method reference must point to a Component implementation class method, it is called when the bundle is removed
+ * and takes as argument a Bundle and a Component.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- <T> BundleAdapterBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> change, CbTypeComponentBundle<T> remove);
+ <T> BundleAdapterBuilder remove(CbBundleComponent<T> remove);
/**
- * Sets a <code>callback instance</code> invoked on a given Object instance when a bundle is added.
- * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
+ * Sets a reference to a callback method invoked on a given Object instance.
+ * The method reference is invoked when the bundle is added and takes as argument a Bundle.
*
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- BundleAdapterBuilder cbi(CbBundle add);
+ BundleAdapterBuilder add(InstanceCbBundle add);
/**
- * Sets some <code>callback instance</code> invoked on a given Object instance when a bundle is added or removed.
- * The method references must point to an Object instance method, and take as argument a Bundle parameter.
+ * Sets a reference to a callback method invoked on a given Object instance.
+ * The method reference is invoked when the bundle has changed and takes as argument a Bundle.
*
- * @param add the method reference invoked when a bundle is added.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- BundleAdapterBuilder cbi(CbBundle add, CbBundle remove);
-
- /**
- * Sets some <code>callback instance</code> invoked on a given Object instance when a bundle is added, changed or removed.
- * The method references must point to an Object instance method, and take as argument a Bundle parameter.
- *
- * @param add the method reference invoked when a bundle is added.
* @param change the method reference invoked when a bundle has changed.
+ * @return this builder
+ */
+ BundleAdapterBuilder change(InstanceCbBundle change);
+
+ /**
+ * Sets a reference to a callback method invoked on a given Object instance.
+ * The method reference is invoked when the bundle is removed and takes as argument a Bundle.
+ *
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- BundleAdapterBuilder cbi(CbBundle add, CbBundle change, CbBundle remove);
+ BundleAdapterBuilder remove(InstanceCbBundle remove);
/**
- * Sets a <code>callback instance</code> invoked on a given Object instance when a bundle is added.
- * The method reference must point to an Object instance method, and takes as arguments a Component and a Bundle.
+ * Sets a reference to a callback method invoked on a given Object instance.
+ * The method reference is invoked when the bundle is added and takes as argument a Bundle and a Component.
*
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- BundleAdapterBuilder cbi(CbComponentBundle add);
+ BundleAdapterBuilder add(InstanceCbBundleComponent add);
/**
- * Sets some <code>callback instance</code> invoked on a given Object instance when a bundle is added or removed.
- * The method references must point to an Object instance method, and take as argument a Component and a Bundle.
+ * Sets a reference to a callback method invoked on a given Object instance.
+ * The method reference is invoked when the bundle has changed and takes as argument a Bundle and a Component.
*
- * @param add the method reference invoked when a bundle is added.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- BundleAdapterBuilder cbi(CbComponentBundle add, CbComponentBundle remove);
-
- /**
- * Sets some <code>callback instance</code> invoked on a given Object instance when a bundle is added, changed or removed.
- * The method references must point to an Object instance method, and take as argument a Component and a Bundle.
- *
- * @param add the method reference invoked when a bundle is added.
* @param change the method reference invoked when a bundle has changed.
+ * @return this builder
+ */
+ BundleAdapterBuilder change(InstanceCbBundleComponent change);
+
+ /**
+ * Sets a reference to a callback method invoked on a given Object instance.
+ * The method reference is invoked when the bundle is removed and takes as argument a Bundle and a Component.
+ *
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- BundleAdapterBuilder cbi(CbComponentBundle add, CbComponentBundle change, CbComponentBundle remove);
+ BundleAdapterBuilder remove(InstanceCbBundleComponent remove);
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java
index 0c577ba..7d87a12 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java
@@ -1,27 +1,30 @@
package org.apache.felix.dm.lambda;
import java.util.Dictionary;
-import java.util.function.Supplier;
+import java.util.function.Function;
import org.apache.felix.dm.BundleDependency;
import org.apache.felix.dm.lambda.callbacks.CbBundle;
-import org.apache.felix.dm.lambda.callbacks.CbComponentBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentBundle;
+import org.apache.felix.dm.lambda.callbacks.CbBundleComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent;
import org.osgi.framework.Bundle;
/**
- * Builds a Dependency Manager Bundle Dependency. The Dependency is required by default (unlike in the original Dependency Manager API).
+ * Builds a Dependency Manager Bundle Dependency.
+ * The Dependency is required by default, but you can
+ * control the default mode (required or optional) using the "org.apache.felix.dependencymanager.lambda.dependencymode"
+ * system property which can be set to either "required" or "optional" ("required" by default).
*
- * <p> Example of a Component which tracks a started bundle having a given bundle symbolic name:
+ * <p> Example of a Pojo Component which tracks a started bundle having a given bundle symbolic name:
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* String BSN = "org.apache.felix.dependencymanager";
* component(comp -> comp
- * .impl(MyComponent.class)
- * .withBundle(b -> b.mask(Bundle.ACTIVE).filter("(Bundle-SymbolicName=" + BSN + ")").cb(MyComponent::add, MyComponent::remove)));
+ * .impl(Pojo.class)
+ * .withBundle(b -> b.mask(Bundle.ACTIVE).filter("(Bundle-SymbolicName=" + BSN + ")").add(Pojo::add).remove(Pojo::remove)));
*
* }
* }
@@ -31,7 +34,7 @@
*/
public interface BundleDependencyBuilder extends DependencyBuilder<BundleDependency> {
/**
- * Enables auto configuration for this dependency. This means the component implementation (composition) will be
+ * Enables auto configuration for this dependency. This means the component implementation class fields will be
* injected with this bundle dependency automatically.
*
* @param autoConfig <code>true</code> to enable auto configuration
@@ -40,7 +43,7 @@
public BundleDependencyBuilder autoConfig(boolean autoConfig);
/**
- * Enables auto configuration for this dependency. This means the component implementation (composition) will be
+ * Enables auto configuration for this dependency. This means the component implementation class fields will be
* injected with this bundle dependency automatically.
*
* @return the bundle dependency builder
@@ -48,7 +51,8 @@
public BundleDependencyBuilder autoConfig();
/**
- * Sets the dependency to be required. By default, the dependency is required.
+ * Sets the dependency to be required. By default, the dependency is required, but you can specify the default mode
+ * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
*
* @param required <code>true</code> if this bundle dependency is required (true by default).
* @return the bundle dependency builder
@@ -56,7 +60,8 @@
public BundleDependencyBuilder required(boolean required);
/**
- * Sets the dependency to be required.
+ * Sets the dependency to be required. By default, the dependency is required, but you can specify the default mode
+ * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
*
* @return the bundle dependency builder
*/
@@ -107,9 +112,9 @@
/**
* Sets an Object instance and a callback method used to propagate some properties to the provided service properties.
* The method will be invoked on the specified object instance and must have one of the following signatures:
- * <ul><li>Dictionary callback(ServiceReference, Object service)
- * <li>Dictionary callback(ServiceReference)
- * </ul>
+ *
+ * <p><ul><li>Dictionary callback(Bundle bundle)</ul>
+ *
* @param instance the Object instance which is used to retrieve propagated service properties
* @param method the method to invoke for retrieving the properties to be propagated to the service properties.
* @return this service dependency. builder
@@ -117,163 +122,176 @@
public BundleDependencyBuilder propagate(Object instance, String method);
/**
- * Sets an Object instance and a callback method used to propagate some properties to the provided service properties.
- * The method will be invoked on the specified object instance and must have one of the following signatures:
- * <ul><li>Dictionary callback(ServiceReference, Object service)
- * <li>Dictionary callback(ServiceReference)
- * </ul>
- * @param instance the Object instance which is used to retrieve propagated service properties
+ * Sets a reference to a method on an Object instance used to propagate some bundle properties to the provided service properties.
+ *
+ * @param propagate a function which accepts a Bundle argument and which returns some properties that will be
+ * propagated to the provided component service properties.
* @return this service dependency. builder
*/
- public BundleDependencyBuilder propagate(Supplier<Dictionary<?, ?>> instance);
+ public BundleDependencyBuilder propagate(Function<Bundle, Dictionary<?, ?>> propagate);
/**
- * Sets some <code>callback</code> methods to invoke on the component instance(s). When a bundle state matches the bundle
- * filter, then the bundle is injected using the specified callback methods. When you specify one callback, it stands for the "add" callback.
- * When you specify two callbacks, the first one corresponds to the "add" callback, and the second one to the "remove" callback. When you specify three
- * callbacks, the first one stands for the "add" callback, the second one for the "change" callback, and the third one for the "remove" callback.
+ * Sets a "add" <code>callback</code> method to invoke on the component implementation instance(s).
+ * The callback is invoked when the bundle is added, and the following signatures are supported:
*
- * @param callbacks a list of callbacks (1 param: "add", 2 params: "add"/remove", 3 params: "add"/"change"/"remove" callbacks).
+ * <p><ol>
+ * <li>method(Bundle)</li>
+ * <li>method(Component, Bundle)</li>
+ * </ol>
+ *
+ * @param callback the add callback
* @return this builder
*/
- BundleDependencyBuilder cb(String ... callbacks);
+ BundleDependencyBuilder add(String callback);
/**
- * Sets some <code>callback instance</code> methods to invoke on a given Object instance. When a bundle state matches the bundle
- * filter, then the bundle is injected using the specified callback methods. When you specify one callback, it stands for the "add" callback.
- * When you specify two callbacks, the first one corresponds to the "add" callback, and the second one to the "remove" callback.
- * When you specify three callbacks, the first one stands for the "add" callback, the second one for the "change" callback, and the third one for
- * the "remove" callback.
+ * Sets a "change" <code>callback</code> method to invoke on the component implementation instance(s).
+ * The callback is invoked when the bundle state has changed, and the following signatures are supported:
*
- * @param callbackInstance the Object instance where the callbacks are invoked on
- * @param callbacks a list of callbacks (1 param: "add", 2 params: "add/remove", 3 params: "add/change/remove" callbacks).
+ * <p><ol>
+ * <li>method(Bundle)</li>
+ * <li>method(Component, Bundle)</li>
+ * </ol>
+ *
+ * @param callback the change callback
* @return this builder
*/
- BundleDependencyBuilder cb(Object callbackInstance, String ... callbacks);
+ BundleDependencyBuilder change(String callback);
+
+ /**
+ * Sets a "remove" <code>callback</code> method to invoke on the component implementation instance(s).
+ * The callback is invoked when the bundle is removed, and the following signatures are supported:
+ * <p><ol>
+ * <li>method(Bundle)</li>
+ * <li>method(Component, Bundle)</li>
+ * </ol>
+ *
+ * @param callback the remove callback
+ * @return this builder
+ */
+ BundleDependencyBuilder remove(String callback);
+
+ /**
+ * Specifies a callback instance used to invoke the reflection based callbacks on it.
+ * @param callbackInstance the instance to invoke the callbacks on
+ * @return this builder
+ * @see #add(String)
+ * @see #change(String)
+ * @see #remove(String)
+ */
+ BundleDependencyBuilder callbackInstance(Object callbackInstance);
/**
* Sets a <code>callback</code> method reference which is invoked when a bundle is added.
- * The method reference must point to a Component implementation class method, and take as argument a Bundle.
+ * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
*
* @param <T> the type of the component implementation class on which the callback is invoked on.
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- <T> BundleDependencyBuilder cb(CbTypeBundle<T> add);
-
+ <T> BundleDependencyBuilder add(CbBundle<T> add);
+
/**
- * Sets some <code>callback</code> method references which are invoked when a bundle is added, or removed.
- * The method references must point to a Component implementation class method, and take as argument a Bundle.
+ * Sets a <code>callback</code> method reference which is invoked when a bundle is changed.
+ * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
*
* @param <T> the type of the component implementation class on which the callback is invoked on.
- * @param add the method reference invoked when a bundle is added.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- <T> BundleDependencyBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> remove);
-
- /**
- * Sets some <code>callback</code> method references which are invoked when a bundle is added, changed or removed.
- * The method references must point to a Component implementation class method, and take as argument a Bundle.
- *
- * @param <T> the type of the component implementation class on which the callback is invoked on.
- * @param add the method reference invoked when a bundle is added.
* @param change the method reference invoked when a bundle has changed.
+ * @return this builder
+ */
+ <T> BundleDependencyBuilder change(CbBundle<T> change);
+
+ /**
+ * Sets a <code>callback</code> method reference which is invoked when a bundle is removed.
+ * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
+ *
+ * @param <T> the type of the component implementation class on which the callback is invoked on.
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- <T> BundleDependencyBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> change, CbTypeBundle<T> remove);
-
+ <T> BundleDependencyBuilder remove(CbBundle<T> remove);
+
/**
* Sets a <code>callback</code> method reference which is invoked when a bundle is added.
- * The method reference must point to a Component implementation class method, and take as argument a Component and a Bundle.
+ * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
*
* @param <T> the type of the component implementation class on which the callback is invoked on.
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- <T> BundleDependencyBuilder cb(CbTypeComponentBundle<T> add);
+ <T> BundleDependencyBuilder add(CbBundleComponent<T> add);
/**
- * Sets some <code>callback</code> method references which are invoked when a bundle is added, or removed.
- * The method references must point to a Component implementation class method, and take as argument a Component and a Bundle.
+ * Sets a <code>callback</code> method reference which is invoked when a bundle is changed.
+ * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
*
* @param <T> the type of the component implementation class on which the callback is invoked on.
- * @param add the method reference invoked when a bundle is added.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- <T> BundleDependencyBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> remove);
-
- /**
- * Sets some <code>callback</code> method references which are invoked when a bundle is added, changed or removed.
- * The method references must point to a Component implementation class method, and take as argument a Component and a Bundle.
- *
- * @param <T> the type of the component implementation class on which the callback is invoked on.
- * @param add the method reference invoked when a bundle is added.
* @param change the method reference invoked when a bundle has changed.
- * @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- <T> BundleDependencyBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> change, CbTypeComponentBundle<T> remove);
+ <T> BundleDependencyBuilder change(CbBundleComponent<T> change);
/**
- * Sets a <code>callback instance</code> method reference which is invoked when a bundle is added.
+ * Sets a <code>callback</code> method reference which is invoked when a bundle is removed.
+ * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
+ *
+ * @param <T> the type of the component implementation class on which the callback is invoked on.
+ * @param remove the method reference invoked when a bundle is removed.
+ * @return this builder
+ */
+ <T> BundleDependencyBuilder remove(CbBundleComponent<T> remove);
+
+ /**
+ * Sets a method reference on an Object instance which is invoked when a bundle is added.
* The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
*
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- BundleDependencyBuilder cbi(CbBundle add);
+ BundleDependencyBuilder add(InstanceCbBundle add);
/**
- * Sets some <code>callback instance</code> method references which are invoked when a bundle is added or removed.
- * The method references must point to an Object instance method, and take as argument a Bundle parameter.
+ * Sets a method reference on an Object instance which is invoked when a bundle is changed.
+ * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
*
- * @param add the method reference invoked when a bundle is added.
+ * @param change the method reference invoked when a bundle is changed.
+ * @return this builder
+ */
+ BundleDependencyBuilder change(InstanceCbBundle change);
+
+ /**
+ * Sets a method reference on an Object instance which is invoked when a bundle is removed.
+ * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
+ *
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- BundleDependencyBuilder cbi(CbBundle add, CbBundle remove);
-
- /**
- * Sets some <code>callback instance</code> method references which are invoked when a bundle is added, changed or removed.
- * The method references must point to an Object instance method, and take as argument a Bundle parameter.
- *
- * @param add the method reference invoked when a bundle is added.
- * @param change the method reference invoked when a bundle has changed.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- BundleDependencyBuilder cbi(CbBundle add, CbBundle change, CbBundle remove);
+ BundleDependencyBuilder remove(InstanceCbBundle remove);
/**
* Sets a <code>callback instance</code> method reference which is invoked when a bundle is added.
- * The method reference must point to an Object instance method, and takes as arguments a Component and a Bundle.
+ * The method reference must point to an Object instance method, and takes as arguments a Bundle and a Component.
*
* @param add the method reference invoked when a bundle is added.
* @return this builder
*/
- BundleDependencyBuilder cbi(CbComponentBundle add);
+ BundleDependencyBuilder add(InstanceCbBundleComponent add);
/**
- * Sets some <code>callback instance</code> method references which are invoked when a bundle is added or removed.
- * The method references must point to an Object instance method, and take as argument a Component and a Bundle.
+ * Sets a <code>callback instance</code> method reference which is invoked when a bundle is changed.
+ * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component.
*
- * @param add the method reference invoked when a bundle is added.
+ * @param change the method reference invoked when a bundle is changed.
+ * @return this builder
+ */
+ BundleDependencyBuilder change(InstanceCbBundleComponent change);
+
+ /**
+ * Sets a <code>callback instance</code> method reference which is invoked when a bundle is removed.
+ * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component.
+ *
* @param remove the method reference invoked when a bundle is removed.
* @return this builder
*/
- BundleDependencyBuilder cbi(CbComponentBundle add, CbComponentBundle remove);
-
- /**
- * Sets some <code>callback instance</code> method references which are invoked when a bundle is added, changed or removed.
- * The method references must point to an Object instance method, and take as argument a Component and a Bundle.
- *
- * @param add the method reference invoked when a bundle is added.
- * @param change the method reference invoked when a bundle has changed.
- * @param remove the method reference invoked when a bundle is removed.
- * @return this builder
- */
- BundleDependencyBuilder cbi(CbComponentBundle add, CbComponentBundle change, CbComponentBundle remove);
+ BundleDependencyBuilder remove(InstanceCbBundleComponent remove);
}
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 0c978ea..206c9e9 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
@@ -8,9 +8,10 @@
import java.util.stream.Stream;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.lambda.callbacks.Cb;
import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbConsumer;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCb;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
/**
* Builds a Dependency Manager Component. Components are the main building blocks for OSGi applications.
@@ -25,8 +26,8 @@
*
* <pre>{@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
- * component(comp -> comp.impl(Configurator.class).withSrv(ConfigurationAdmin.class));
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * component(comp -> comp.impl(Configurator.class).withSvc(ConfigurationAdmin.class));
* }
* }
* } </pre>
@@ -35,6 +36,7 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public interface ComponentBuilder<B extends ComponentBuilder<B>> {
+
/**
* Configures the component implementation. Can be a class name, or a component implementation object.
*
@@ -84,8 +86,9 @@
<U, V> B factory(Supplier<U> factory, Function<U, V> create);
/**
- * Configures a factory used to create this component implementation using a Factory object and a "getComponent" factory method.
- * the Factory method may then return multiple objects that will be part of this component implementation.
+ * Configures a factory used to create this component implementation using a Factory object and a "getComposition" factory method.
+ * the Factory method may then return multiple objects that will be part of this component implementation, and
+ * all of them will be searched for injecting any of the dependencies.
*
* Example:
*
@@ -110,8 +113,9 @@
* factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition).
* }</pre>
*
- * Here, the CompositionManager will act as a factory (the create method will return the component implementation object), and the
- * CompositionManager.getComposition() method will return all the objects that are also part of the component implementation.
+ * Here, the CompositionManager will act as a factory (the create method will return the component implementation object), the
+ * CompositionManager.getComposition() method will return all the objects that are also part of the component implementation,
+ * and all of them will be searched for injecting any of the dependencies.
*
* @param <U> the type of the object returned by the supplier factory
* @param factory the function used to create the Factory itself
@@ -122,9 +126,9 @@
<U> B factory(Supplier<U> factory, Function<U, ?> create, Function<U, Object[]> getComposition);
/**
- * Sets the public interfaces under which this component should be registered in the OSGi service registry.
+ * Sets the public interface under which this component should be registered in the OSGi service registry.
*
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @return this builder
*/
B provides(Class<?> iface);
@@ -132,7 +136,7 @@
/**
* Sets the public interface under which this component should be registered in the OSGi service registry.
*
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @param name a property name for the provided service
* @param value a property value for the provided service
* @param rest the rest of property name/value pairs.
@@ -150,7 +154,7 @@
* provides(MyService.class, property1 -> "value1", property2 -> 123);
* }</pre>
*
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @param properties a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
* {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
* @return this builder.
@@ -159,7 +163,7 @@
/**
* Sets the public interface under which this component should be registered in the OSGi service registry.
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @param properties the properties for the provided service
* @return this builder.
*/
@@ -202,6 +206,7 @@
/**
* Sets the public interfaces under which this component should be registered in the OSGi service registry.
+ *
* @param ifaces the public interfaces to register in the OSGI service registry.
* @param properties the properties for the provided service
* @return this builder.
@@ -219,7 +224,7 @@
/**
* Sets the public interface under which this component should be registered in the OSGi service registry.
*
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @param name a property name for the provided service
* @param value a property value for the provided service
* @param rest the rest of property name/value pairs.
@@ -236,7 +241,7 @@
* provides(MyService.class, property1 -> "value1", property2 -> 123);
* }</pre>
*
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @param properties a list of fluent service properties for the provided service. You can specify a list of lambda expression, each one implementing the
* {@link FluentProperty} interface that allows to define a property name using a lambda parameter.
* @return this builder.
@@ -245,7 +250,7 @@
/**
* Sets the public interface under which this component should be registered in the OSGi service registry.
- * @param iface the public interfaces to register in the OSGI service registry.
+ * @param iface the public interface to register in the OSGI service registry.
* @param properties the properties for the provided service
* @return this builder.
*/
@@ -288,6 +293,7 @@
/**
* Sets the public interfaces under which this component should be registered in the OSGi service registry.
+ *
* @param ifaces the public interfaces to register in the OSGI service registry.
* @param properties the properties for the provided service
* @return this builder.
@@ -339,14 +345,14 @@
* @param filter the service filter
* @return this builder
*/
- B withSrv(Class<?> service, String filter);
+ B withSvc(Class<?> service, String filter);
/**
* Adds in one shot multiple required/autoconfig service dependencies.
* @param services the dependencies that are required and that will be injected in any field with the same dependency type.
* @return this builder
*/
- B withSrv(Class<?> ... services);
+ B withSvc(Class<?> ... services);
/**
* Adds a service dependency built using a Consumer lambda that is provided with a ServiceDependencyBuilder.
@@ -356,7 +362,7 @@
* @param consumer the lambda for building the service dependency
* @return this builder.
*/
- <U> B withSrv(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer);
+ <U> B withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer);
/**
* Adds a configuration dependency.
@@ -377,17 +383,6 @@
}
/**
- * Adds multiple configuration dependencies in one single call.
- * @param pids list of configuration pids
- * @return this builder
- */
- @SuppressWarnings("unchecked")
- default B withCnf(Class<?> ... pids) {
- Stream.of(pids).forEach(pid -> withCnf(cnf -> cnf.pid(pid)));
- return (B) this;
- }
-
- /**
* Adds a bundle dependency.
* @param consumer the lambda used to build the bundle dependency.
* @return this builder.
@@ -405,6 +400,25 @@
<U> B withFuture(CompletableFuture<U> future, Consumer<FutureDependencyBuilder<U>> consumer);
/**
+ * Sets the instance to invoke with the reflection based lifecycle callbacks. By default, reflection based
+ * lifecycle callbacks (init/start/stop/destroy) methods are invoked on the component implementation instance(s).
+ * But you can set a specific callback instance using this method.
+ * <p>
+ * Specifying an instance means you can create a manager
+ * that will be invoked whenever the life cycle of a component changes and this manager
+ * can then decide how to expose this life cycle to the actual component, offering an
+ * important indirection when developing your own component models.
+ *
+ * @see #init(String)
+ * @see #start(String)
+ * @see #stop(String)
+ * @see #destroy(String)
+ * @param lifecycleCallbackInstance the instance the lifecycle callback will be invoked on.
+ * @return this builder.
+ */
+ B lifecycleCallbackInstance(Object lifecycleCallbackInstance);
+
+ /**
* Sets the name of the method used as the "init" callback. This method, when found, is
* invoked as part of the life cycle management of the component implementation.
* This method is useful because when it is invoked, all required dependencies defines in the Activator
@@ -466,165 +480,100 @@
* @return this builder.
*/
B destroy(String callback);
-
+
/**
- * Sets the name of the methods used as init callback that is invoked on a given Object instance.
- * These methods, when found, are invoked on the specified instance as part of the life cycle management
- * of the component implementation.
- * <p>
- * Specifying an instance means you can create a manager
- * that will be invoked whenever the life cycle of a component changes and this manager
- * can then decide how to expose this life cycle to the actual component, offering an
- * important indirection when developing your own component models.
- *
- * @see #init(String)
- * @param callbackInstance the instance the callback will be invoked on.
- * @param callback the callback name
- * @return this builder.
- */
- B init(Object callbackInstance, String callback);
-
- /**
- * Sets the name of the methods used as start callback that is invoked on a given Object instance.
- * These methods, when found, are invoked on the specified instance as part of the life cycle management
- * of the component implementation.
- * <p>
- * Specifying an instance means you can create a manager
- * that will be invoked whenever the life cycle of a component changes and this manager
- * can then decide how to expose this life cycle to the actual component, offering an
- * important indirection when developing your own component models.
- *
- * @see #start(String)
- * @param callbackInstance the instance the callback will be invoked on.
- * @param callback the name of the start method
- * @return this builder.
- */
- B start(Object callbackInstance, String callback);
-
- /**
- * Sets the name of the methods used as stop callback that is invoked on a given Object instance.
- * These methods, when found, are invoked on the specified instance as part of the life cycle management
- * of the component implementation.
- * <p>
- * Specifying an instance means you can create a manager
- * that will be invoked whenever the life cycle of a component changes and this manager
- * can then decide how to expose this life cycle to the actual component, offering an
- * important indirection when developing your own component models.
- *
- * @see #stop(String)
- * @param callbackInstance the instance the callback will be invoked on.
- * @param callback the name of the stop method
- * @return this builder.
- */
- B stop(Object callbackInstance, String callback);
-
- /**
- * Sets the name of the methods used as destroy callback that is invoked on a given Object instance.
- * These methods, when found, are invoked on the specified instance as part of the life cycle management
- * of the component implementation.
- * <p>
- * Specifying an instance means you can create a manager
- * that will be invoked whenever the life cycle of a component changes and this manager
- * can then decide how to expose this life cycle to the actual component, offering an
- * important indirection when developing your own component models.
- *
- * @see #destroy(String)
- * @param callbackInstance the instance the callback will be invoked on.
- * @param callback the name of the destroy method
- * @return this builder.
- */
- B destroy(Object callbackInstance, String callback);
-
- /**
- * Sets a method reference used as the "init" callback. This method reference must point to method from one
- * of the component instance classes. It is invoked as part of the life cycle management of the component implementation.
+ * Sets a reference to a component implementation class "init" callback method.
+ * This method does not take any arguments and is
+ * invoked as part of the life cycle management of the component implementation.
* This method is useful because when it is invoked, all required dependencies defines in the Activator
* are already injected, and you can then add more extra dependencies from the init() method.
* And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
- * The method does not take any parameters.
*
- * @param <U> the type of the component class on which the callback is invoked on.
- * @param callback a method reference must point to method from one of the component instance classes.
+ * @param <T> the type of the component class on which the callback is invoked on.
+ * @param callback a method reference must point to method from the component instance class(es).
* @return this builder
*/
- <U> B init(CbConsumer<U> callback);
+ <T> B init(Cb<T> callback);
/**
- * Sets a method reference used as the "start" callback. This method reference must point to method from one
- * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
+ * Sets a reference to a component implementation class "start" callback method.
+ * This method does not take any arguments and is
+ * invoked as part of the life cycle management of the component implementation.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes.
* @return this builder.
*/
- <U> B start(CbConsumer<U> callback);
+ <T> B start(Cb<T> callback);
/**
- * Sets a method reference used as the "stop" callback. This method reference must point to method from one
- * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
+ * Sets a reference to a component implementation class "stop" callback method.
+ * This method does not take any arguments and is
+ * invoked as part of the life cycle management of the component implementation.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes.
* @return this builder.
*/
- <U> B stop(CbConsumer<U> callback);
+ <T> B stop(Cb<T> callback);
/**
- * Sets a method reference used as the "destroy" callback. This method reference must point to method from one
- * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
+ * Sets a reference to a component implementation class "destroy" callback method.
+ * This method does not take any arguments and is
+ * invoked as part of the life cycle management of the component implementation.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes.
* @return this builder.
*/
- <U> B destroy(CbConsumer<U> callback);
+ <T> B destroy(Cb<T> callback);
/**
- * Sets a method reference used as the "init" callback. This method reference must point to method from one
- * of the component instance classes. It is invoked as part of the life cycle management of the component implementation.
+ * Sets a reference to a component implementation class "init" callback method.
+ * This method takes a Component argument and is
+ * invoked as part of the life cycle management of the component implementation.
* This method is useful because when it is invoked, all required dependencies defines in the Activator
* are already injected, and you can then add more extra dependencies from the init() method.
* And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
- * The method takes as argument a Component parameter.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
* @return this builder
*/
- <U> B init(CbTypeComponent<U> callback);
+ <T> B init(CbComponent<T> callback);
/**
- * Sets a method reference used as the "start" callback. This method reference must point to method from one
- * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
- * The method takes as argument a Component parameter.
+ * Sets a reference to a component implementation class "start" callback method.
+ * This method takes a Component argument and is
+ * invoked as part of the life cycle management of the component implementation.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
* @return this builder.
*/
- <U> B start(CbTypeComponent<U> callback);
+ <T> B start(CbComponent<T> callback);
/**
- * Sets a method reference used as the "stop" callback. This method reference must point to method from one
- * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
- * The method takes as argument a Component parameter.
+ * Sets a reference to a component implementation class "stop" callback method.
+ * This method takes a Component argument and is
+ * invoked as part of the life cycle management of the component implementation.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
* @return this builder.
*/
- <U> B stop(CbTypeComponent<U> callback);
+ <T> B stop(CbComponent<T> callback);
/**
- * Sets a method reference used as the "destroy" callback. This method reference must point to method from one
- * of the component instance classes. This method is invoked as part of the life cycle management of the component implementation.
- * The method takes as argument a Component parameter.
+ * Sets a reference to a component implementation class "destroy" callback method.
+ * This method takes a Component argument and is
+ * invoked as part of the life cycle management of the component implementation.
*
- * @param <U> the type of the component class on which the callback is invoked on.
+ * @param <T> the type of the component class on which the callback is invoked on.
* @param callback a method reference must point to method from one of the component instance classes. The method takes as argument a Component parameter.
* @return this builder.
*/
- <U> B destroy(CbTypeComponent<U> callback);
+ <T> B destroy(CbComponent<T> callback);
/**
* Sets an Object instance method reference used as the "init" callback. It is invoked as part of the life cycle management of the component
@@ -637,7 +586,7 @@
* @param callback an Object instance method reference. The method does not take any parameters.
* @return this builder
*/
- B initInstance(Runnable callback);
+ B initInstance(InstanceCb callback);
/**
* Sets an Object instance method reference used as the "start" callback. This method reference must point to method from one
@@ -647,7 +596,7 @@
* @param callback an Object instance method reference. The method does not take any parameters.
* @return this builder.
*/
- B startInstance(Runnable callback);
+ B startInstance(InstanceCb callback);
/**
* Sets an Object instance method reference used as the "stop" callback. It is invoked as part of the life cycle management of the component
@@ -660,7 +609,7 @@
* @param callback an Object instance method reference. The method does not take any parameters.
* @return this builder
*/
- B stopInstance(Runnable callback);
+ B stopInstance(InstanceCb callback);
/**
* Sets an Object instance method reference used as the "destroy" callback. It is invoked as part of the life cycle management of the component
@@ -673,7 +622,7 @@
* @param callback an Object instance method reference. The method does not take any parameters.
* @return this builder
*/
- B destroyInstance(Runnable callback);
+ B destroyInstance(InstanceCb callback);
/**
* Sets an Object instance method reference used as the "init" callback. It is invoked as part of the life cycle management of the component
@@ -683,10 +632,10 @@
* And once all extra dependencies will be available and injected, then the "start" callback will be invoked.
* The method takes as argument a Component parameter.
*
- * @param callback an Object instance method reference.
+ * @param callback an Object instance method reference. The method takes as argument a Component parameter.
* @return this builder
*/
- B initInstance(CbComponent callback);
+ B initInstance(InstanceCbComponent callback);
/**
* Sets an Object instance method reference used as the "start" callback. This method reference must point to method from one
@@ -696,7 +645,7 @@
* @param callback an Object instance method reference. The method takes as argument a Component parameter.
* @return this builder.
*/
- B startInstance(CbComponent callback);
+ B startInstance(InstanceCbComponent callback);
/**
* Sets an Object instance method reference used as the "stop" callback. This method reference must point to method from one
@@ -706,7 +655,7 @@
* @param callback an Object instance method reference. The method takes as argument a Component parameter.
* @return this builder.
*/
- B stopInstance(CbComponent callback);
+ B stopInstance(InstanceCbComponent callback);
/**
* Sets an Object instance method reference used as the "destroy" callback. This method reference must point to method from one
@@ -716,7 +665,7 @@
* @param callback an Object instance method reference. The method takes as argument a Component parameter.
* @return this builder.
*/
- B destroyInstance(CbComponent callback);
+ B destroyInstance(InstanceCbComponent callback);
/**
* Configures OSGi object (BundleContext, Component, etc ...) that will be injected in any field having the same OSGi object type.
@@ -753,7 +702,7 @@
/**
* Sets the method to invoke on the service implementation to get back all
* instances that are part of a composition and need dependencies injected.
- * All of them will be searched for any of the dependencies. The method that
+ * All of them will be searched to inject any of the dependencies. The method that
* is invoked must return an <code>Object[]</code>.
*
* @param getCompositionMethod the method to invoke
@@ -764,7 +713,7 @@
/**
* Sets the instance and method to invoke to get back all instances that
* are part of a composition and need dependencies injected. All of them
- * will be searched for any of the dependencies. The method that is
+ * will be searched to inject any of the dependencies. The method that is
* invoked must return an <code>Object[]</code>.
*
* @param instance the instance that has the method
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java
index c91a7fd..60a3537 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java
@@ -1,24 +1,128 @@
package org.apache.felix.dm.lambda;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Map;
+
import org.apache.felix.dm.ConfigurationDependency;
-import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.CbConfigurationComponent;
import org.apache.felix.dm.lambda.callbacks.CbDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbDictionaryComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
/**
* Builds a Dependency Manager Configuration Dependency.
- * By default, the updated callback is "updated", like in original DM API.
+ * Two families of callbacks are supported: <p>
*
- * <p> Code example with a component that defines a Configuration Dependency. the ServiceImpl modified method
- * callback is declared using a method reference (see the "cb(ServiceImpl::modified)" code):
+ * <ul>
+ * <li>reflection based callbacks: you specify a callback method name
+ * <li>method reference callbacks: you specify a java8 method reference
+ * </ul>
+ *
+ * <p> Callbacks may accept a Dictionary, a Component, or a user defined configuration type interface.
+ *
+ * If you only specify a pid, by default the callback method name is assumed to be "updated".
+ *
+ * <p> Configuration types are a new feature that allows you to specify an interface that is implemented
+ * by DM and such interface is then injected to your callback instead of the actual Dictionary.
+ * Using such configuration interface provides a way for creating type-safe configurations from a actual {@link Dictionary} that is
+ * normally injected by Dependency Manager.
+ * The callback accepts in argument an interface that you have to provide, and DM will inject a proxy that converts
+ * method calls from your configuration-type to lookups in the actual map or dictionary. The results of these lookups are then
+ * converted to the expected return type of the invoked configuration method.<br>
+ * As proxies are injected, no implementations of the desired configuration-type are necessary!
+ * </p>
+ * <p>
+ * The lookups performed are based on the name of the method called on the configuration type. The method names are
+ * "mangled" to the following form: <tt>[lower case letter] [any valid character]*</tt>. Method names starting with
+ * <tt>get</tt> or <tt>is</tt> (JavaBean convention) are stripped from these prefixes. For example: given a dictionary
+ * with the key <tt>"foo"</tt> can be accessed from a configuration-type using the following method names:
+ * <tt>foo()</tt>, <tt>getFoo()</tt> and <tt>isFoo()</tt>.
+ * </p>
+ * <p>
+ * The return values supported are: primitive types (or their object wrappers), strings, enums, arrays of
+ * primitives/strings, {@link Collection} types, {@link Map} types, {@link Class}es and interfaces. When an interface is
+ * returned, it is treated equally to a configuration type, that is, it is returned as a proxy.
+ * </p>
+ * <p>
+ * Arrays can be represented either as comma-separated values, optionally enclosed in square brackets. For example:
+ * <tt>[ a, b, c ]</tt> and <tt>a, b,c</tt> are both considered an array of length 3 with the values "a", "b" and "c".
+ * Alternatively, you can append the array index to the key in the dictionary to obtain the same: a dictionary with
+ * "arr.0" => "a", "arr.1" => "b", "arr.2" => "c" would result in the same array as the earlier examples.
+ * </p>
+ * <p>
+ * Maps can be represented as single string values similarly as arrays, each value consisting of both the key and value
+ * separated by a dot. Optionally, the value can be enclosed in curly brackets. Similar to array, you can use the same
+ * dot notation using the keys. For example, a dictionary with
+ *
+ * <pre>{@code "map" => "{key1.value1, key2.value2}"}</pre>
+ *
+ * and a dictionary with <p>
+ *
+ * <pre>{@code "map.key1" => "value1", "map2.key2" => "value2"}</pre>
+ *
+ * result in the same map being returned.
+ * Instead of a map, you could also define an interface with the methods <tt>getKey1()</tt> and <tt>getKey2</tt> and use
+ * that interface as return type instead of a {@link Map}.
+ * </p>
+ * <p>
+ * In case a lookup does not yield a value from the underlying map or dictionary, the following rules are applied:
+ * <ol>
+ * <li>primitive types yield their default value, as defined by the Java Specification;
+ * <li>string, {@link Class}es and enum values yield <code>null</code>;
+ * <li>for arrays, collections and maps, an empty array/collection/map is returned;
+ * <li>for other interface types that are treated as configuration type a null-object is returned.
+ * </ol>
+ * </p>
+ *
+ * <b> Sample codes: </b>
+ *
+ * <p> Code example with a component that defines a Configuration Dependency using a specific callback method reference,
+ * and the method accepts in argument a configuration type (the pid is assumed to be the fqdn of the configuration type):
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* component(comp -> comp
* .impl(ServiceImpl.class)
- * .withConf(conf -> conf.pid(ServiceConsumer.class).cb(ServiceImpl::modified)));
+ * .withConf(conf -> conf.update(MyConfig.class, ServiceImpl::modified)));
+ * }
+ * }
+ * }</pre>
+ *
+ * <p> Code example with a component that defines a Configuration Dependency using a specific callback method reference
+ * which accepts a Dictionary in argument:
+ *
+ * <pre> {@code
+ * public class Activator extends DependencyManagerActivator {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * component(comp -> comp
+ * .impl(ServiceImpl.class)
+ * .withConf(conf -> conf.pid("my.pid").update(ServiceImpl::modified)));
+ * }
+ * }
+ * }</pre>
+ *
+ * <p> Code example which defines a configuration dependency injected in the "ServiceImpl.updated(Dictionary)" callback:
+ *
+ * <pre> {@code
+ * public class Activator extends DependencyManagerActivator {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * component(comp -> comp.impl(ServiceImpl.class).withConf("my.pid"));
+ * }
+ * }
+ * }</pre>
+ *
+ * <p> Code example with a component that defines a Configuration Dependency using a specific callback method name:
+ *
+ * <pre> {@code
+ * public class Activator extends DependencyManagerActivator {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * component(comp -> comp.impl(ServiceImpl.class).withConf(conf -> conf.pid("my.pid").update("modified")));
* }
* }
* }</pre>
@@ -29,21 +133,13 @@
/**
* Sets the pid for this configuration dependency.
*
- * @param pid the configuration dependendency pid.
+ * @param pid the configuration dependency pid.
* @return this builder
*/
ConfigurationDependencyBuilder pid(String pid);
/**
- * Sets the class which fqdn represents the pid for this configuration dependency. Usually, this class can optionally be annotated with metatypes bnd annotations.
- *
- * @param pidClass the class which fqdn represents the pid for this configuration dependency.
- * @return this builder
- */
- ConfigurationDependencyBuilder pid(Class<?> pidClass);
-
- /**
- * Sets propagation of the configuration properties to the service properties (false by default).
+ * Sets propagation of the configuration to the service properties (false by default).
* All public configuration properties (not starting with a dot) will be propagated to the component service properties.
*
* @return this builder
@@ -57,73 +153,146 @@
* @return this builder
*/
ConfigurationDependencyBuilder propagate(boolean propagate);
-
+
/**
- * Configures whether or not the component instance should be instantiated at the time the updated callback is invoked.
- * By default, when the callback is applied on an external object instance, the component is not instantiated, but in this case
- * you can force the creation of the component instances by calling this method.
- *
- * @param needsInstance true if the component instance should be instantiated at the time the updated callback is invoked on an external object instance.
+ * Sets a callback method to call on the component implementation class(es) when the configuration is updated. When the configuration is lost, the callback is invoked
+ * with a null dictionary. The following callback signatures are supported and searched in the following order:
+ * <ol>
+ * <li>method(Dictionary)</li>
+ * <li>method(Component, Dictionary)</li>
+ * </ol>
+ *
+ * @param updateMethod the name of the callback
* @return this builder
*/
- ConfigurationDependencyBuilder needsInstance(boolean needsInstance);
+ ConfigurationDependencyBuilder update(String updateMethod);
/**
- * Sets a <code>callback</code> to call on the component instance(s) when the configuration is updated.
+ * Sets a callback method to call on the component implementation class(es) when the configuration is updated. The callback is invoked with a configuration type
+ * argument (null if the configuration is lost).
*
+ * @param configType the type of a configuration that is passed as argument to the callback
* @param updateMethod the callback to call on the component instance(s) when the configuration is updated.
* @return this builder
*/
- ConfigurationDependencyBuilder cb(String updateMethod);
+ ConfigurationDependencyBuilder update(Class<?> configType, String updateMethod);
/**
- * Sets a <code>callback instance</code> to call on a given object instance when the configuration is updated.
- * When the updated method is invoked, the Component implementation has not yet been instantiated, unless you have called
- * the @link {@link #needsInstance(boolean)} method with "true".
+ * Sets a callback method to call on a given Object instance when the configuration is updated.
+ * When the updated method is invoked, the Component implementation is not yet instantiated. This method
+ * can be typically used by a Factory object which needs the configuration before it can create the actual
+ * component implementation instance(s).
+ *
+ * When the configuration is lost, the callback is invoked with a null dictionary, and the following signatures are supported:
+ * <ol>
+ * <li>method(Dictionary)</li>
+ * <li>method(Component, Dictionary)</li>
+ * </ol>
*
* @param callbackInstance the object instance on which the updatedMethod is invoked
* @param updateMethod the callback to call on the callbackInstance when the configuration is updated.
* @return this builder
*/
- ConfigurationDependencyBuilder cbi(Object callbackInstance, String updateMethod);
+ ConfigurationDependencyBuilder update(Object callbackInstance, String updateMethod);
/**
- * Sets a <code>callback</code> method reference used to invoke an update method. The method reference must point to a method from one of the component
- * implementation classes, and is invoked when the configuration is updated.
- *
- * @param <T> the type of the component implementation class on which the callback is invoked on.
- * @param callback the callback method reference which must point to a method from one of the component implementation classes. The method
- * takes as argument a Dictionary.
+ * Sets a callback method to call on a given Object instance when the configuration is updated.
+ * When the updated method is invoked, the Component implementation is not yet instantiated. This method
+ * can be typically used by a Factory object which needs the configuration before it can create the actual
+ * component implementation instance(s).
+ * The callback is invoked with a configuration type argument (null of the configuration is lost).
+ *
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callbackInstance the object instance on which the updatedMethod is invoked
+ * @param updateMethod the callback to call on the callbackInstance when the configuration is updated.
* @return this builder
*/
- <T> ConfigurationDependencyBuilder cb(CbTypeDictionary<T> callback);
+ ConfigurationDependencyBuilder update(Class<?> configType, Object callbackInstance, String updateMethod);
+
+ /**
+ * Sets a reference to a "callback(Dictionary)" method from one of the component implementation classes.
+ * The method is invoked with a Dictionary argument (which is null if the configuration is lost).
+ *
+ * @param <T> The type of the target component implementation class on which the method is invoked
+ * @param callback a reference to a method of one of the component implementation classes.
+ * @return this builder
+ */
+ <T> ConfigurationDependencyBuilder update(CbDictionary<T> callback);
+
+ /**
+ * Sets a reference to a "callback(Dictionary, Component)" method from one of the component implementation classes.
+ * The method is invoked with Dictionary/Component arguments. When the configuration is lost, the Dictionary argument
+ * is null.
+ *
+ * @param <T> The type of the target component implementation class on which the method is invoked
+ * @param callback a reference to a method callback defined in one of the the component implementation classes.
+ * @return this builder
+ */
+ <T> ConfigurationDependencyBuilder update(CbDictionaryComponent<T> callback);
+
+ /**
+ * Sets a reference to a "callback(Configuration)" method from one of the component implementation classes.
+ * The method is invoked with a configuration type argument (null if the configuration is lost).
+ *
+ * @param <T> The type of the target component implementation class on which the method is invoked
+ * @param <U> the type of the configuration interface accepted by the callback method.
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callback the callback method reference which must point to a method from one of the component implementation classes. The method
+ * takes as argument an interface which will be implemented by a dynamic proxy that wraps the actual configuration properties.
+ * @return this builder
+ */
+ <T, U> ConfigurationDependencyBuilder update(Class<U> configType, CbConfiguration<T, U> callback);
/**
- * Sets the <code>callback</code> method reference used to invoke an update method. The method reference must point to a method from one of the
- * component implementation classes, and is invoked when the configuration is updated.
+ * Sets a reference to a "callback(configType, Component)" method from one of the component implementation classes.
+ * The method is invoked with two args: configuration type, Component. The configuration type argument is null if the configuration is lost.
*
- * @param <T> the type of the component implementation class on which the callback is invoked on.
- * @param callback the callback method reference used to invoke an update method on the component instance(s) when the configuration is updated.
- * The method takes as argument a Component and a Dictionary.
+ * @param <T> The type of the target component implementation class on which the method is invoked
+ * @param <U> the type of the configuration interface accepted by the callback method.
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callback the reference to a method from one of the component implementation classes. The method
+ * takes as argument an interface which will be implemented by a dynamic proxy that wraps the actual configuration properties. It also
+ * takes as the second argument a Component object.
* @return this builder
*/
- <T> ConfigurationDependencyBuilder cb(CbTypeComponentDictionary<T> callback);
-
+ <T, U> ConfigurationDependencyBuilder update(Class<U> configType, CbConfigurationComponent<T, U> callback);
+
/**
- * Sets a <code>callback instance</code> method reference used to invoke the update method. The method reference must point to an Object instance
- * method which takes as argument a Dictionary.
+ * Sets a reference to a "callback(Dictionary)" method from an Object instance.
*
- * @param updated a method reference that points to an Object instance method which takes as argument a Dictionary.
+ * @param callback a reference to an Object instance which takes as argument a Dictionary (null if the configuration is lost).
* @return this builder
*/
- ConfigurationDependencyBuilder cbi(CbDictionary updated);
+ ConfigurationDependencyBuilder update(InstanceCbDictionary callback);
+
+ /**
+ * Sets a reference to a "callback(Dictionary, Component)" method from an Object instance. The method accepts
+ * a Dictionary and a Component object. The passed Dictionary is null in case the configuration is lost.
+ *
+ * @param callback a reference to method from an Object instance which takes as argument a Dictionary and a Component
+ * @return this builder
+ */
+ ConfigurationDependencyBuilder update(InstanceCbDictionaryComponent callback);
/**
- * Sets a <code>callback instance</code> method reference used to invoke the update method. The method reference must point to an Object instance method
- * which takes as argument a Component and a Dictionary.
- *
- * @param updated a method reference that points to an Object instance method which takes as argument a Component and a Dictionary.
+ * Sets a reference to a "callback(ConfigType)" method from an Object instance. The configuration type argument is null if the configuration is lost.
+ *
+ * @param <T> the type of the configuration interface accepted by the callback method.
+ * @param configType the class of the configuration that is passed as argument to the callback
+ * @param updated a reference to an Object instance which takes as argument the given configuration type
* @return this builder
*/
- ConfigurationDependencyBuilder cbi(CbComponentDictionary updated);
+ <T> ConfigurationDependencyBuilder update(Class<T> configType, InstanceCbConfiguration<T> updated);
+
+ /**
+ * Sets a reference to a "callback(Configuration, Component)" method from an Object instance. The method accepts
+ * a configuration type and a Component object. The configuration type argument is null if the configuration is lost.
+ *
+ * @param <T> the type of the configuration interface accepted by the callback method.
+ * @param configType the class of the configuration that is passed as argument to the callback
+ * @param updated a reference to an Object instance which takes as argument a the given configuration type, and a Component object.
+ * @return this builder
+ */
+ <T> ConfigurationDependencyBuilder update(Class<T> configType, InstanceCbConfigurationComponent<T> updated);
}
+
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java
index ba8b078..2c2482e 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java
@@ -27,11 +27,11 @@
* import org.apache.felix.dm.lambda.DependencyManagerActivator;
*
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* component(comp -> comp
* .provides(Service.class, property -> "value")
* .impl(ServiceImpl.class)
- * .withSrv(LogService.class, ConfigurationAdmni.class) // both services are required and injected in class fields with compatible types.
+ * .withSvc(LogService.class, ConfigurationAdmni.class) // both services are required and injected in class fields with compatible types.
* }
* }
* }</pre>
@@ -42,12 +42,12 @@
* import org.apache.felix.dm.lambda.DependencyManagerActivator;
*
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* component(comp -> comp
* .provides(Service.class, property -> "value")
* .impl(ServiceImpl.class)
- * .withSrv(LogService.class, log -> log.cb("setLog"))
- * .withSrv(ConfigurationAdmni.class, cm -> cm.cb("setConfigAdmin")))
+ * .withSvc(LogService.class, svc -> svc.add("setLog"))
+ * .withSvc(ConfigurationAdmni.class, svc -> svc.add("setConfigAdmin")))
* }
* }
* }</pre>
@@ -58,12 +58,12 @@
* import org.apache.felix.dm.lambda.DependencyManagerActivator;
*
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* component(comp -> comp
* .provides(Service.class, property -> "value")
* .impl(ServiceImpl.class)
- * .withSrv(LogService.class, log -> log.cb(ServiceImpl::setLog))
- * .withSrv(ConfigurationAdmni.class, cm -> cm.cb(ServiceImpl::setConfigAdmin)))
+ * .withSvc(LogService.class, svc -> svc.add(ServiceImpl::setLog))
+ * .withSvc(ConfigurationAdmni.class, svc -> svc.add(ServiceImpl::setConfigAdmin)))
* }
* }
* }</pre>
@@ -80,7 +80,7 @@
@Override
public void start(BundleContext context) throws Exception {
m_manager = new DependencyManager(context);
- activate();
+ init(context, m_manager);
}
/**
@@ -88,21 +88,22 @@
*/
@Override
public void stop(BundleContext context) throws Exception {
- deactivate();
+ destroy();
}
/**
* Sub classes must override this method in order to build some DM components.
- *
+ * @param ctx the context associated to the bundle
+ * @param dm the DependencyManager assocaited to this activator
* @throws Exception if the activation fails
*/
- protected abstract void activate() throws Exception;
+ protected abstract void init(BundleContext ctx, DependencyManager dm) throws Exception;
/**
* Sub classes may override this method that is called when the Activator is stopped.
* @throws Exception if the deactivation fails
*/
- protected void deactivate() throws Exception {
+ protected void destroy() throws Exception {
}
/**
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java
index 909109c..b5771b5 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java
@@ -1,26 +1,56 @@
package org.apache.felix.dm.lambda;
-import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.CbConfigurationComponent;
import org.apache.felix.dm.lambda.callbacks.CbDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbDictionaryComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
/**
* Builds a Dependency Manager Factory Configuration Adapter Component. For each new Config Admin factory configuration matching the factoryPid,
* an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface,
* and with the specified adapter service properties. Depending on the propagate parameter, every public factory configuration properties
- * (which don't start with ".") will be propagated along with the adapter service properties.
+ * (which don't start with ".") will be propagated along with the adapter service properties.
+ *
+ * This builded supports type safe configuration types. For a given factory configuration, you can specify an interface of your choice,
+ * and DM will implement it using a dynamic proxy that converts interface methods to lookups in the actual factory configuration dictionary.
*
* <p> Example that defines a factory configuration adapter service for the "foo.bar" factory pid:
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* factoryPidAdapter(adapter -> adapter
* .impl(DictionaryImpl.class)
- * .factoryPid("foo.bar").cb(ServiceImpl::updated)
+ * .factoryPid("foo.bar")
+ * .update(ServiceImpl::updated)
* .propagate()
- * .withSrv(LogService.class, log -> log.optional()));
+ * .withSvc(LogService.class, log -> log.optional()));
+ * }
+ * }
+ * }</pre>
+ *
+ * <p> Example that defines a factory configuration adapter using a user defined configuration type
+ * (the pid is by default assumed to match the fqdn of the configuration type):
+ *
+ * <pre> {@code
+ *
+ * public interface DictionaryConfiguration {
+ * public String getLanguage();
+ * public List<String> getWords();
+ * }
+ *
+ * public class Activator extends DependencyManagerActivator {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * factoryPidAdapter(adapter -> adapter
+ * .impl(DictionaryImpl.class)
+ * .factoryPid("foo.bar")
+ * .update(DictionaryConfiguration.class, ServiceImpl::updated)
+ * .propagate()
+ * .withSvc(LogService.class, log -> log.optional()));
* }
* }
* }</pre>
@@ -32,29 +62,25 @@
* @return this builder
*/
FactoryPidAdapterBuilder factoryPid(String pid);
-
- /**
- * Specifies a class name which fqdn represents the factory pid. Usually, this class can optionally be annotated with metatypes bnd annotations.
- * @param pidClass the class that acts as the factory pid
- * @return this builder
- */
- FactoryPidAdapterBuilder factoryPid(Class<?> pidClass);
-
+
/**
* Specifies if the public properties (not starting with a dot) should be propagated in the adapter service properties (false by default).
+ *
* @return this builder.
*/
FactoryPidAdapterBuilder propagate();
/**
* Specifies if the public properties (not starting with a dot) should be propagated in the adapter service properties (false by default).
+ *
* @param propagate true if the public properties should be propagated in the adapter service properties (false by default).
* @return this builder.
*/
FactoryPidAdapterBuilder propagate(boolean propagate);
/**
- * Specifies a callback method that will be called on the component instances when the configuration is injected
+ * Specifies a callback method that will be called on the component instances when the configuration is injected.
+ *
* @param updateMethod the method to call on the component instances when the configuration is available ("updated" by default).
* The following method signatures are supported:
*
@@ -65,10 +91,21 @@
*
* @return this builder
*/
- FactoryPidAdapterBuilder cb(String updateMethod);
+ FactoryPidAdapterBuilder update(String updateMethod);
/**
- * Specifies a callback instance method that will be called on a given object instance when the configuration is injected
+ * Sets a callback method to call on the component implementation class(es) when the configuration is updated.
+ * The callback is invoked with a configuration type argument.
+ *
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param updateMethod the callback to call on the component instance(s) when the configuration is updated.
+ * @return this builder
+ */
+ FactoryPidAdapterBuilder update(Class<?> configType, String updateMethod);
+
+ /**
+ * Specifies a callback instance method that will be called on a given object instance when the configuration is injected.
+ *
* @param updateMethod the method to call on the given object instance when the configuration is available ("updated" by default).
* The following method signatures are supported:
*
@@ -80,41 +117,101 @@
* @param callbackInstance the Object instance on which the updated callback will be invoked.
* @return this builder
*/
- FactoryPidAdapterBuilder cb(Object callbackInstance, String updateMethod);
+ FactoryPidAdapterBuilder update(Object callbackInstance, String updateMethod);
/**
- * Specifies a callback method reference that will be called on one of the component classes when the configuration is injected.
+ * Specifies a callback instance method that will be called on a given object instance when the configuration is injected.
+ * The callback is invoked with a configuration type argument.
*
- * @param <U> the type of the component implementation class on which the callback is invoked on.
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callbackInstance the Object instance on which the updated callback will be invoked.
+ * @param updateMethod the method to call on the given object instance when the configuration is available. The callback is invoked
+ * with a configuration type argument (matching the configType you have specified.
+ * @return this builder
+ */
+ FactoryPidAdapterBuilder update(Class<?> configType, Object callbackInstance, String updateMethod);
+
+ /**
+ * Specifies a method reference that will be called on one of the component classes when the configuration is injected.
+ * The callback is invoked with a Dictionary argument.
+ *
+ * @param <T> the type of the component implementation class on which the callback is invoked on.
* @param callback the method to call on one of the component classes when the configuration is available.
* @return this builder
*/
- <U> FactoryPidAdapterBuilder cb(CbTypeDictionary<U> callback);
+ <T> FactoryPidAdapterBuilder update(CbDictionary<T> callback);
/**
- * Specifies a callback method reference that will be called on one of the component classes when the configuration is injected
+ * Specifies a method reference that will be called on one of the component classes when the configuration is injected.
+ * The callback is invoked with a configuration type argument.
*
- * @param <U> the type of the component implementation class on which the callback is invoked on.
- * @param callback the reference to a method on one of the component classes. The method may takes as parameter a Component and a Dictionary.
+ * @param <T> the type of the component implementation class on which the callback is invoked on.
+ * @param <U> the configuration type accepted by the callback method.
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callback the method to call on one of the component classes when the configuration is available.
* @return this builder
*/
- <U> FactoryPidAdapterBuilder cb(CbTypeComponentDictionary<U> callback);
+ <T, U> FactoryPidAdapterBuilder update(Class<U> configType, CbConfiguration<T, U> callback);
/**
- * Specifies a callback instance method reference that will be called on a given object instance when the configuration is injected
+ * Specifies a method reference that will be called on one of the component classes when the configuration is injected
+ *
+ * @param <T> the type of the component implementation class on which the callback is invoked on.
+ * @param callback the reference to a method on one of the component classes. The method may takes as parameter a Dictionary and a Component.
+ * @return this builder
+ */
+ <T> FactoryPidAdapterBuilder update(CbDictionaryComponent<T> callback);
+
+ /**
+ * Specifies a method reference that will be called on one of the component classes when the configuration is injected.
+ * The callback is invoked with the following arguments: a configuration type, and a Component object.
+ *
+ * @param <T> the type of the component implementation class on which the callback is invoked on.
+ * @param <U> the configuration type accepted by the callback method.
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callback the reference to a method on one of the component classes. The method may takes as parameter a configuration type and a Component.
+ * @return this builder
+ */
+ <T, U> FactoryPidAdapterBuilder update(Class<U> configType, CbConfigurationComponent<T, U> callback);
+
+ /**
+ * Specifies a method reference that will be called on a given object instance when the configuration is injected
*
* @param callback the method to call on a given object instance when the configuration is available. The callback takes as argument a
* a Dictionary parameter.
* @return this builder
*/
- FactoryPidAdapterBuilder cbi(CbDictionary callback);
+ FactoryPidAdapterBuilder update(InstanceCbDictionary callback);
/**
- * Specifies a callback instance method reference that will be called on a given object instance when the configuration is injected.
+ * Specifies a method reference that will be called on a given object instance when the configuration is injected.
+ * The callback is invoked with a type-safe configuration type argument.
*
+ * @param <T> the configuration type accepted by the callback method.
+ * @param configType the type of a configuration that is passed as argument to the callback
* @param callback the method to call on a given object instance when the configuration is available. The callback takes as argument a
- * Dictionary parameter.
+ * a configuration type parameter.
* @return this builder
*/
- FactoryPidAdapterBuilder cbi(CbComponentDictionary callback);
+ <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfiguration<T> callback);
+
+ /**
+ * Specifies a method reference that will be called on a given object instance when the configuration is injected.
+ *
+ * @param callback the method to call on a given object instance when the configuration is available. The callback takes as argument a
+ * Dictionary, and a Component parameter.
+ * @return this builder
+ */
+ FactoryPidAdapterBuilder update(InstanceCbDictionaryComponent callback);
+
+ /**
+ * Specifies a method reference that will be called on a given object instance when the configuration is injected.
+ *
+ * @param <T> the configuration type accepted by the callback method.
+ * @param configType the type of a configuration that is passed as argument to the callback
+ * @param callback the method to call on a given object instance when the configuration is available. The callback takes as argument a
+ * configuration type, and a Component parameter.
+ * @return this builder
+ */
+ <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfigurationComponent<T> callback);
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperty.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperty.java
index 3409ea3..d030bf3 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperty.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperty.java
@@ -9,7 +9,7 @@
*
* <pre>{@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* component(comp -> comp.impl(MyComponentImpl.class).provides(MyService.class, foo->"bar", foo2 -> 123));
* }
* }
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java
index 800e306..ef4a860 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java
@@ -4,7 +4,7 @@
import org.apache.felix.dm.Dependency;
import org.apache.felix.dm.lambda.callbacks.CbFuture;
-import org.apache.felix.dm.lambda.callbacks.CbTypeFuture;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbFuture;
/**
* Defines a builder for a CompletableFuture dependency.
@@ -22,7 +22,7 @@
* <pre>{@code
*
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* String url = "http://felix.apache.org/";
* CompletableFuture<String> page = CompletableFuture.supplyAsync(() -> downloadSite(url));
*
@@ -32,7 +32,7 @@
* component(comp -> comp
* .impl(MyComponent.class)
* .withService(LogService.class)
- * .withFuture(page, result -> result.cb(MyComponent::setPage)));
+ * .withFuture(page, result -> result.complete(MyComponent::setPage)));
* }
* }
*
@@ -58,7 +58,15 @@
* @param callback the callback method name to invoke on the component instances, once the CompletableFuture on which we depend has completed.
* @return this dependency.
*/
- FutureDependencyBuilder<F> cb(String callback);
+ FutureDependencyBuilder<F> complete(String callback);
+
+ /**
+ * Sets the callback instance method name to invoke on a given Object instance, once the CompletableFuture has completed.
+ * @param callbackInstance the object instance on which the callback must be invoked
+ * @param callback the callback method name to invoke on Object instance, once the CompletableFuture has completed.
+ * @return this dependency.
+ */
+ FutureDependencyBuilder<F> complete(Object callbackInstance, String callback);
/**
* Sets the function to invoke when the future task has completed. The function is from one of the Component implementation classes, and it accepts the
@@ -68,7 +76,7 @@
* @param callback the function to perform when the future task as completed.
* @return this dependency
*/
- <T> FutureDependencyBuilder<F> cb(CbTypeFuture<T, ? super F> callback);
+ <T> FutureDependencyBuilder<F> complete(CbFuture<T, ? super F> callback);
/**
* Sets the function to invoke asynchronously when the future task has completed. The function is from one of the Component implementation classes,
@@ -79,7 +87,7 @@
* @param async true if the callback should be invoked asynchronously using the default jdk execution facility, false if not.
* @return this dependency
*/
- <T> FutureDependencyBuilder<F> cb(CbTypeFuture<T, ? super F> callback, boolean async);
+ <T> FutureDependencyBuilder<F> complete(CbFuture<T, ? super F> callback, boolean async);
/**
* Sets the function to invoke asynchronously when the future task has completed. The function is from one of the Component implementation classes,
@@ -90,23 +98,15 @@
* @param executor the executor used to schedule the callback.
* @return this dependency
*/
- <T> FutureDependencyBuilder<F> cb(CbTypeFuture<T, ? super F> callback, Executor executor);
+ <T> FutureDependencyBuilder<F> complete(CbFuture<T, ? super F> callback, Executor executor);
/**
- * Sets the callback instance method name to invoke on a given Object instance, once the CompletableFuture has completed.
- * @param callbackInstance the object instance on which the callback must be invoked
- * @param callback the callback method name to invoke on Object instance, once the CompletableFuture has completed.
- * @return this dependency.
- */
- FutureDependencyBuilder<F> cbi(Object callbackInstance, String callback);
-
- /**
* Sets the callback instance to invoke when the future task has completed. The callback is a Consumer instance which accepts the
* result of the completed future.
* @param callback a Consumer instance which accepts the result of the completed future.
* @return this dependency
*/
- FutureDependencyBuilder<F> cbi(CbFuture<? super F> callback);
+ FutureDependencyBuilder<F> complete(InstanceCbFuture<? super F> callback);
/**
* Sets the callback instance to invoke when the future task has completed. The callback is a Consumer instance which accepts the
@@ -116,7 +116,7 @@
* @param async true if the callback should be invoked asynchronously using the default jdk execution facility, false if not.
* @return this dependency
*/
- FutureDependencyBuilder<F> cbi(CbFuture<? super F> callback, boolean async);
+ FutureDependencyBuilder<F> complete(InstanceCbFuture<? super F> callback, boolean async);
/**
* Sets the callback instance to invoke when the future task has completed. The callback is a Consumer instance which accepts the
@@ -125,5 +125,5 @@
* @param executor the executor to use for asynchronous execution of the callback.
* @return this dependency
*/
- FutureDependencyBuilder<F> cbi(CbFuture<? super F> callback, Executor executor);
+ FutureDependencyBuilder<F> complete(InstanceCbFuture<? super F> callback, Executor executor);
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java
index eef4890..95dd012 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java
@@ -10,7 +10,7 @@
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* adapter(Device.class, adapt -> adapt.impl(DeviceServlet.class).provides(HttpServlet.class).properties(alias -> "/device");
* }
* }}</pre>
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java
index 160975e..d611a31 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java
@@ -13,8 +13,8 @@
*
* <pre>{@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
- * aspect(LogService.class, asp -> asp.impl(SpellCheckLogAspect.class).rank(10).withSrv(Dictionary.class));
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * aspect(LogService.class, asp -> asp.impl(SpellCheckLogAspect.class).rank(10).withSvc(Dictionary.class));
* }
* }} </pre>
*
@@ -22,10 +22,11 @@
*
* <pre>{@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
- * aspect(LogService.class, asp -> asp.impl(SpellCheckLogAspect.class).rank(10)
- * .cb(SpellCheckLogAspect::setLogService)
- * .withSrv(Dictionary.class, dict -> dict.cb(SpellCheckLogAspect::setDictionary)));
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * aspect(LogService.class, asp -> asp
+ * .impl(SpellCheckLogAspect.class).rank(10)
+ * .add(SpellCheckLogAspect::setLogService)
+ * .withSvc(Dictionary.class, svc -> svc.add(SpellCheckLogAspect::setDictionary)));
* }
* }} </pre>
*
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java
index d6190bc..53723c2 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java
@@ -1,37 +1,35 @@
package org.apache.felix.dm.lambda;
-import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRef;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRefService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbRef;
-import org.apache.felix.dm.lambda.callbacks.CbRefService;
import org.apache.felix.dm.lambda.callbacks.CbRefServiceRefService;
+import org.apache.felix.dm.lambda.callbacks.CbRefServiceRefServiceComponent;
import org.apache.felix.dm.lambda.callbacks.CbService;
+import org.apache.felix.dm.lambda.callbacks.CbServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.CbServiceComponentRef;
import org.apache.felix.dm.lambda.callbacks.CbServiceDict;
import org.apache.felix.dm.lambda.callbacks.CbServiceMap;
+import org.apache.felix.dm.lambda.callbacks.CbServiceRef;
import org.apache.felix.dm.lambda.callbacks.CbServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRef;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRef;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceDict;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceMap;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceService;
+import org.apache.felix.dm.lambda.callbacks.CbServiceServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbRefServiceRefService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbRefServiceRefServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceComponentRef;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceDict;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceMap;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceRef;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceServiceComponent;
/**
* Builds a service dependency callback (required by default).
*
+ * TODO: fix javadoc for method reference (do the same as in ConfigurationDependencyBuilder: use double quotes ...
+ *
* A Service may be injected in a bind-method of a component or an object instance using this builder.
- * The builder supports the following kind of method signatures for bind methods:
+ * The builder supports reflection based callbacks (same as with the original DM API), as well as java8 method reference based callbacks.
+ *
+ * <p> <b> List of signatures supported using reflection based callbacks (same as original DM API): </b>
*
* <pre> {@code
* method(S service)
@@ -48,26 +46,29 @@
* swapMethod(Component component, S oldService, S newService)
* swapMethod(Component component, ServiceReference<S> oldRef, S old, ServiceReference<S> newRef, S newService)
* }</pre>
- *
- * The following families of callbacks are supported:
*
- * <ul>
- * <li> "cb(String ... callback)": stands for "callback" and specifies a list of callbacks from the component instances. When using one arg, it stands for the "add" callback.
- * When using two args, it stands for "add/remove" callbacks. When using three args, it stands for "add/change/remove" callbacks. When using four args, it stands for "add/change/remove/swap" callbacks.
- * <li> "cbi(Object callbackInstance, String ... callbacks)": stands for "callback instance" and specifies some callbacks on a given object instance.
- * <li> "cb(lambda) ": stands for "callback" and specifies a method reference of a callback from a given component class.
- * <li> "cbi(lambda)": stands for "callback instance" and specifies a method reference from a given object instance.
- * <li> "sw(lambda)": stands for "swap callback" and specifies a method reference of a swap callback from a given component class.
- * <li> "swi(lambda)": stands for "swap callback instance" and specifies a method reference of a swap callback from a given object instance.
- * </ul>
+ * <b> List of signatures supported using java 8 method references: </b>
*
+ * <pre> {@code
+ * method(S service)
+ * method(S service, ServiceReference<S> serviceRef),
+ * method(S service, Map<String, Object> serviceProperties)
+ * method(S service, Dictionary<String, Object> serviceProperties)
+ * method(S service, Component serviceComponent)
+ * method(S service, Component serviceComponent, ServiceReference<S> serviceRef)
+ * swapMethod(S oldService, S newService)
+ * swapMethod(S oldService, S newService, Component component))
+ * swapMethod(ServiceReference<S> oldRef, S old, ServiceReference<S> newRef, S newService)
+ * swapMethod(ServiceReference<S> oldRef, S old, ServiceReference<S> newRef, S newService, Component component)
+ * }</pre>
+ *
* <p> Here is an example of a Component that defines a dependency of a LogService which is injected in the "bindLogService" method using a ServiceCallbacksBuilder:
- * The withSrv(...)" declaration defines a method reference on the "ComponentImpl::bindLogService" method (using a lambda):
+ * The withSvc(...)" declaration defines a method reference on the "ComponentImpl::bindLogService" method (using a lambda):
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
- * component(comp -> comp.impl(ComponentImpl.class).withSrv(LogService.class, log -> log.cb(ComponentImpl::bindLogService)));
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * component(comp -> comp.impl(ComponentImpl.class).withSvc(LogService.class, log -> log.add(ComponentImpl::bindLogService)));
* }
* }}</pre>
*
@@ -75,9 +76,9 @@
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* ComponentImpl impl = new ComponentImpl();
- * component(comp -> comp.impl(impl).withSrv(LogService.class, log -> log.cbi(impl::bindLogService)));
+ * component(comp -> comp.impl(impl).withSvc(LogService.class, log -> log.add(impl::bindLogService)));
* }
* }}</pre>
*
@@ -85,8 +86,8 @@
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
- * component(comp -> comp.impl(ComponentImpl::class).withSrv(LogService.class, log -> log.cb("bindLogService")));
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+ * component(comp -> comp.impl(ComponentImpl::class).withSvc(LogService.class, log -> log.add("bindLogService")));
* }
* }}</pre>
*
@@ -94,9 +95,9 @@
*
* <pre> {@code
* public class Activator extends DependencyManagerActivator {
- * public void activate() throws Exception {
+ * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
* ComponentImpl impl = new ComponentImpl();
- * component(comp -> comp.impl(impl).withSrv(LogService.class, log -> log.cbi(impl, "bindLogService")));
+ * component(comp -> comp.impl(impl).withSvc(LogService.class, log -> log.callbackInstance(impl).add("bindLogService")));
* }
* }}</pre>
*
@@ -106,12 +107,18 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public interface ServiceCallbacksBuilder<S, B extends ServiceCallbacksBuilder<S, B>> {
+
/**
- * Sets <code>callback</code> methods to invoke on the component instance(s). When a service matches the service
- * filter, then the service is injected using the specified callback methods. When you specify one callback, it stands for the "add" callback.
- * When you specify two callbacks, the first one corresponds to the "add" callback, and the second one to the "remove" callback. When you specify three
- * callbacks, the first one stands for the "add" callback, the second one for the "change" callback, and the third one for the "remove" callback.
- * When you specify four callbacks, it stands for "add"/"change"/"remove"/swap callbacks.
+ * Sets the callback instance used for reflection based callbacks.
+ * @param callbackInstance the object on which reflection based callbacks are invoked on.
+ * @return this builder
+ */
+ B callbackInstance(Object callbackInstance);
+
+ /**
+ * Sets <code>callback</code> methods to invoke when a service is added. When a service matches the service
+ * filter, then the service is injected using the specified callback method. The callback is invoked on the component instances, or on the callback
+ * instance, is specified using the {@link #callbackInstance(Object)} method.
*
* The following method signature are supported:
* <pre>{@code
@@ -124,676 +131,496 @@
* method(Component serviceComponent, ServiceReference<S> serviceRef)
* method(Component serviceComponent, S service)
* method(Component serviceComponent, ServiceReference<S> serviceRef, S service)
+ * }</pre>
+ *
+ * @param callback the add callback
+ * @return this builder
+ * @see #callbackInstance(Object)
+ */
+ B add(String callback);
+
+ /**
+ * Sets <code>callback</code> methods to invoke when a service is changed. When a changed service matches the service
+ * filter, then the service is injected using the specified callback method. The callback is invoked on the component instances, or on the callback
+ * instance, is specified using the {@link #callbackInstance(Object)} method.
+ *
+ * The following method signature are supported:
+ * <pre>{@code
+ * method(S service)
+ * method(S service, Map<String, Object> serviceProperties)
+ * method(S service, Dictionary<String, Object> serviceProperties)
+ * method(ServiceReference<S> serviceRef, S service),
+ * method(ServiceReference<S> serviceRef)
+ * method(Component serviceComponent)
+ * method(Component serviceComponent, ServiceReference<S> serviceRef)
+ * method(Component serviceComponent, S service)
+ * method(Component serviceComponent, ServiceReference<S> serviceRef, S service)
+ * }</pre>
+ *
+ * @param callback the change callback
+ * @return this builder
+ * @see #callbackInstance(Object)
+ */
+ B change(String callback);
+
+ /**
+ * Sets <code>callback</code> methods to invoke when a service is removed. When a removed service matches the service
+ * filter, then the specified callback in invoked with the removed service. The callback is invoked on the component instances, or on the callback
+ * instance, is specified using the {@link #callbackInstance(Object)} method.
+ *
+ * The following method signature are supported:
+ * <pre>{@code
+ * method(S service)
+ * method(S service, Map<String, Object> serviceProperties)
+ * method(S service, Dictionary<String, Object> serviceProperties)
+ * method(ServiceReference<S> serviceRef, S service),
+ * method(ServiceReference<S> serviceRef)
+ * method(Component serviceComponent)
+ * method(Component serviceComponent, ServiceReference<S> serviceRef)
+ * method(Component serviceComponent, S service)
+ * method(Component serviceComponent, ServiceReference<S> serviceRef, S service)
+ * }</pre>
+ *
+ * @param callback the remove callback
+ * @return this builder
+ * @see #callbackInstance(Object)
+ */
+ B remove(String callback);
+
+ /**
+ * Sets <code>callback</code> methods to invoke when a service is swapped. The callback is invoked on the component instances, or on the callback
+ * instance, is specified using the {@link #callbackInstance(Object)} method.
+ *
+ * The following method signature are supported:
+ * <pre>{@code
* swapMethod(S oldService, S newService)
* swapMethod(ServiceReference<S> oldRef, S old, ServiceReference<S> newRef, S newService)
* swapMethod(Component component, S oldService, S newService)
* swapMethod(Component component, ServiceReference<S> oldRef, S old, ServiceReference<S> newRef, S newService)
* }</pre>
*
- * @param callbacks a list of callbacks (1 param: "add", 2 params: "add"/remove", 3 params: "add"/"change"/"remove", 4 params: "add"/"change"/"remove"/"swap" callbacks).
+ * @param callback the remove callback
* @return this builder
+ * @see #callbackInstance(Object)
*/
- B cb(String ... callbacks);
+ B swap(String callback);
/**
- * Sets <code>callback instance</code> methods to invoke on a given Object instance. When a service matches the service
- * filter, then the service is injected using the specified callback methods. When you specify one callback, it stands for the "add" callback.
- * When you specify two callbacks, the first one corresponds to the "add" callback, and the second one to the "remove" callback. When you specify three
- * callbacks, the first one stands for the "add" callback, the second one for the "change" callback, and the third one for the "remove" callback.
- *
- * @param callbackInstance the object on which the callback is invoked.
- * @param callbacks a list of callbacks (1 param : "add", 2 params : "add"/remove", 3 params : "add"/"change"/"remove", 4 params : "add"/"change"/"remove"/"swap" callbacks).
- * @see #cb(String...)
- * @return this builder
- */
- B cbi(Object callbackInstance, String ... callbacks);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service.
+ * Sets a <code>component instance callback(Service)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a service is added.
* @return this builder
*/
- <T> B cb(CbTypeService<T, S> add);
+ <T> B add(CbService<T, S> add);
/**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service.
+ * Sets a <code>component instance callback(Service)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ <T> B change(CbService<T, S> change);
+
+ /**
+ * Sets a <code>component instance callback(Service)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
* @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeService<T, S> add, CbTypeService<T, S> remove);
+ <T> B remove(CbService<T, S> remove);
/**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service.
+ * Sets a {@code component instance callback(Service, Map<String, Object>)} callback. The callback is invoked when a service is added.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ <T> B add(CbServiceMap<T, S> add);
+
+ /**
+ * Sets a {@code component instance callback(Service, Map<String, Object>)} callback. The callback is invoked when a service is changed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
* @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeService<T, S> add, CbTypeService<T, S> change, CbTypeService<T, S> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service, and a properties map.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeServiceMap<T, S> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service, and a properties map.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeServiceMap<T, S> add, CbTypeServiceMap<T, S> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service, and a properties map.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeServiceMap<T, S> add, CbTypeServiceMap<T, S> change, CbTypeServiceMap<T, S> remove);
+ <T> B change(CbServiceMap<T, S> change);
/**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service, and a properties dictionary.
+ * Sets a {@code component instance callback(Service, Map<String, Object></code>)} callback. The callback is invoked when a service is removed.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeServiceDict<T, S> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service, and a properties dictionary.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
* @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeServiceDict<T, S> add, CbTypeServiceDict<T, S> remove);
+ <T> B remove(CbServiceMap<T, S> remove);
/**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service, and a properties dictionary.
+ * Sets a {@code component instance callback(Service, Dictionary<String, Object>)} callback. The callback is invoked when a service is added.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ <T> B add(CbServiceDict<T, S> add);
+
+ /**
+ * Sets a {@code component instance callback(Service, Dictionary<String, Object>)} callback. The callback is invoked when a service is changed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
* @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeServiceDict<T, S> add, CbTypeServiceDict<T, S> change, CbTypeServiceDict<T, S> remove);
+ <T> B change(CbServiceDict<T, S> change);
/**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service reference, and the service.
+ * Sets a {@code component instance callback(Service, Dictionary<String, Object>)} callback. The callback is invoked when a service is removed.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeRefService<T, S> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service reference, and the service.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
* @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeRefService<T, S> add, CbTypeRefService<T, S> remove);
+ <T> B remove(CbServiceDict<T, S> remove);
+
+ /**
+ * Sets a <code>component instance callback(Service, ServiceReference)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a Component implementation class method.
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ <T> B add(CbServiceRef<T, S> add);
+
+ /**
+ * Sets a <code>component instance callback(Service, ServiceReference)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ <T> B change(CbServiceRef<T, S> change);
+
+ /**
+ * Sets a <code>component instance callback(Service, ServiceReference)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ <T> B remove(CbServiceRef<T, S> remove);
+
+ /**
+ * Sets a <code>component instance callback(Service, Component)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ <T> B add(CbServiceComponent<T, S> add);
+
+ /**
+ * Sets a <code>component instance callback(Service, Component)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ <T> B change(CbServiceComponent<T, S> change);
+
+ /**
+ * Sets a <code>component instance callback(Service, Component)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ <T> B remove(CbServiceComponent<T, S> remove);
+
+ /**
+ * Sets a <code>component instance callback(Service, Component, ServiceReference ref)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a Component implementation class method.
+ *
+ * @param <T> the type of the component instance class on which the callback is invoked.
+ * @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ <T> B add(CbServiceComponentRef<T, S> add);
/**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service reference, and the service.
+ * Sets a <code>component instance callback(Service, Component, ServiceReference)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
* @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeRefService<T, S> add, CbTypeRefService<T, S> change, CbTypeRefService<T, S> remove);
+ <T> B change(CbServiceComponentRef<T, S> change);
/**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service reference.
+ * Sets a <code>component instance callback(Service, Component, ServiceReference)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeRef<T, S> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service reference.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
* @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeRef<T, S> add, CbTypeRef<T, S> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the service reference.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeRef<T, S> add, CbTypeRef<T, S> change, CbTypeRef<T, S> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeComponent<T> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeComponent<T> add, CbTypeComponent<T> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeComponent<T> add, CbTypeComponent<T> change, CbTypeComponent<T> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, and the service reference.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeComponentRef<T, S> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, and the service reference.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeComponentRef<T, S> add, CbTypeComponentRef<T, S> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, and the service reference.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeComponentRef<T, S> add, CbTypeComponentRef<T, S> change, CbTypeComponentRef<T, S> remove);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, and the service.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- <T> B cb(CbTypeComponentService<T, S> add);
-
- /**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, and the service.
- *
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- <T> B cb(CbTypeComponentService<T, S> add, CbTypeComponentService<T, S> remove);
+ <T> B remove(CbServiceComponentRef<T, S> remove);
/**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, and the service.
+ * Sets an <code>object instance callback(Service)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a method from an Object instance.
*
- * @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ B add(InstanceCbService<S> add);
+
+ /**
+ * Sets an <code>object instance callback(Service)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to method from an Object instance.
+ *
* @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ B change(InstanceCbService<S> change);
+
+ /**
+ * Sets an <code>object instance callback(Service)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to method from an Object instance.
+ *
* @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeComponentService<T, S> add, CbTypeComponentService<T, S> change, CbTypeComponentService<T, S> remove);
-
+ B remove(InstanceCbService<S> remove);
+
/**
- * Sets a <code>callback</code> invoked when a service is added.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, the service Reference and the service.
+ * Sets an {@code object instance callback(Service, Map<String, Object>)} callback. The callback is invoked when a service is added.
+ * The method reference must point to a method from an Object instance.
*
- * @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a service is added.
* @return this builder
*/
- <T> B cb(CbTypeComponentRefService<T, S> add);
+ B add(InstanceCbServiceMap<S> add);
+
+ /**
+ * Sets an {@code object instance callback(Service, Map<String, Object>)} callback. The callback is invoked when a service is changed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ B change(InstanceCbServiceMap<S> change);
+
+ /**
+ * Sets an {@code object instance callback(Service, Map<String, Object>)} callback. The callback is invoked when a service is removed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ B remove(InstanceCbServiceMap<S> remove);
+
+ /**
+ * Sets an {@code object instance callback(Service svc, Dictionary<String, Object>} callback. The callback is invoked when a service is added.
+ * The method reference must point to a method from an Object instance.
+ *
+ * @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ B add(InstanceCbServiceDict<S> add);
+
+ /**
+ * Sets an {@code object instance callback(Service, Dictionary<String, Object>)} callback. The callback is invoked when a service is changed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ B change(InstanceCbServiceDict<S> change);
+
+ /**
+ * Sets an {@code object instance callback(Service, Dictionary<String, Object>)} callback. The callback is invoked when a service is removed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ B remove(InstanceCbServiceDict<S> remove);
/**
- * Sets a <code>callback</code> invoked when a service is added or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, the service Reference and the service.
+ * Sets an <code>object instance callback(Service, ServiceReference)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a method from an Object instance.
*
- * @param <T> the type of the component instance class on which the callback is invoked.
* @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeComponentRefService<T, S> add, CbTypeComponentRefService<T, S> remove);
-
+ B add(InstanceCbServiceRef<S> add);
+
/**
- * Sets a <code>callback</code> invoked when a service is added, changed, or removed.
- * The method reference must point to a Component implementation class method. Callback argument(s): the Component, the service Reference and the service.
+ * Sets an <code>object instance callback(Service, ServiceReference)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to method from an Object instance.
*
- * @param <T> the type of the component instance class on which the callback is invoked.
- * @param add the method reference invoked when a service is added.
* @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
* @return this builder
*/
- <T> B cb(CbTypeComponentRefService<T, S> add, CbTypeComponentRefService<T, S> change, CbTypeComponentRefService<T, S> remove);
+ B change(InstanceCbServiceRef<S> change);
/**
- * Sets a <code>swap callback(Service, Service)</code> invoked when a service is swapped.
- * The method reference must point to a Component implementation class method. Callback argument(s): the old service and the new replacing service.
+ * Sets an <code>object instance callback(Service, ServiceReference)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ B remove(InstanceCbServiceRef<S> remove);
+
+ /**
+ * Sets an <code>object instance callback(Service, Component)</code> callback invoked. The callback is when a service is added.
+ * The method reference must point to a method from an Object instance.
+ *
+ * @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ B add(InstanceCbServiceComponent<S> add);
+
+ /**
+ * Sets an <code>object instance callback(Service, Component)</code> callback invoked. The callback is when a service is changed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ B change(InstanceCbServiceComponent<S> change);
+
+ /**
+ * Sets an <code>object instance callback(Service, Component)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ B remove(InstanceCbServiceComponent<S> remove);
+
+ /**
+ * Sets an <code>object instance callback(Service, Component, ServiceReference)</code> callback. The callback is invoked when a service is added.
+ * The method reference must point to a method from an Object instance.
+ *
+ * @param add the method reference invoked when a service is added.
+ * @return this builder
+ */
+ B add(InstanceCbServiceComponentRef<S> add);
+
+ /**
+ * Sets an <code>object instance callback(Service, Component, ServiceReference)</code> callback. The callback is invoked when a service is changed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param change the method reference invoked when a service is changed.
+ * @return this builder
+ */
+ B change(InstanceCbServiceComponentRef<S> change);
+
+ /**
+ * Sets an <code>object instance callback(Service, Component, ServiceReference)</code> callback. The callback is invoked when a service is removed.
+ * The method reference must point to method from an Object instance.
+ *
+ * @param remove the method reference invoked when a service is removed.
+ * @return this builder
+ */
+ B remove(InstanceCbServiceComponentRef<S> remove);
+
+ /**
+ * Sets a swap <code>component instance callback(Service, Service)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- <T> B sw(CbTypeServiceService<T, S> swap);
+ <T> B swap(CbServiceService<T, S> swap);
/**
- * Sets a <code>swap callback(Component, Service, Service)</code> invoked when a service is swapped.
- * The method reference must point to a Component implementation class method. Callback argument(s): the component, the old service and the new replacing service.
+ * Sets a wap <code>component instance callback(Service, Service, Component)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a Component implementation class method.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- <T> B sw(CbTypeComponentServiceService<T, S> swap);
+ <T> B swap(CbServiceServiceComponent<T, S> swap);
/**
- * Sets a <code>swap callback(ServiceReference, Service, ServiceReference, Service)</code> invoked when a service is swapped.
- * The method reference must point to a Component implementation class method. Callback argument(s): the old service reference, the old service, the new service reference, and
+ * Sets a swap <code>component instance callback(ServiceReference, Service, ServiceReference, Service)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a Component implementation class method.
* the new service.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- <T> B sw(CbTypeRefServiceRefService<T, S> swap);
+ <T> B swap(CbRefServiceRefService<T, S> swap);
/**
- * Sets a swap <code>callback</code> invoked when a service is swapped.
- * The method reference must point to a Component implementation class method. Callback argument(s): the component, the old service reference, the old service, the new service reference, and
+ * Sets a swap <code>component instance callback(ServiceReference, Service, ServiceReference, Service, Component</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a Component implementation class method.
* the new service.
*
* @param <T> the type of the component instance class on which the callback is invoked.
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- <T> B sw(CbTypeComponentRefServiceRefService<T, S> swap);
+ <T> B swap(CbRefServiceRefServiceComponent<T, S> swap);
/**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a service.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbService<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbService<S> add, CbService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbService<S> add, CbService<S> change, CbService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a service and a properties Map.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbServiceMap<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service and a properties Map.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbServiceMap<S> add, CbServiceMap<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service and a properties Map.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbServiceMap<S> add, CbServiceMap<S> change, CbServiceMap<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a service and a properties Dictionary.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbServiceDict<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service and a properties Dictionary.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbServiceDict<S> add, CbServiceDict<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service and a properties Dictionary.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbServiceDict<S> add, CbServiceDict<S> change, CbServiceDict<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a service reference and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbRefService<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service reference and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbRefService<S> add, CbRefService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service reference and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbRefService<S> add, CbRefService<S> change, CbRefService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a service reference.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbRef<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service reference.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbRef<S> add, CbRef<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a service reference.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbRef<S> add, CbRef<S> change, CbRef<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a Component.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbComponent add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponent add, CbComponent remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponent add, CbComponent change, CbComponent remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a Component and a service reference.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbComponentRef<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component and a service reference.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponentRef<S> add, CbComponentRef<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component and a service reference.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponentRef<S> add, CbComponentRef<S> change, CbComponentRef<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a Component and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbComponentService<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponentService<S> add, CbComponentService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponentService<S> add, CbComponentService<S> change, CbComponentService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added.
- * The method reference must point to a method from an Object instance. Callback argument(s): a Component, a service reference, and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @return this builder
- */
- B cbi(CbComponentRefService<S> add);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component, a service reference, and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponentRefService<S> add, CbComponentRefService<S> remove);
-
- /**
- * Sets a <code>callback instance</code> invoked when a service is added/changed/removed.
- * The method reference must point to method from an Object instance. Callback argument(s): a Component, a service reference, and a service.
- *
- * @param add the method reference invoked when a service is added.
- * @param change the method reference invoked when a service is changed.
- * @param remove the method reference invoked when a service is removed.
- * @return this builder
- */
- B cbi(CbComponentRefService<S> add, CbComponentRefService<S> change, CbComponentRefService<S> remove);
-
- /**
- * Sets a swap <code>callback instance</code> invoked when a service is swapped.
- * The method reference must point to a method from an Object instance. Callback argument(s): the old service, and the new service.
- * the new service.
+ * Sets a swap <code>instance callback(Service, Service)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a method from an Object instance.
*
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- B swi(CbServiceService<S> swap);
+ B swap(InstanceCbServiceService<S> swap);
/**
- * Sets a swap <code>callback instance</code> invoked when a service is swapped.
- * The method reference must point to a method from an Object instance. Callback argument(s): the component, the old service, and the new service.
- * the new service.
+ * Sets a swap <code>instance callback(Service, Service, Component)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a method from an Object instance.
*
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- B swi(CbComponentServiceService<S> swap);
+ B swap(InstanceCbServiceServiceComponent<S> swap);
/**
- * Sets a swap <code>callback instance</code> invoked when a service is swapped.
- * The method reference must point to a method from an Object instance. Callback argument(s): the old service reference, the old service, the
- * new service reference, and the new service.
+ * Sets a swap <code>instance callback(ServiceReference, Service, ServiceReference, Service)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a method from an Object instance.
*
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- B swi(CbRefServiceRefService<S> swap);
+ B swap(InstanceCbRefServiceRefService<S> swap);
/**
- * Sets a swap <code>callback instance</code> invoked when a service is swapped.
- * The method reference must point to a method from an Object instance. Callback argument(s): the component, old service reference, the old service, the
- * new service reference, and the new service.
+ * Sets a swap <code>instance callback(ServiceReference, Service, ServiceReference, Service, Component)</code> method reference. The callback is invoked when a service is swapped.
+ * The method reference must point to a method from an Object instance.
*
* @param swap the method reference invoked when the service is swapped.
* @return this builder
*/
- B swi(CbComponentRefServiceRefService<S> swap);
+ B swap(InstanceCbRefServiceRefServiceComponent<S> swap);
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceDependencyBuilder.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceDependencyBuilder.java
index e2e4370..8ad3707 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceDependencyBuilder.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceDependencyBuilder.java
@@ -8,8 +8,10 @@
import org.osgi.framework.ServiceReference;
/**
- * Builds a Dependency Manager Service Dependency. Dependency callbacks can be defined using methods reflection like
- * in original DM API, or using Java8 method references.
+ * Builds a Dependency Manager Service Dependency.
+ * The Dependency is required by default, but you can
+ * control the default mode (required or optional) using the "org.apache.felix.dependencymanager.lambda.dependencymode"
+ * system property which can be set to either "required" or "optional" ("required" by default).
*
* Unlike with original DM, dependencies are required by default.
*
@@ -31,19 +33,22 @@
ServiceDependencyBuilder<S> ref(ServiceReference<S> ref);
/**
- * Configures this dependency as optional. By default, a dependency is required.
+ * Configures this dependency as optional. By default, the dependency is required, but you can specify the default mode
+ * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
* @return this builder
*/
ServiceDependencyBuilder<S> optional();
/**
- * Configures this dependency as required. By default, a dependency is required.
+ * Configures this dependency as required. By default, the dependency is required, but you can specify the default mode
+ * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
* @return this builder
*/
ServiceDependencyBuilder<S> required();
/**
- * Configures whether this dependency is required or not.
+ * Configures whether this dependency is required or not. By default, the dependency is required, but you can specify the default mode
+ * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
*
* @param required true if the dependency is required, false if not. Unlike with the original DM API, service dependencies are required by default.
* @return this builder
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/Cb.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/Cb.java
new file mode 100644
index 0000000..3e44ac6
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/Cb.java
@@ -0,0 +1,25 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+/**
+ * Represents a java8 method reference to a zero-argument method from a given component implementation class.
+ * <p> The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface Cb<T> extends SerializableLambda {
+ /**
+ * Invokes the callback method on the given component implementation instance.
+ * @param t the component implementation instance the callback is invoked on.
+ */
+ void accept(T t);
+
+ default Cb<T> andThen(Cb<? super T> after) {
+ Objects.requireNonNull(after);
+ return (T t) -> {
+ accept(t);
+ after.accept(t);
+ };
+ }
+}
\ No newline at end of file
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundle.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundle.java
index 32d24b4..268c308 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundle.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundle.java
@@ -5,23 +5,25 @@
import org.osgi.framework.Bundle;
/**
- * Represents a callback(Bundle) on an Object instance.
+ * Represents a callback(Bundle) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbBundle extends SerializableLambda {
+public interface CbBundle<T> extends SerializableLambda {
/**
- * Handles the given argument.
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
* @param bundle the callback parameter
*/
- void accept(Bundle bundle);
+ void accept(T instance, Bundle bundle);
- default CbBundle andThen(CbBundle after) {
+ default CbBundle<T> andThen(CbBundle<? super T> after) {
Objects.requireNonNull(after);
- return (Bundle bundle) -> {
- accept(bundle);
- after.accept(bundle);
+ return (T instance, Bundle bundle) -> {
+ accept(instance, bundle);
+ after.accept(instance, bundle);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundleComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundleComponent.java
new file mode 100644
index 0000000..58befd1
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbBundleComponent.java
@@ -0,0 +1,31 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.Bundle;
+
+/**
+ * Represents a callback(Bundle, Component) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbBundleComponent<T> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param bundle the first callback parameter
+ * @param component the second callback parameter
+ */
+ void accept(T instance, Bundle bundle, Component component);
+
+ default CbBundleComponent<T> andThen(CbBundleComponent<? super T> after) {
+ Objects.requireNonNull(after);
+ return (T instance, Bundle bundle, Component component) -> {
+ accept(instance, bundle, component);
+ after.accept(instance, bundle, component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponent.java
index e5fbf41..15bde58 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponent.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponent.java
@@ -5,23 +5,26 @@
import org.apache.felix.dm.Component;
/**
- * Represents a callback(Component) on an Object instance.
+ * Represents a callback(Component) that is invoked on a Component implementation class.
+ * The type of the component implementation class on which the callback is invoked on is represented by the T generic parameter.
+ * The component callback accepts in argument a Component parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbComponent {
+public interface CbComponent<T> extends SerializableLambda {
/**
- * Handles the given argument.
+ * Handles the given arguments.
+ * @param instance the Component implementation class instance on which the callback is invoked on.
* @param component the callback parameter
*/
- void accept(Component component);
+ void accept(T instance, Component bundle);
- default CbComponent andThen(CbComponent after) {
+ default CbComponent<T> andThen(CbComponent<? super T> after) {
Objects.requireNonNull(after);
- return (Component component) -> {
- accept(component);
- after.accept(component);
+ return (T instance, Component component) -> {
+ accept(instance, component);
+ after.accept(instance, component);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentBundle.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentBundle.java
deleted file mode 100644
index 5049a25..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentBundle.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.Bundle;
-
-/**
- * Represents a callback(Component, Bundle) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentBundle {
- /**
- * Handles the given arguments.
- * @param component the callback parameter
- * @param bundle the callback parameter
- */
- void accept(Component component, Bundle bundle);
-
- default CbComponentBundle andThen(CbComponentBundle after) {
- Objects.requireNonNull(after);
- return (Component component, Bundle bundle) -> {
- accept(component, bundle);
- after.accept(component, bundle);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentDictionary.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentDictionary.java
deleted file mode 100644
index 1c0f525..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentDictionary.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Dictionary;
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, Dictionary) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentDictionary {
- /**
- * Handles the given arguments.
- * @param component a Component
- * @param properties some service properties
- */
- void accept(Component component, Dictionary<String, Object> properties);
-
- default CbComponentDictionary andThen(CbComponentDictionary after) {
- Objects.requireNonNull(after);
- return (Component component, Dictionary<String, Object> properties) -> {
- accept(component, properties);
- after.accept(component, properties);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRef.java
deleted file mode 100644
index 956293d..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRef.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(Component, ServiceReference) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentRef<S> {
- /**
- * Handles the given arguments.
- * @param c a Component
- * @param ref the service reference
- */
- void accept(Component c, ServiceReference<S> ref);
-
- default CbComponentRef<S> andThen(CbComponentRef<S> after) {
- Objects.requireNonNull(after);
- return (Component c, ServiceReference<S> ref) -> {
- accept(c, ref);
- after.accept(c, ref);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRefService.java
deleted file mode 100644
index adf982d..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRefService.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(Component, ServiceReference, Service) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentRefService<S> {
- /**
- * Handles the given arguments.
- * @param c a Component
- * @param ref the service reference
- * @param service the service
- */
- void accept(Component c, ServiceReference<S> ref, S service);
-
- default CbComponentRefService<S> andThen(CbComponentRefService<S> after) {
- Objects.requireNonNull(after);
- return (Component c, ServiceReference<S> ref, S service) -> {
- accept(c, ref, service);
- after.accept(c, ref, service);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRefServiceRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRefServiceRefService.java
deleted file mode 100644
index 6ea5e2a..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentRefServiceRefService.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(Component, ServiceReference, Service, ServiceReference, Service) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentRefServiceRefService<S> {
- /**
- * Handles the given arguments
- * @param c a Component
- * @param oldRef an old swapped service reference
- * @param old an old swapped service
- * @param replaceRef the new service reference
- * @param replace the new service
- */
- void accept(Component c, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace);
-
- default CbComponentRefServiceRefService<S> andThen(CbComponentRefServiceRefService<S> after) {
- Objects.requireNonNull(after);
- return (Component c, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> {
- accept(c, oldRef, old, replaceRef, replace);
- after.accept(c, oldRef, old, replaceRef, replace);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentService.java
deleted file mode 100644
index 7ddbe53..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentService.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, Service) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentService<S> {
- /**
- * Handles the given arguments
- * @param c the component
- * @param service the service
- */
- void accept(Component c, S service);
-
- default CbComponentService<S> andThen(CbComponentService<S> after) {
- Objects.requireNonNull(after);
- return (Component c, S service) -> {
- accept(c, service);
- after.accept(c, service);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentServiceService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentServiceService.java
deleted file mode 100644
index cf8190a..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbComponentServiceService.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, Service, Service) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbComponentServiceService<S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param c the component
- * @param old the old service
- * @param replace the new service
- */
- void accept(Component c, S old, S replace);
-
- default CbComponentServiceService<S> andThen(CbComponentServiceService<S> after) {
- Objects.requireNonNull(after);
- return (Component c, S old, S replace) -> {
- accept(c, old, replace);
- after.accept(c, old, replace);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConfiguration.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConfiguration.java
new file mode 100644
index 0000000..9f8a2e8
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConfiguration.java
@@ -0,0 +1,83 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Represents a callback(Configuration) that is invoked on a Component implementation class.
+ * The callback which accepts a type-safe configuration class for wrapping properties behind a dynamic proxy interface.
+ *
+ * <p> The T generic parameter represents the type of the class on which the callback is invoked on.
+ * <p> The U generic parameter represents the type of the configuration class passed to the callback argument.
+ *
+ * <p> Using such callback provides a way for creating type-safe configurations from a actual {@link Map} or {@link Dictionary} that is
+ * normally injected by Dependency Manager.
+ * The callback accepts in argument an interface that you have to provide, and DM will inject a proxy that converts
+ * method calls from your configuration-type to lookups in the actual map or dictionary. The results of these lookups are then
+ * converted to the expected return type of the invoked configuration method.<br>
+ * As proxies are injected, no implementations of the desired configuration-type are necessary!
+ * </p>
+ * <p>
+ * The lookups performed are based on the name of the method called on the configuration type. The method names are
+ * "mangled" to the following form: <tt>[lower case letter] [any valid character]*</tt>. Method names starting with
+ * <tt>get</tt> or <tt>is</tt> (JavaBean convention) are stripped from these prefixes. For example: given a dictionary
+ * with the key <tt>"foo"</tt> can be accessed from a configuration-type using the following method names:
+ * <tt>foo()</tt>, <tt>getFoo()</tt> and <tt>isFoo()</tt>.
+ * </p>
+ * <p>
+ * The return values supported are: primitive types (or their object wrappers), strings, enums, arrays of
+ * primitives/strings, {@link Collection} types, {@link Map} types, {@link Class}es and interfaces. When an interface is
+ * returned, it is treated equally to a configuration type, that is, it is returned as a proxy.
+ * </p>
+ * <p>
+ * Arrays can be represented either as comma-separated values, optionally enclosed in square brackets. For example:
+ * <tt>[ a, b, c ]</tt> and <tt>a, b,c</tt> are both considered an array of length 3 with the values "a", "b" and "c".
+ * Alternatively, you can append the array index to the key in the dictionary to obtain the same: a dictionary with
+ * "arr.0" => "a", "arr.1" => "b", "arr.2" => "c" would result in the same array as the earlier examples.
+ * </p>
+ * <p>
+ * Maps can be represented as single string values similarly as arrays, each value consisting of both the key and value
+ * separated by a dot. Optionally, the value can be enclosed in curly brackets. Similar to array, you can use the same
+ * dot notation using the keys. For example, a dictionary with
+ *
+ * <pre>{@code "map" => "{key1.value1, key2.value2}"}</pre>
+ *
+ * and a dictionary with <p>
+ *
+ * <pre>{@code "map.key1" => "value1", "map2.key2" => "value2"}</pre>
+ *
+ * result in the same map being returned.
+ * Instead of a map, you could also define an interface with the methods <tt>getKey1()</tt> and <tt>getKey2</tt> and use
+ * that interface as return type instead of a {@link Map}.
+ *
+ * <p>
+ * In case a lookup does not yield a value from the underlying map or dictionary, the following rules are applied:
+ * <ol>
+ * <li>primitive types yield their default value, as defined by the Java Specification;
+ * <li>string, {@link Class}es and enum values yield <code>null</code>;
+ * <li>for arrays, collections and maps, an empty array/collection/map is returned;
+ * <li>for other interface types that are treated as configuration type a null-object is returned.
+ * </ol>
+ * </p>
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbConfiguration<T, U> extends SerializableLambda {
+ /**
+ * Handles the given arguments
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param configuration the configuration proxy
+ */
+ void accept(T instance, U configuration);
+
+ default CbConfiguration<T, U> andThen(CbConfiguration<T, U> after) {
+ Objects.requireNonNull(after);
+ return (T instance, U configuration) -> {
+ accept(instance, configuration);
+ after.accept(instance, configuration);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConfigurationComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConfigurationComponent.java
new file mode 100644
index 0000000..1e34dc0
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConfigurationComponent.java
@@ -0,0 +1,33 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Configuration, Component) which accepts a configuration type for wrapping properties
+ * behind a dynamic proxy interface. For more informations about configuration type, please refer to {@link CbConfiguration}.
+ *
+ * <p> The T generic parameter represents the type of the class on which the callback is invoked on.
+ * <p> The U generic parameter represents the type of the configuration class passed to the callback argument.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbConfigurationComponent<T, U> extends SerializableLambda {
+ /**
+ * Handles the given arguments
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param configuration the configuration proxy
+ * @param component the callback Component
+ */
+ void accept(T instance, U configuration, Component component);
+
+ default CbConfigurationComponent<T, U> andThen(CbConfigurationComponent<T, U> after) {
+ Objects.requireNonNull(after);
+ return (T instance, U configuration, Component component) -> {
+ accept(instance, configuration, component);
+ after.accept(instance, configuration, component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConsumer.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConsumer.java
deleted file mode 100644
index 403ec7a..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbConsumer.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-/**
- * Represents a callback(T param) on an Object instance.
- *
- * @param T the type of the callback parameter.
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbConsumer<T> extends SerializableLambda {
- /**
- * Handles the given argument
- * @param t the argument
- */
- void accept(T t);
-
- default CbConsumer<T> andThen(CbConsumer<? super T> after) {
- Objects.requireNonNull(after);
- return (T t) -> {
- accept(t);
- after.accept(t);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionary.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionary.java
index dda1178..bc69d01 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionary.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionary.java
@@ -4,23 +4,25 @@
import java.util.Objects;
/**
- * Represents a callback(Dictionary) on an Object instance.
+ * Represents a callback(Dictionary) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbDictionary {
+public interface CbDictionary<T> extends SerializableLambda {
/**
- * Handles the given argument.
- * @param conf the properties
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param conf the callback argument
*/
- void accept(Dictionary<String, Object> conf);
+ void accept(T instance, Dictionary<String, Object> conf);
- default CbDictionary andThen(CbDictionary after) {
+ default CbDictionary<T> andThen(CbDictionary<? super T> after) {
Objects.requireNonNull(after);
- return (Dictionary<String, Object> conf) -> {
- accept(conf);
- after.accept(conf);
+ return (T instance, Dictionary<String, Object> conf) -> {
+ accept(instance, conf);
+ after.accept(instance, conf);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionaryComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionaryComponent.java
new file mode 100644
index 0000000..daee390
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbDictionaryComponent.java
@@ -0,0 +1,31 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Dictionary;
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Dictionary, Component) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbDictionaryComponent<T> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param conf the first callback parameter
+ * @param component the second callback parameter
+ */
+ void accept(T instance, Dictionary<String, Object> conf, Component component);
+
+ default CbDictionaryComponent<T> andThen(CbDictionaryComponent<? super T> after) {
+ Objects.requireNonNull(after);
+ return (T instance, Dictionary<String, Object> conf, Component component) -> {
+ accept(instance, conf, component);
+ after.accept(instance, conf, component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbFuture.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbFuture.java
index bab63af..669d01b 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbFuture.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbFuture.java
@@ -3,23 +3,26 @@
import java.util.Objects;
/**
- * Represents a callback that accepts a the result of a CompletableFuture. The callback is invoked on an Object instance.
+ * Represents a callback that accepts the result of a CompletableFuture operation. The callback is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ * The type of the result of the CompletableFuture is represented by the F generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbFuture<F> {
+public interface CbFuture<T, F> extends SerializableLambda {
/**
- * Handles the result of a CompletableFuture operation.
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
* @param future the result of a CompletableFuture operation.
*/
- void accept(F future);
+ void accept(T instance, F future);
- default CbFuture<F> andThen(CbFuture<? super F> after) {
+ default CbFuture<T, F> andThen(CbFuture<? super T, F> after) {
Objects.requireNonNull(after);
- return (F f) -> {
- accept(f);
- after.accept(f);
+ return (T instance, F future) -> {
+ accept(instance, future);
+ after.accept(instance, future);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRef.java
deleted file mode 100644
index 6e5425c..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRef.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(ServiceReference) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbRef<S> {
- /**
- * Handles the given argument
- * @param ref a service reference
- */
- void accept(ServiceReference<S> ref);
-
- default CbRef<S> andThen(CbRef<S> after) {
- Objects.requireNonNull(after);
- return (ServiceReference<S> ref) -> {
- after.accept(ref);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefService.java
deleted file mode 100644
index ca795f4..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefService.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(ServiceReference, Service) on an Object instance.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbRefService<S> {
- /**
- * Handles the given arguments.
- * @param ref a Service Reference
- * @param service a Service
- */
- void accept(ServiceReference<S> ref, S service);
-
- default CbRefService<S> andThen(CbRefService<S> after) {
- Objects.requireNonNull(after);
- return (ServiceReference<S> ref, S service) -> {
- accept(ref, service);
- after.accept(ref, service);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefService.java
index 7917ea3..dc05c83 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefService.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefService.java
@@ -5,26 +5,28 @@
import org.osgi.framework.ServiceReference;
/**
- * Represents a callback(ServiceReference, Service, ServiceReference, Service) on an Object instance.
+ * Represents a callback(ServiceReference, Service, ServiceReference, Service) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbRefServiceRefService<S> {
+public interface CbRefServiceRefService<T, S> extends SerializableLambda {
/**
- * Handles the given arguments
- * @param oldRef a service reference
- * @param old a service
- * @param replaceRef a service reference
- * @param replace a service
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param oldRef first callback param
+ * @param old second callback param
+ * @param replaceRef third callback param
+ * @param replace fourth callback param
*/
- void accept(ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace);
+ void accept(T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace);
- default CbRefServiceRefService<S> andThen(CbRefServiceRefService<S> after) {
+ default CbRefServiceRefService<T, S> andThen(CbRefServiceRefService<? super T, S> after) {
Objects.requireNonNull(after);
- return (ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> {
- accept(oldRef, old, replaceRef, replace);
- after.accept(oldRef, old, replaceRef, replace);
+ return (T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> {
+ accept(instance, oldRef, old, replaceRef, replace);
+ after.accept(instance, oldRef, old, replaceRef, replace);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefServiceComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefServiceComponent.java
new file mode 100644
index 0000000..63c64ca
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbRefServiceRefServiceComponent.java
@@ -0,0 +1,34 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a callback(ServiceReference, Service, ServiceReference, Service, Component) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbRefServiceRefServiceComponent<T, S> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param oldRef first callback arg
+ * @param old second callback arg
+ * @param replaceRef third callback arg
+ * @param replace fourth callback arg
+ * @param c fifth callback arg
+ */
+ void accept(T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace, Component c);
+
+ default CbRefServiceRefServiceComponent<T, S> andThen(CbRefServiceRefServiceComponent<? super T, S> after) {
+ Objects.requireNonNull(after);
+ return (T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace, Component c) -> {
+ accept(instance, oldRef, old, replaceRef, replace, c);
+ after.accept(instance, oldRef, old, replaceRef, replace, c);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbService.java
index 98ca2ab..89aba90 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbService.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbService.java
@@ -3,23 +3,25 @@
import java.util.Objects;
/**
- * Represents a callback(Service) on an Object instance.
+ * Represents a callback(Service) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbService<S> {
+public interface CbService<T, S> extends SerializableLambda {
/**
- * Handles the given argument.
- * @param service a Service
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param service the callback argument.
*/
- void accept(S service);
+ void accept(T instance, S service);
- default CbService<S> andThen(CbService<S> after) {
+ default CbFuture<T, S> andThen(CbFuture<? super T, S> after) {
Objects.requireNonNull(after);
- return (S service) -> {
- accept(service);
- after.accept(service);
+ return (T instance, S service) -> {
+ accept(instance, service);
+ after.accept(instance, service);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceComponent.java
new file mode 100644
index 0000000..4cd2506
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceComponent.java
@@ -0,0 +1,30 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Service, Component) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbServiceComponent<T, S> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param service the first callback argument
+ * @param c the second callback argument
+ */
+ void accept(T instance, S service, Component c);
+
+ default CbServiceComponent<T, S> andThen(CbServiceComponent<T, S> after) {
+ Objects.requireNonNull(after);
+ return (T instance, S s, Component c) -> {
+ accept(instance, s, c);
+ after.accept(instance, s, c);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceComponentRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceComponentRef.java
new file mode 100644
index 0000000..959ba11
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceComponentRef.java
@@ -0,0 +1,32 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a callback(Service, Component, ServiceReference) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbServiceComponentRef<T, S> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param service the first callback parameter
+ * @param c the second callback parameter
+ * @param ref the third callback parameter
+ */
+ void accept(T instance, S service, Component c, ServiceReference<S> ref);
+
+ default CbServiceComponentRef<T, S> andThen(CbServiceComponentRef<T, S> after) {
+ Objects.requireNonNull(after);
+ return (T instance, S service, Component c, ServiceReference<S> ref) -> {
+ accept(instance, service, c, ref);
+ after.accept(instance, service, c, ref);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceDict.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceDict.java
index 0d88a18..046baf6 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceDict.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceDict.java
@@ -4,24 +4,26 @@
import java.util.Objects;
/**
- * Represents a callback(Service, Dictionary) on an Object instance.
+ * Represents a callback(Service, Dictionary) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbServiceDict<S> {
+public interface CbServiceDict<T, S> extends SerializableLambda {
/**
* Handles the given arguments.
- * @param service a Service
- * @param properties a Dictionary
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param service first callback arg
+ * @param properties second callback arg
*/
- void accept(S service, Dictionary<String, Object> properties);
+ void accept(T instance, S service, Dictionary<String, Object> properties);
- default CbServiceDict<S> andThen(CbServiceDict<S> after) {
+ default CbServiceDict<T, S> andThen(CbServiceDict<? super T, S> after) {
Objects.requireNonNull(after);
- return (S service, Dictionary<String, Object> properties) -> {
- accept(service, properties);
- after.accept(service, properties);
+ return (T instance, S service, Dictionary<String, Object> properties) -> {
+ accept(instance, service, properties);
+ after.accept(instance, service, properties);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceMap.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceMap.java
index ae1d6c0..fcf737c 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceMap.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceMap.java
@@ -4,24 +4,26 @@
import java.util.Objects;
/**
- * Represents a callback(Service, Map) on an Object instance.
+ * Represents a callback(Service, Map) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbServiceMap<S> {
+public interface CbServiceMap<T, S> extends SerializableLambda {
/**
* Handles the given arguments.
- * @param service a Service
- * @param properties a Map
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param service first callback arg
+ * @param properties second callback arg
*/
- void accept(S service, Map<String, Object> properties);
+ void accept(T instance, S service, Map<String, Object> properties);
- default CbServiceMap<S> andThen(CbServiceMap<S> after) {
+ default CbServiceMap<T, S> andThen(CbServiceMap<? super T, S> after) {
Objects.requireNonNull(after);
- return (S service, Map<String, Object> properties) -> {
- accept(service, properties);
- after.accept(service, properties);
+ return (T instance, S service, Map<String, Object> properties) -> {
+ accept(instance, service, properties);
+ after.accept(instance, service, properties);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceRef.java
new file mode 100644
index 0000000..5282f27
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceRef.java
@@ -0,0 +1,30 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a callback(Service, ServiceReference) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbServiceRef<T, S> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param service first callback arg
+ * @param ref second callback arg
+ */
+ void accept(T instance, S service, ServiceReference<S> ref);
+
+ default CbServiceRef<T, S> andThen(CbServiceRef<? super T, S> after) {
+ Objects.requireNonNull(after);
+ return (T instance, S service, ServiceReference<S> ref) -> {
+ accept(instance, service, ref);
+ after.accept(instance, service, ref);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceService.java
index 02c4d94..91d2ab0 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceService.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceService.java
@@ -3,24 +3,26 @@
import java.util.Objects;
/**
- * Represents a callback(Service, Service) on an Object instance.
+ * Represents a swap callback(Service, Service) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@FunctionalInterface
-public interface CbServiceService<S> extends SerializableLambda {
+public interface CbServiceService<T, S> extends SerializableLambda {
/**
- * Handles the given argument
- * @param old a Service
- * @param replace a Service
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param old first callback arg
+ * @param replace second callback arg
*/
- void accept(S old, S replace);
+ void accept(T instance, S old, S replace);
- default CbServiceService<S> andThen(CbServiceService<S> after) {
+ default CbServiceService<T, S> andThen(CbServiceService<? super T, S> after) {
Objects.requireNonNull(after);
- return (S old, S replace) -> {
- accept(old, replace);
- after.accept(old, replace);
+ return (T instance, S old, S replace) -> {
+ accept(instance, old, replace);
+ after.accept(instance, old, replace);
};
}
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceServiceComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceServiceComponent.java
new file mode 100644
index 0000000..a31fd09
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbServiceServiceComponent.java
@@ -0,0 +1,31 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a swap callback(Service, Service, Component) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface CbServiceServiceComponent<T, S> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param old first callback arg
+ * @param replace second callback arg
+ * @param c third callback arg
+ */
+ void accept(T instance, S old, S replace, Component c);
+
+ default CbServiceServiceComponent<T, S> andThen(CbServiceServiceComponent<? super T, S> after) {
+ Objects.requireNonNull(after);
+ return (T instance, S old, S replace, Component c) -> {
+ accept(instance, old, replace, c);
+ after.accept(instance, old, replace, c);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeBundle.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeBundle.java
deleted file mode 100644
index aa6c444..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeBundle.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.osgi.framework.Bundle;
-
-/**
- * Represents a callback(Bundle) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeBundle<T> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param bundle the callback parameter
- */
- void accept(T instance, Bundle bundle);
-
- default CbTypeBundle<T> andThen(CbTypeBundle<? super T> after) {
- Objects.requireNonNull(after);
- return (T instance, Bundle bundle) -> {
- accept(instance, bundle);
- after.accept(instance, bundle);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponent.java
deleted file mode 100644
index 9bed1bd..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponent.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponent<T> extends SerializableLambda {
- /**
- * Handles the given arguments
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param component the callback parameter
- */
- void accept(T instance, Component component);
-
- default CbTypeComponent<T> andThen(CbTypeComponent<T> after) {
- Objects.requireNonNull(after);
- return (T instance, Component component) -> {
- accept(instance, component);
- after.accept(instance, component);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentBundle.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentBundle.java
deleted file mode 100644
index 7bee3c3..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentBundle.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.Bundle;
-
-/**
- * Represents a callback(Component, Bundle) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentBundle<T> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param component the first callback parameter
- * @param bundle the second callback parameter
- */
- void accept(T instance, Component component, Bundle bundle);
-
- default CbTypeComponentBundle<T> andThen(CbTypeComponentBundle<? super T> after) {
- Objects.requireNonNull(after);
- return (T instance, Component component, Bundle bundle) -> {
- accept(instance, component, bundle);
- after.accept(instance, component, bundle);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentDictionary.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentDictionary.java
deleted file mode 100644
index f84c71b..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentDictionary.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Dictionary;
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, Dictionary) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentDictionary<T> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param component the first callback parameter
- * @param conf the second callback parameter
- */
- void accept(T instance, Component component, Dictionary<String, Object> conf);
-
- default CbTypeComponentDictionary<T> andThen(CbTypeComponentDictionary<? super T> after) {
- Objects.requireNonNull(after);
- return (T instance, Component component, Dictionary<String, Object> conf) -> {
- accept(instance, component, conf);
- after.accept(instance, component, conf);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRef.java
deleted file mode 100644
index 19bcb7d..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRef.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(Component, ServiceReference) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentRef<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c the first callback parameter
- * @param ref the second callback parameter
- */
- void accept(T instance, Component c, ServiceReference<S> ref);
-
- default CbTypeComponentRef<T, S> andThen(CbTypeComponentRef<T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, ServiceReference<S> ref) -> {
- accept(instance, c, ref);
- after.accept(instance, c, ref);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRefService.java
deleted file mode 100644
index c11e1a5..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRefService.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(Component, ServiceReference, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentRefService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c the first callback parameter
- * @param ref the second callback parameter
- * @param service the third callback parameter
- */
- void accept(T instance, Component c, ServiceReference<S> ref, S service);
-
- default CbTypeComponentRefService<T, S> andThen(CbTypeComponentRefService<T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, ServiceReference<S> ref, S service) -> {
- accept(instance, c, ref, service);
- after.accept(instance, c, ref, service);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRefServiceRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRefServiceRefService.java
deleted file mode 100644
index 43ac90a..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentRefServiceRefService.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(Component, ServiceReference, Service, ServiceReference, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentRefServiceRefService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c first callback param
- * @param oldRef second callback param
- * @param old third callback param
- * @param replaceRef fourth callback param
- * @param replace fifth callback param
- */
- void accept(T instance, Component c, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace);
-
- default CbTypeComponentRefServiceRefService<T, S> andThen(CbTypeComponentRefServiceRefService<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef,
- S replace) -> {
- accept(instance, c, oldRef, old, replaceRef, replace);
- after.accept(instance, c, oldRef, old, replaceRef, replace);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentService.java
deleted file mode 100644
index 705533d..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentService.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c first callback param
- * @param service second callback param
- */
- void accept(T instance, Component c, S service);
-
- default CbTypeComponentService<T, S> andThen(CbTypeComponentService<T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, S s) -> {
- accept(instance, c, s);
- after.accept(instance, c, s);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceDict.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceDict.java
deleted file mode 100644
index 3fe4403..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceDict.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Dictionary;
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, ServiceReference, Dictionary) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentServiceDict<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c first callback param
- * @param service second callback param
- * @param props third callback param
- */
- void accept(T instance, Component c, S service, Dictionary<String, Object> props);
-
- default CbTypeComponentServiceDict<T, S> andThen(CbTypeComponentServiceDict<T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, S s, Dictionary<String, Object> props) -> {
- accept(instance, c, s, props);
- after.accept(instance, c, s, props);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceMap.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceMap.java
deleted file mode 100644
index 509cdc4..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceMap.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Map;
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, ServiceReference, Service, Service Reference, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentServiceMap<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c first callback param
- * @param service second callback param
- * @param props third callback param
- */
- void accept(T instance, Component c, S service, Map<String, Object> props);
-
- default CbTypeComponentServiceMap<T, S> andThen(CbTypeComponentServiceMap<T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, S s, Map<String, Object> props) -> {
- accept(instance, c, s, props);
- after.accept(instance, c, s, props);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceService.java
deleted file mode 100644
index d234a91..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeComponentServiceService.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.apache.felix.dm.Component;
-
-/**
- * Represents a callback(Component, Service, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeComponentServiceService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param c first callback param
- * @param old second callback param
- * @param replace third callback param
- */
- void accept(T instance, Component c, S old, S replace);
-
- default CbTypeComponentServiceService<T, S> andThen(CbTypeComponentServiceService<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, Component c, S old, S replace) -> {
- accept(instance, c, old, replace);
- after.accept(instance, c, old, replace);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeDictionary.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeDictionary.java
deleted file mode 100644
index 8d4ceb1..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeDictionary.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Dictionary;
-import java.util.Objects;
-
-/**
- * Represents a callback(Dictionary) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeDictionary<T> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param conf first callback param
- */
- void accept(T instance, Dictionary<String, Object> conf);
-
- default CbTypeDictionary<T> andThen(CbTypeDictionary<? super T> after) {
- Objects.requireNonNull(after);
- return (T instance, Dictionary<String, Object> conf) -> {
- accept(instance, conf);
- after.accept(instance, conf);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeFuture.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeFuture.java
deleted file mode 100644
index 54b0d72..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeFuture.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-/**
- * Represents a callback that accepts the result of a CompletableFuture operation. The callback is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- * The type of the result of the CompletableFuture is represented by the F generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeFuture<T, F> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param future the result of a CompletableFuture operation.
- */
- void accept(T instance, F future);
-
- default CbTypeFuture<T, F> andThen(CbTypeFuture<? super T, F> after) {
- Objects.requireNonNull(after);
- return (T instance, F future) -> {
- accept(instance, future);
- after.accept(instance, future);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRef.java
deleted file mode 100644
index 36fa87c..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRef.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(ServiceReference) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeRef<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param service first callback param
- */
- void accept(T instance, ServiceReference<S> service);
-
- default CbTypeRef<T, S> andThen(CbTypeRef<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, ServiceReference<S> ref) -> {
- accept(instance, ref);
- after.accept(instance, ref);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRefService.java
deleted file mode 100644
index 099416d..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRefService.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(ServiceReference, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeRefService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param ref first callback param
- * @param service second callback param
- */
- void accept(T instance, ServiceReference<S> ref, S service);
-
- default CbTypeRefService<T, S> andThen(CbTypeRefService<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, ServiceReference<S> ref, S service) -> {
- accept(instance, ref, service);
- after.accept(instance, ref, service);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRefServiceRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRefServiceRefService.java
deleted file mode 100644
index ccb9142..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeRefServiceRefService.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-import org.osgi.framework.ServiceReference;
-
-/**
- * Represents a callback(ServiceReference, Service, ServiceReference, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeRefServiceRefService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param oldRef first callback param
- * @param old second callback param
- * @param replaceRef third callback param
- * @param replace fourth callback param
- */
- void accept(T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace);
-
- default CbTypeRefServiceRefService<T, S> andThen(CbTypeRefServiceRefService<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> {
- accept(instance, oldRef, old, replaceRef, replace);
- after.accept(instance, oldRef, old, replaceRef, replace);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeService.java
deleted file mode 100644
index 01f518b..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeService.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-/**
- * Represents a callback(Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param service first callback param
- */
- void accept(T instance, S service);
-
- default CbTypeFuture<T, S> andThen(CbTypeFuture<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, S service) -> {
- accept(instance, service);
- after.accept(instance, service);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceDict.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceDict.java
deleted file mode 100644
index 01c8abb..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceDict.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Dictionary;
-import java.util.Objects;
-
-/**
- * Represents a callback(Component, Dictionary) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeServiceDict<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param service first callback param
- * @param properties second callback param
- */
- void accept(T instance, S service, Dictionary<String, Object> properties);
-
- default CbTypeServiceDict<T, S> andThen(CbTypeServiceDict<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, S service, Dictionary<String, Object> properties) -> {
- accept(instance, service, properties);
- after.accept(instance, service, properties);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceMap.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceMap.java
deleted file mode 100644
index bfe875e..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceMap.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Represents a callback(Component, Map) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeServiceMap<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param service first callback param
- * @param properties second callback param
- */
- void accept(T instance, S service, Map<String, Object> properties);
-
- default CbTypeServiceMap<T, S> andThen(CbTypeServiceMap<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, S service, Map<String, Object> properties) -> {
- accept(instance, service, properties);
- after.accept(instance, service, properties);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceService.java
deleted file mode 100644
index a81aa72..0000000
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/CbTypeServiceService.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.felix.dm.lambda.callbacks;
-
-import java.util.Objects;
-
-/**
- * Represents a callback(Service, Service) that is invoked on a Component implementation class.
- * The type of the class on which the callback is invoked on is represented by the T generic parameter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-@FunctionalInterface
-public interface CbTypeServiceService<T, S> extends SerializableLambda {
- /**
- * Handles the given arguments.
- * @param instance the Component implementation instance on which the callback is invoked on.
- * @param old first callback param
- * @param replace second callback param
- */
- void accept(T instance, S old, S replace);
-
- default CbTypeServiceService<T, S> andThen(CbTypeServiceService<? super T, S> after) {
- Objects.requireNonNull(after);
- return (T instance, S old, S replace) -> {
- accept(instance, old, replace);
- after.accept(instance, old, replace);
- };
- }
-}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCb.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCb.java
new file mode 100644
index 0000000..1e1f6f6
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCb.java
@@ -0,0 +1,24 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+/**
+ * Represents a method reference to a no-args callback method from an arbitrary Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCb {
+ /**
+ * Implements the callback method.
+ */
+ void cb();
+
+ default InstanceCb andThen(InstanceCb after) {
+ Objects.requireNonNull(after);
+ return () -> {
+ cb();
+ after.cb();
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbBundle.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbBundle.java
new file mode 100644
index 0000000..400d6a3
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbBundle.java
@@ -0,0 +1,27 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * Represents a callback(Bundle) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbBundle extends SerializableLambda {
+ /**
+ * Handles the given argument.
+ * @param bundle the callback parameter
+ */
+ void accept(Bundle bundle);
+
+ default InstanceCbBundle andThen(InstanceCbBundle after) {
+ Objects.requireNonNull(after);
+ return (Bundle bundle) -> {
+ accept(bundle);
+ after.accept(bundle);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbBundleComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbBundleComponent.java
new file mode 100644
index 0000000..d0ae29b
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbBundleComponent.java
@@ -0,0 +1,29 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.Bundle;
+
+/**
+ * Represents a callback(Bundle, Component) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbBundleComponent {
+ /**
+ * Handles the given arguments.
+ * @param component the callback parameter
+ * @param bundle the callback parameter
+ */
+ void accept(Bundle bundle, Component component);
+
+ default InstanceCbBundleComponent andThen(InstanceCbBundleComponent after) {
+ Objects.requireNonNull(after);
+ return (Bundle bundle, Component component) -> {
+ accept(bundle, component);
+ after.accept(bundle, component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbComponent.java
new file mode 100644
index 0000000..20888fd
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbComponent.java
@@ -0,0 +1,27 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Component) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbComponent {
+ /**
+ * Handles the given argument.
+ * @param component the callback parameter
+ */
+ void accept(Component component);
+
+ default InstanceCbComponent andThen(InstanceCbComponent after) {
+ Objects.requireNonNull(after);
+ return (Component component) -> {
+ accept(component);
+ after.accept(component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbConfiguration.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbConfiguration.java
new file mode 100644
index 0000000..6f60523
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbConfiguration.java
@@ -0,0 +1,28 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+/**
+ * Represents a reference to a callback on an Object instance that takes Configuration type as argument.
+ * For more informations about configuration type, please refer to {@link CbConfiguration}.
+ *
+ * <p> The T generic parameter represents the type of the configuration class passed to the callback argument.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbConfiguration<T> extends SerializableLambda {
+ /**
+ * Handles the given argument.
+ * @param configType the configuration type
+ */
+ void accept(T configType);
+
+ default InstanceCbConfiguration<T> andThen(InstanceCbConfiguration<T> after) {
+ Objects.requireNonNull(after);
+ return (T configProxy) -> {
+ accept(configProxy);
+ after.accept(configProxy);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbConfigurationComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbConfigurationComponent.java
new file mode 100644
index 0000000..1feaea3
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbConfigurationComponent.java
@@ -0,0 +1,32 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Configuration, Component) that is invoked on a Component implementation class.
+ * The type of the class on which the callback is invoked on is represented by the T generic parameter.
+ * For more informations about configuration type, please refer to {@link CbConfiguration}.
+ *
+ * <p> The T generic parameter represents the type of the configuration class passed to the callback argument.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbConfigurationComponent<T> extends SerializableLambda {
+ /**
+ * Handles the given arguments
+ * @param instance the Component implementation instance on which the callback is invoked on.
+ * @param component the callback Component
+ */
+ void accept(T instance, Component component);
+
+ default InstanceCbConfigurationComponent<T> andThen(InstanceCbConfigurationComponent<T> after) {
+ Objects.requireNonNull(after);
+ return (T instance, Component component) -> {
+ accept(instance, component);
+ after.accept(instance, component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbDictionary.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbDictionary.java
new file mode 100644
index 0000000..53f3d02
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbDictionary.java
@@ -0,0 +1,26 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Dictionary;
+import java.util.Objects;
+
+/**
+ * Represents a callback(Dictionary) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbDictionary {
+ /**
+ * Handles the given argument.
+ * @param conf the properties
+ */
+ void accept(Dictionary<String, Object> conf);
+
+ default InstanceCbDictionary andThen(InstanceCbDictionary after) {
+ Objects.requireNonNull(after);
+ return (Dictionary<String, Object> conf) -> {
+ accept(conf);
+ after.accept(conf);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbDictionaryComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbDictionaryComponent.java
new file mode 100644
index 0000000..20f1a0b
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbDictionaryComponent.java
@@ -0,0 +1,29 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Dictionary;
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Dictionary, Component) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbDictionaryComponent {
+ /**
+ * Handles the given arguments.
+ * @param properties some service properties
+ * @param component a Component
+ */
+ void accept(Dictionary<String, Object> properties, Component component);
+
+ default InstanceCbDictionaryComponent andThen(InstanceCbDictionaryComponent after) {
+ Objects.requireNonNull(after);
+ return (Dictionary<String, Object> properties, Component component) -> {
+ accept(properties, component);
+ after.accept(properties, component);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbFuture.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbFuture.java
new file mode 100644
index 0000000..f2b2662
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbFuture.java
@@ -0,0 +1,25 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+/**
+ * Represents a callback that accepts the result of a CompletableFuture. The callback is invoked on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbFuture<F> {
+ /**
+ * Handles the result of a CompletableFuture operation.
+ * @param future the result of a CompletableFuture operation.
+ */
+ void accept(F future);
+
+ default InstanceCbFuture<F> andThen(InstanceCbFuture<? super F> after) {
+ Objects.requireNonNull(after);
+ return (F f) -> {
+ accept(f);
+ after.accept(f);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbRefServiceRefService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbRefServiceRefService.java
new file mode 100644
index 0000000..297e109
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbRefServiceRefService.java
@@ -0,0 +1,30 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a swap callback(ServiceReference, Service, ServiceReference, Service) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbRefServiceRefService<S> {
+ /**
+ * Handles the given arguments
+ * @param oldRef the old service reference
+ * @param old the old service
+ * @param replaceRef the replace service reference
+ * @param replace the replace service
+ */
+ void accept(ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace);
+
+ default InstanceCbRefServiceRefService<S> andThen(InstanceCbRefServiceRefService<S> after) {
+ Objects.requireNonNull(after);
+ return (ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> {
+ accept(oldRef, old, replaceRef, replace);
+ after.accept(oldRef, old, replaceRef, replace);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbRefServiceRefServiceComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbRefServiceRefServiceComponent.java
new file mode 100644
index 0000000..60c5378
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbRefServiceRefServiceComponent.java
@@ -0,0 +1,32 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a swap callback(ServiceReference, Service, ServiceReference, Service, Component) on an Object instance.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbRefServiceRefServiceComponent<S> {
+ /**
+ * Handles the given arguments
+ * @param oldRef an old swapped service reference
+ * @param old an old swapped service
+ * @param replaceRef the new service reference
+ * @param replace the new service
+ * @param c a Component
+ */
+ void accept(ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace, Component c);
+
+ default InstanceCbRefServiceRefServiceComponent<S> andThen(InstanceCbRefServiceRefServiceComponent<S> after) {
+ Objects.requireNonNull(after);
+ return (ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace, Component c) -> {
+ accept(oldRef, old, replaceRef, replace, c);
+ after.accept(oldRef, old, replaceRef, replace, c);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbService.java
new file mode 100644
index 0000000..1755c52
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbService.java
@@ -0,0 +1,27 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+/**
+ * Represents a callback(Service) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbService<S> {
+ /**
+ * Handles the given argument.
+ * @param service a Service
+ */
+ void accept(S service);
+
+ default InstanceCbService<S> andThen(InstanceCbService<S> after) {
+ Objects.requireNonNull(after);
+ return (S service) -> {
+ accept(service);
+ after.accept(service);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceComponent.java
new file mode 100644
index 0000000..cd3eb08
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceComponent.java
@@ -0,0 +1,30 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a callback(Service, Component) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceComponent<S> {
+ /**
+ * Handles the given arguments
+ * @param c the component
+ * @param service the service
+ */
+ void accept(S service, Component c);
+
+ default InstanceCbServiceComponent<S> andThen(InstanceCbServiceComponent<S> after) {
+ Objects.requireNonNull(after);
+ return (S service, Component c) -> {
+ accept(service, c);
+ after.accept(service, c);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceComponentRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceComponentRef.java
new file mode 100644
index 0000000..2d48a98
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceComponentRef.java
@@ -0,0 +1,32 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a callback(Service, Component, ServiceReference) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceComponentRef<S> {
+ /**
+ * Handles the given arguments.
+ * @param c a Component
+ * @param ref the service reference
+ * @param service the service
+ */
+ void accept(S service, Component c, ServiceReference<S> ref);
+
+ default InstanceCbServiceComponentRef<S> andThen(InstanceCbServiceComponentRef<S> after) {
+ Objects.requireNonNull(after);
+ return (S service, Component c, ServiceReference<S> ref) -> {
+ accept(service, c, ref);
+ after.accept(service, c, ref);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceDict.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceDict.java
new file mode 100644
index 0000000..a65422b
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceDict.java
@@ -0,0 +1,29 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Dictionary;
+import java.util.Objects;
+
+/**
+ * Represents a callback(Service, Dictionary) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceDict<S> {
+ /**
+ * Handles the given arguments.
+ * @param service a Service
+ * @param properties a Dictionary
+ */
+ void accept(S service, Dictionary<String, Object> properties);
+
+ default InstanceCbServiceDict<S> andThen(InstanceCbServiceDict<S> after) {
+ Objects.requireNonNull(after);
+ return (S service, Dictionary<String, Object> properties) -> {
+ accept(service, properties);
+ after.accept(service, properties);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceMap.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceMap.java
new file mode 100644
index 0000000..733a15f
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceMap.java
@@ -0,0 +1,29 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Represents a callback(Service, Map) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceMap<S> {
+ /**
+ * Handles the given arguments.
+ * @param service a Service
+ * @param properties a Map
+ */
+ void accept(S service, Map<String, Object> properties);
+
+ default InstanceCbServiceMap<S> andThen(InstanceCbServiceMap<S> after) {
+ Objects.requireNonNull(after);
+ return (S service, Map<String, Object> properties) -> {
+ accept(service, properties);
+ after.accept(service, properties);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceRef.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceRef.java
new file mode 100644
index 0000000..1b22c05
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceRef.java
@@ -0,0 +1,30 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Represents a callback(Service, ServiceReference) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceRef<S> {
+ /**
+ * Handles the given arguments.
+ * @param ref a Service Reference
+ * @param service a Service
+ */
+ void accept(S service, ServiceReference<S> ref);
+
+ default InstanceCbServiceRef<S> andThen(InstanceCbServiceRef<S> after) {
+ Objects.requireNonNull(after);
+ return (S service, ServiceReference<S> ref) -> {
+ accept(service, ref);
+ after.accept(service, ref);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceService.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceService.java
new file mode 100644
index 0000000..1f5077b
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceService.java
@@ -0,0 +1,28 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+/**
+ * Represents a swap callback(Service, Service) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceService<S> extends SerializableLambda {
+ /**
+ * Handles the given argument
+ * @param old a Service
+ * @param replace a Service
+ */
+ void accept(S old, S replace);
+
+ default InstanceCbServiceService<S> andThen(InstanceCbServiceService<S> after) {
+ Objects.requireNonNull(after);
+ return (S old, S replace) -> {
+ accept(old, replace);
+ after.accept(old, replace);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceServiceComponent.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceServiceComponent.java
new file mode 100644
index 0000000..d48a9bb
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/callbacks/InstanceCbServiceServiceComponent.java
@@ -0,0 +1,31 @@
+package org.apache.felix.dm.lambda.callbacks;
+
+import java.util.Objects;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * Represents a swap callback(Service, Service, Component) on an Object instance.
+ *
+ * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@FunctionalInterface
+public interface InstanceCbServiceServiceComponent<S> extends SerializableLambda {
+ /**
+ * Handles the given arguments.
+ * @param c the component
+ * @param old the old service
+ * @param replace the new service
+ */
+ void accept(S old, S replace, Component c);
+
+ default InstanceCbServiceServiceComponent<S> andThen(InstanceCbServiceServiceComponent<S> after) {
+ Objects.requireNonNull(after);
+ return (S old, S replace, Component c) -> {
+ accept(old, replace, c);
+ after.accept(old, replace, c);
+ };
+ }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/AdapterBase.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/AdapterBase.java
index 1fd3038..f8b6fef 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/AdapterBase.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/AdapterBase.java
@@ -12,9 +12,10 @@
import org.apache.felix.dm.lambda.FluentProperty;
import org.apache.felix.dm.lambda.FutureDependencyBuilder;
import org.apache.felix.dm.lambda.ServiceDependencyBuilder;
+import org.apache.felix.dm.lambda.callbacks.Cb;
import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbConsumer;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCb;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
/**
* Methods common to extended components like adapters or aspects.
@@ -156,18 +157,18 @@
return (B) this;
}
- default B withSrv(Class<?> service, String filter) {
- andThenBuild(compBuilder -> compBuilder.withSrv(service, filter));
+ default B withSvc(Class<?> service, String filter) {
+ andThenBuild(compBuilder -> compBuilder.withSvc(service, filter));
return (B) this;
}
- default B withSrv(Class<?> ... services) {
- andThenBuild(compBuilder -> compBuilder.withSrv(services));
+ default B withSvc(Class<?> ... services) {
+ andThenBuild(compBuilder -> compBuilder.withSvc(services));
return (B) this;
}
- default <U> B withSrv(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
- andThenBuild(compBuilder -> compBuilder.withSrv(service, consumer));
+ default <U> B withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
+ andThenBuild(compBuilder -> compBuilder.withSvc(service, consumer));
return (B) this;
}
@@ -186,6 +187,11 @@
return (B) this;
}
+ default B lifecycleCallbackInstance(Object lifecycleCallbackInstance) {
+ andThenBuild(compBuilder -> compBuilder.lifecycleCallbackInstance(lifecycleCallbackInstance));
+ return (B) this;
+ }
+
default B init(String callback) {
andThenBuild(compBuilder -> compBuilder.init(callback));
return (B) this;
@@ -205,103 +211,83 @@
andThenBuild(compBuilder -> compBuilder.destroy(callback));
return (B) this;
}
-
- default B init(Object callbackInstance, String callback) {
- andThenBuild(compBuilder -> compBuilder.init(callbackInstance, callback));
- return (B) this;
- }
-
- default B start(Object callbackInstance, String callback) {
- andThenBuild(compBuilder -> compBuilder.start(callbackInstance, callback));
- return (B) this;
- }
-
- default B stop(Object callbackInstance, String callback) {
- andThenBuild(compBuilder -> compBuilder.stop(callbackInstance, callback));
- return (B) this;
- }
-
- default B destroy(Object callbackInstance, String callback) {
- andThenBuild(compBuilder -> compBuilder.destroy(callbackInstance, callback));
- return (B) this;
- }
-
- default <U> B init(CbConsumer<U> callback) {
+
+ default <U> B init(Cb<U> callback) {
andThenBuild(compBuilder -> compBuilder.init(callback));
return (B) this;
}
- default <U> B start(CbConsumer<U> callback) {
+ default <U> B start(Cb<U> callback) {
andThenBuild(compBuilder -> compBuilder.start(callback));
return (B) this;
}
- default <U> B stop(CbConsumer<U> callback) {
+ default <U> B stop(Cb<U> callback) {
andThenBuild(compBuilder -> compBuilder.stop(callback));
return (B) this;
}
- default <U> B destroy(CbConsumer<U> callback) {
+ default <U> B destroy(Cb<U> callback) {
andThenBuild(compBuilder -> compBuilder.destroy(callback));
return (B) this;
}
- default <U> B init(CbTypeComponent<U> callback) {
+ default <U> B init(CbComponent<U> callback) {
andThenBuild(compBuilder -> compBuilder.init(callback));
return (B) this;
}
- default <U> B start(CbTypeComponent<U> callback) {
+ default <U> B start(CbComponent<U> callback) {
andThenBuild(compBuilder -> compBuilder.start(callback));
return (B) this;
}
- default <U> B stop(CbTypeComponent<U> callback) {
+ default <U> B stop(CbComponent<U> callback) {
andThenBuild(compBuilder -> compBuilder.stop(callback));
return (B) this;
}
- default <U> B destroy(CbTypeComponent<U> callback) {
+ default <U> B destroy(CbComponent<U> callback) {
andThenBuild(compBuilder -> compBuilder.destroy(callback));
return (B) this;
}
- default B initInstance(Runnable callback) {
+ default B initInstance(InstanceCb callback) {
andThenBuild(compBuilder -> compBuilder.initInstance(callback));
return (B) this;
}
- default B startInstance(Runnable callback) {
+ default B startInstance(InstanceCb callback) {
andThenBuild(compBuilder -> compBuilder.startInstance(callback));
return (B) this;
}
- default B stopInstance(Runnable callback) {
+ default B stopInstance(InstanceCb callback) {
andThenBuild(compBuilder -> compBuilder.stopInstance(callback));
return (B) this;
}
- default B destroyInstance(Runnable callback) {
+ default B destroyInstance(InstanceCb callback) {
andThenBuild(compBuilder -> compBuilder.destroyInstance(callback));
return (B) this;
}
- default B initInstance(CbComponent callback) {
+ default B initInstance(InstanceCbComponent callback) {
andThenBuild(compBuilder -> compBuilder.initInstance(callback));
return (B) this;
}
- default B startInstance(CbComponent callback) {
+ default B startInstance(InstanceCbComponent callback) {
andThenBuild(compBuilder -> compBuilder.startInstance(callback));
return (B) this;
}
- default B stopInstance(CbComponent callback) {
+ default B stopInstance(InstanceCbComponent callback) {
andThenBuild(compBuilder -> compBuilder.stopInstance(callback));
return (B) this;
}
- default B destroyInstance(CbComponent callback) {
+ default B destroyInstance(InstanceCbComponent callback) {
andThenBuild(compBuilder -> compBuilder.destroyInstance(callback));
return (B) this;
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleAdapterBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleAdapterBuilderImpl.java
index 8cd257e..bb13512 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleAdapterBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleAdapterBuilderImpl.java
@@ -12,9 +12,9 @@
import org.apache.felix.dm.lambda.BundleAdapterBuilder;
import org.apache.felix.dm.lambda.ComponentBuilder;
import org.apache.felix.dm.lambda.callbacks.CbBundle;
-import org.apache.felix.dm.lambda.callbacks.CbComponentBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentBundle;
+import org.apache.felix.dm.lambda.callbacks.CbBundleComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent;
import org.osgi.framework.Bundle;
public class BundleAdapterBuilderImpl implements AdapterBase<BundleAdapterBuilder>, BundleAdapterBuilder {
@@ -82,45 +82,44 @@
return this;
}
- public BundleAdapterBuilder cb(String ... callbacks) {
- return cbi(null, callbacks);
+ public BundleAdapterBuilder add(String callback) {
+ return callbacks(callback, null, null);
}
- public BundleAdapterBuilder cbi(Object callbackInstance, String ... callbacks) {
- switch (callbacks.length) {
- case 1:
- return cbi(callbackInstance, callbacks[0], null, null);
-
- case 2:
- return cbi(callbackInstance, callbacks[0], null, callbacks[1]);
-
- case 3:
- return cbi(callbackInstance, callbacks[0], callbacks[1], callbacks[2]);
-
- default:
- throw new IllegalArgumentException("wrong number of arguments: " + callbacks.length + ". " +
- "Possible arguments: [add], [add, remove] or [add, change, remove]");
- }
+ public BundleAdapterBuilder change(String callback) {
+ return callbacks(null, callback, null);
}
- private BundleAdapterBuilder cbi(Object callbackInstance, String add, String change, String remove) {
- checkHasNoMethodRefs();
+ public BundleAdapterBuilder remove(String callback) {
+ return callbacks(null, null, callback);
+ }
+
+ public BundleAdapterBuilder callbackInstance(Object callbackInstance) {
m_callbackInstance = callbackInstance;
- m_add = add;
- m_change = change;
- m_remove = remove;
return this;
}
- public <T> BundleAdapterBuilder cb(CbTypeBundle<T> add) {
- return cb(add, (CbTypeBundle<T>) null, (CbTypeBundle<T>) null);
+ private BundleAdapterBuilder callbacks(String add, String change, String remove) {
+ checkHasNoMethodRefs();
+ m_add = add != null ? add : m_add;
+ m_change = change != null ? change : m_change;
+ m_remove = remove != null ? remove : m_remove;
+ return this;
+ }
+
+ public <T> BundleAdapterBuilder add(CbBundle<T> add) {
+ return callbacks(add, (CbBundle<T>) null, (CbBundle<T>) null);
}
- public <T> BundleAdapterBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> remove) {
- return cb(add, null, remove);
+ public <T> BundleAdapterBuilder change(CbBundle<T> change) {
+ return callbacks(null, change, null);
}
- public <T> BundleAdapterBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> change, CbTypeBundle<T> remove) {
+ public <T> BundleAdapterBuilder remove(CbBundle<T> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private <T> BundleAdapterBuilder callbacks(CbBundle<T> add, CbBundle<T> change, CbBundle<T> remove) {
if (add != null) {
Class<T> type = Helpers.getLambdaArgType(add, 0);
setComponentCallbackRef(Cb.ADD, type, (instance, component, bundle) -> { add.accept((T) instance, bundle); });
@@ -136,57 +135,69 @@
return this;
}
- public BundleAdapterBuilder cbi(CbBundle add) {
- return cbi(add, null, null);
- }
-
- public BundleAdapterBuilder cbi(CbBundle add, CbBundle remove) {
- return cbi(add, null, remove);
+ public BundleAdapterBuilder add(InstanceCbBundle add) {
+ return callbacks(add, null, null);
}
- public BundleAdapterBuilder cbi(CbBundle add, CbBundle change, CbBundle remove) {
+ public BundleAdapterBuilder change(InstanceCbBundle change) {
+ return callbacks(null, change, null);
+ }
+
+ public BundleAdapterBuilder remove(InstanceCbBundle remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public BundleAdapterBuilder callbacks(InstanceCbBundle add, InstanceCbBundle change, InstanceCbBundle remove) {
if (add != null) setInstanceCallbackRef(Cb.ADD, (instance, component, bundle) -> { add.accept(bundle); });
if (change != null) setInstanceCallbackRef(Cb.CHG, (instance, component, bundle) -> { change.accept(bundle); });
if (remove != null) setInstanceCallbackRef(Cb.REM, (instance, component, bundle) -> { remove.accept(bundle); });
return this;
}
- public <T> BundleAdapterBuilder cb(CbTypeComponentBundle<T> add) {
- return cb((CbTypeComponentBundle<T>) add, (CbTypeComponentBundle<T>) null, (CbTypeComponentBundle<T>) null);
+ public <T> BundleAdapterBuilder add(CbBundleComponent<T> add) {
+ return callbacks(add, null, null);
}
- public <T> BundleAdapterBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> remove) {
- return cb(add, null, remove);
+ public <T> BundleAdapterBuilder change(CbBundleComponent<T> change) {
+ return callbacks(null, change, null);
}
- public <T> BundleAdapterBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> change, CbTypeComponentBundle<T> remove) {
+ public <T> BundleAdapterBuilder remove(CbBundleComponent<T> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public <T> BundleAdapterBuilder callbacks(CbBundleComponent<T> add, CbBundleComponent<T> change, CbBundleComponent<T> remove) {
if (add != null) {
Class<T> type = Helpers.getLambdaArgType(add, 0);
- return setComponentCallbackRef(Cb.ADD, type, (instance, component, bundle) -> { add.accept((T) instance, component, bundle); });
+ return setComponentCallbackRef(Cb.ADD, type, (instance, component, bundle) -> { add.accept((T) instance, bundle, component); });
}
if (change != null) {
Class<T> type = Helpers.getLambdaArgType(change, 0);
- return setComponentCallbackRef(Cb.CHG, type, (instance, component, bundle) -> { change.accept((T) instance, component, bundle); });
+ return setComponentCallbackRef(Cb.CHG, type, (instance, component, bundle) -> { change.accept((T) instance, bundle, component); });
}
if (remove != null) {
Class<T> type = Helpers.getLambdaArgType(remove, 0);
- return setComponentCallbackRef(Cb.ADD, type, (instance, component, bundle) -> { remove.accept((T) instance, component, bundle); });
+ return setComponentCallbackRef(Cb.ADD, type, (instance, component, bundle) -> { remove.accept((T) instance, bundle, component); });
}
return this;
}
- public BundleAdapterBuilder cbi(CbComponentBundle add) {
- return cbi(add, null, null);
+ public BundleAdapterBuilder add(InstanceCbBundleComponent add) {
+ return callbacks(add, null, null);
}
- public BundleAdapterBuilder cbi(CbComponentBundle add, CbComponentBundle remove) {
- return cbi(add, null, remove);
+ public BundleAdapterBuilder change(InstanceCbBundleComponent change) {
+ return callbacks(null, change, null);
}
-
- public BundleAdapterBuilder cbi(CbComponentBundle add, CbComponentBundle change, CbComponentBundle remove) {
- if (add != null) setInstanceCallbackRef(Cb.ADD, (instance, component, bundle) -> { add.accept(component, bundle); });
- if (change != null) setInstanceCallbackRef(Cb.CHG, (instance, component, bundle) -> { change.accept(component, bundle); });
- if (remove != null) setInstanceCallbackRef(Cb.REM, (instance, component, bundle) -> { remove.accept(component, bundle); });
+
+ public BundleAdapterBuilder remove(InstanceCbBundleComponent remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public BundleAdapterBuilder callbacks(InstanceCbBundleComponent add, InstanceCbBundleComponent change, InstanceCbBundleComponent remove) {
+ if (add != null) setInstanceCallbackRef(Cb.ADD, (instance, component, bundle) -> { add.accept(bundle, component); });
+ if (change != null) setInstanceCallbackRef(Cb.CHG, (instance, component, bundle) -> { change.accept(bundle, component); });
+ if (remove != null) setInstanceCallbackRef(Cb.REM, (instance, component, bundle) -> { remove.accept(bundle, component); });
return this;
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleDependencyBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleDependencyBuilderImpl.java
index fe77432..7cd6717 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleDependencyBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/BundleDependencyBuilderImpl.java
@@ -6,7 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.function.Supplier;
+import java.util.function.Function;
import java.util.stream.Stream;
import org.apache.felix.dm.BundleDependency;
@@ -14,9 +14,9 @@
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.lambda.BundleDependencyBuilder;
import org.apache.felix.dm.lambda.callbacks.CbBundle;
-import org.apache.felix.dm.lambda.callbacks.CbComponentBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeBundle;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentBundle;
+import org.apache.felix.dm.lambda.callbacks.CbBundleComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent;
import org.osgi.framework.Bundle;
@SuppressWarnings("unchecked")
@@ -34,7 +34,7 @@
private boolean m_propagate;
private Object m_propagateInstance;
private String m_propagateMethod;
- private Supplier<Dictionary<?, ?>> m_propagateSupplier;
+ private Function<Bundle, Dictionary<?, ?>> m_propagateCallback;
private final Component m_component;
enum Cb {
@@ -55,13 +55,14 @@
*/
private class Propagate {
@SuppressWarnings("unused")
- Dictionary<?, ?> propagate() {
- return m_propagateSupplier.get();
+ Dictionary<?, ?> propagate(Bundle bundle) {
+ return m_propagateCallback.apply(bundle);
}
}
public BundleDependencyBuilderImpl (Component component) {
m_component = component;
+ m_required = Helpers.isDependencyRequiredByDefault(component);
}
@Override
@@ -121,7 +122,7 @@
@Override
public BundleDependencyBuilder propagate(Object instance, String method) {
- if (m_propagateSupplier != null || m_propagate) throw new IllegalStateException("Propagate callback already set.");
+ if (m_propagateCallback != null || m_propagate) throw new IllegalStateException("Propagate callback already set.");
Objects.nonNull(method);
Objects.nonNull(instance);
m_propagateInstance = instance;
@@ -130,42 +131,38 @@
}
@Override
- public BundleDependencyBuilder propagate(Supplier<Dictionary<?, ?>> instance) {
+ public BundleDependencyBuilder propagate(Function<Bundle, Dictionary<?, ?>> instance) {
if (m_propagateInstance != null || m_propagate) throw new IllegalStateException("Propagate callback already set.");
- m_propagateSupplier = instance;
+ m_propagateCallback = instance;
return this;
}
-
- public BundleDependencyBuilder cb(String ... callbacks) {
- return cb(null, callbacks);
- }
@Override
- public BundleDependencyBuilder cb(Object callbackInstance, String ... callbacks) {
- switch (callbacks.length) {
- case 1:
- cbi(callbackInstance, callbacks[0], null, null);
- break;
-
- case 2:
- cbi(callbackInstance, callbacks[0], null, callbacks[1]);
- break;
-
- case 3:
- cbi(callbackInstance, callbacks[0], callbacks[1], callbacks[2]);
- break;
-
- default:
- throw new IllegalArgumentException("wrong number of arguments: " + callbacks.length + ". " +
- "Possible arguments: [add], [add, remove] or [add, change, remove]");
- }
+ public BundleDependencyBuilder callbackInstance(Object callbackInstance) {
+ m_instance = callbackInstance;
+ return this;
+ }
+ @Override
+ public BundleDependencyBuilder add(String add) {
+ callbacks(add, null, null);
return this;
}
- private BundleDependencyBuilder cbi(Object callbackInstance, String added, String changed, String removed) {
+ @Override
+ public BundleDependencyBuilder change(String change) {
+ callbacks(null, change, null);
+ return this;
+ }
+
+ @Override
+ public BundleDependencyBuilder remove(String remove) {
+ callbacks(null, null, remove);
+ return this;
+ }
+
+ private BundleDependencyBuilder callbacks(String added, String changed, String removed) {
requiresNoMethodRefs();
- m_instance = callbackInstance;
m_added = added != null ? added : m_added;
m_changed = changed != null ? changed : m_changed;
m_removed = removed != null ? removed : m_removed;
@@ -174,17 +171,21 @@
}
@Override
- public <T> BundleDependencyBuilder cb(CbTypeBundle<T> add) {
- return cb(add, null, null);
+ public <T> BundleDependencyBuilder add(CbBundle<T> add) {
+ return callbacks(add, null, null);
}
@Override
- public <T> BundleDependencyBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> remove) {
- return cb(add, null, remove);
+ public <T> BundleDependencyBuilder change(CbBundle<T> change) {
+ return callbacks(null, change, null);
}
@Override
- public <T> BundleDependencyBuilder cb(CbTypeBundle<T> add, CbTypeBundle<T> change, CbTypeBundle<T> remove) {
+ public <T> BundleDependencyBuilder remove(CbBundle<T> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private <T> BundleDependencyBuilder callbacks(CbBundle<T> add, CbBundle<T> change, CbBundle<T> remove) {
if (add != null) {
setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, component, bundle) -> add.accept ((T) inst, bundle));
}
@@ -198,41 +199,49 @@
}
@Override
- public <T> BundleDependencyBuilder cb(CbTypeComponentBundle<T> add) {
- return cb(add, null, null);
+ public <T> BundleDependencyBuilder add(CbBundleComponent<T> add) {
+ return callbacks(add, null, null);
}
@Override
- public <T> BundleDependencyBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> remove) {
- return cb(add, null, remove);
+ public <T> BundleDependencyBuilder change(CbBundleComponent<T> change) {
+ return callbacks(null, change, null);
}
@Override
- public <T> BundleDependencyBuilder cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T> change, CbTypeComponentBundle<T> remove) {
+ public <T> BundleDependencyBuilder remove(CbBundleComponent<T> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private <T> BundleDependencyBuilder callbacks(CbBundleComponent<T> add, CbBundleComponent<T> change, CbBundleComponent<T> remove) {
if (add != null) {
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, component, bundle) -> add.accept ((T) inst, component, bundle));
+ setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, component, bundle) -> add.accept ((T) inst, bundle, component));
}
if (change != null) {
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, component, bundle) -> change.accept ((T) inst, component, bundle));
+ setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, component, bundle) -> change.accept ((T) inst, bundle, component));
}
if (remove != null) {
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, component, bundle) -> remove.accept ((T) inst, component, bundle));
+ setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, component, bundle) -> remove.accept ((T) inst, bundle, component));
}
return this;
}
@Override
- public BundleDependencyBuilder cbi(CbBundle add) {
- return cbi(add, null, null);
+ public BundleDependencyBuilder add(InstanceCbBundle add) {
+ return callbacks(add, null, null);
}
@Override
- public BundleDependencyBuilder cbi(CbBundle add, CbBundle remove) {
- return cbi(add, null, remove);
+ public BundleDependencyBuilder change(InstanceCbBundle change) {
+ return callbacks(null, change, null);
}
@Override
- public BundleDependencyBuilder cbi(CbBundle add, CbBundle change, CbBundle remove) {
+ public BundleDependencyBuilder remove(InstanceCbBundle remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private BundleDependencyBuilder callbacks(InstanceCbBundle add, InstanceCbBundle change, InstanceCbBundle remove) {
if (add != null) setInstanceCallbackRef(Cb.ADD, (inst, component, bundle) -> add.accept(bundle));
if (change != null) setInstanceCallbackRef(Cb.CHG, (inst, component, bundle) -> change.accept(bundle));
if (remove != null) setInstanceCallbackRef(Cb.REM, (inst, component, bundle) -> remove.accept(bundle));
@@ -240,20 +249,24 @@
}
@Override
- public BundleDependencyBuilder cbi(CbComponentBundle add) {
- return cbi(add, null, null);
+ public BundleDependencyBuilder add(InstanceCbBundleComponent add) {
+ return callbacks(add, null, null);
}
@Override
- public BundleDependencyBuilder cbi(CbComponentBundle add, CbComponentBundle remove) {
- return cbi(add, null, remove);
+ public BundleDependencyBuilder change(InstanceCbBundleComponent add) {
+ return callbacks(add, null, null);
+ }
+
+ @Override
+ public BundleDependencyBuilder remove(InstanceCbBundleComponent remove) {
+ return callbacks(null, null, remove);
}
- @Override
- public BundleDependencyBuilder cbi(CbComponentBundle add, CbComponentBundle change, CbComponentBundle remove) {
- if (add != null) setInstanceCallbackRef(Cb.ADD, (inst, component, bundle) -> add.accept(component, bundle));
- if (change != null) setInstanceCallbackRef(Cb.CHG, (inst, component, bundle) -> change.accept(component, bundle));
- if (remove != null) setInstanceCallbackRef(Cb.REM, (inst, component, bundle) -> remove.accept(component, bundle));
+ private BundleDependencyBuilder callbacks(InstanceCbBundleComponent add, InstanceCbBundleComponent change, InstanceCbBundleComponent remove) {
+ if (add != null) setInstanceCallbackRef(Cb.ADD, (inst, component, bundle) -> add.accept(bundle, component));
+ if (change != null) setInstanceCallbackRef(Cb.CHG, (inst, component, bundle) -> change.accept(bundle, component));
+ if (remove != null) setInstanceCallbackRef(Cb.REM, (inst, component, bundle) -> remove.accept(bundle, component));
return this;
}
@@ -280,7 +293,7 @@
dep.setPropagate(true);
} else if (m_propagateInstance != null) {
dep.setPropagate(m_propagateInstance, m_propagateMethod);
- } else if (m_propagateSupplier != null) {
+ } else if (m_propagateCallback != null) {
dep.setPropagate(new Propagate(), "propagate");
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/CompletableFutureDependencyImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/CompletableFutureDependencyImpl.java
index d41456f..ae03fdf 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/CompletableFutureDependencyImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/CompletableFutureDependencyImpl.java
@@ -14,7 +14,7 @@
import org.apache.felix.dm.context.EventType;
import org.apache.felix.dm.lambda.FutureDependencyBuilder;
import org.apache.felix.dm.lambda.callbacks.CbFuture;
-import org.apache.felix.dm.lambda.callbacks.CbTypeFuture;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbFuture;
import org.osgi.service.log.LogService;
public class CompletableFutureDependencyImpl<F> extends AbstractDependency<CompletableFutureDependencyImpl<F>> implements FutureDependencyBuilder<F> {
@@ -23,8 +23,8 @@
private Component m_comp;
private boolean m_async;
private Executor m_exec;
- private CbFuture<F> m_accept = (future) -> {};
- private CbTypeFuture<Object, F> m_accept2;
+ private InstanceCbFuture<F> m_accept = (future) -> {};
+ private CbFuture<Object, F> m_accept2;
private Class<?> m_accept2Type;
public CompletableFutureDependencyImpl(Component c, CompletableFuture<F> future) {
@@ -51,24 +51,24 @@
}
@Override
- public FutureDependencyBuilder<F> cb(String callback) {
- return cbi(null, callback);
+ public FutureDependencyBuilder<F> complete(String callback) {
+ return complete(null, callback);
}
@Override
- public FutureDependencyBuilder<F> cbi(Object callbackInstance, String callback) {
+ public FutureDependencyBuilder<F> complete(Object callbackInstance, String callback) {
super.setCallbacks(callbackInstance, callback, null);
return this;
}
@Override
- public <T> FutureDependencyBuilder<F> cb(CbTypeFuture<T, ? super F> consumer) {
- return cb(consumer, false);
+ public <T> FutureDependencyBuilder<F> complete(CbFuture<T, ? super F> consumer) {
+ return complete(consumer, false);
}
@SuppressWarnings("unchecked")
@Override
- public <T> FutureDependencyBuilder<F> cb(CbTypeFuture<T, ? super F> consumer, boolean async) {
+ public <T> FutureDependencyBuilder<F> complete(CbFuture<T, ? super F> consumer, boolean async) {
m_accept2Type = Helpers.getLambdaArgType(consumer, 0);;
m_accept2 = (instance, result) -> consumer.accept((T) instance, result);
m_async = async;
@@ -76,28 +76,28 @@
}
@Override
- public <T> FutureDependencyBuilder<F> cb(CbTypeFuture<T, ? super F> consumer, Executor executor) {
- cb(consumer, true /* async */);
+ public <T> FutureDependencyBuilder<F> complete(CbFuture<T, ? super F> consumer, Executor executor) {
+ complete(consumer, true /* async */);
m_exec = executor;
return this;
}
@Override
- public FutureDependencyBuilder<F> cbi(CbFuture<? super F> consumer) {
- cbi(consumer, false);
+ public FutureDependencyBuilder<F> complete(InstanceCbFuture<? super F> consumer) {
+ complete(consumer, false);
return this;
}
@Override
- public FutureDependencyBuilder<F> cbi(CbFuture<? super F> consumer, boolean async) {
+ public FutureDependencyBuilder<F> complete(InstanceCbFuture<? super F> consumer, boolean async) {
m_accept = m_accept.andThen(future -> consumer.accept(future));
m_async = async;
return this;
}
@Override
- public FutureDependencyBuilder<F> cbi(CbFuture<? super F> consumer, Executor executor) {
- cbi(consumer, true /* async */);
+ public FutureDependencyBuilder<F> complete(InstanceCbFuture<? super F> consumer, Executor executor) {
+ complete(consumer, true /* async */);
m_exec = executor;
return this;
}
@@ -212,7 +212,7 @@
}
/**
- * Injects the completed fiture result in a method by reflection.
+ * Injects the completed future result in a method by reflection.
* We try to find a method which has in its signature a parameter that is compatible with the future result
* (including any interfaces the result may implements).
*
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java
index a5bab10..66631cf 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java
@@ -29,9 +29,10 @@
import org.apache.felix.dm.lambda.FluentProperty;
import org.apache.felix.dm.lambda.FutureDependencyBuilder;
import org.apache.felix.dm.lambda.ServiceDependencyBuilder;
+import org.apache.felix.dm.lambda.callbacks.Cb;
import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbConsumer;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCb;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbComponent;
public class ComponentBuilderImpl implements ComponentBuilder<ComponentBuilderImpl> {
private final List<DependencyBuilder<?>> m_dependencyBuilders = new ArrayList<>();
@@ -369,12 +370,12 @@
}
@Override
- public ComponentBuilderImpl withSrv(Class<?> service, String filter) {
- return withSrv(service, srv->srv.filter(filter));
+ public ComponentBuilderImpl withSvc(Class<?> service, String filter) {
+ return withSvc(service, srv->srv.filter(filter));
}
@Override
- public ComponentBuilderImpl withSrv(Class<?> ... services) {
+ public ComponentBuilderImpl withSvc(Class<?> ... services) {
for (Class<?> s : services) {
doWithService(s);
}
@@ -387,7 +388,7 @@
}
@Override
- public <U> ComponentBuilderImpl withSrv(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
+ public <U> ComponentBuilderImpl withSvc(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) {
ServiceDependencyBuilder<U> dep = new ServiceDependencyBuilderImpl<>(m_component, service);
consumer.accept(dep);
m_dependencyBuilders.add(dep);
@@ -418,6 +419,11 @@
return this;
}
+ public ComponentBuilderImpl lifecycleCallbackInstance(Object callbackInstance) {
+ m_callbackInstance = callbackInstance;
+ return this;
+ }
+
public ComponentBuilderImpl init(String callback) {
ensureHasNoLifecycleMethodRefs();
m_init = callback;
@@ -442,132 +448,112 @@
return this;
}
- public ComponentBuilderImpl init(Object callbackInstance, String callback) {
- m_callbackInstance = callbackInstance;
- return init(callback);
- }
-
- public ComponentBuilderImpl start(Object callbackInstance, String callback) {
- m_callbackInstance = callbackInstance;
- return start(callback);
- }
-
- public ComponentBuilderImpl stop(Object callbackInstance, String callback) {
- m_callbackInstance = callbackInstance;
- return stop(callback);
- }
-
- public ComponentBuilderImpl destroy(Object callbackInstance, String callback) {
- m_callbackInstance = callbackInstance;
- return destroy(callback);
- }
-
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl init(CbConsumer<U> callback) {
+ public <T> ComponentBuilderImpl init(Cb<T> callback) {
if (callback != null) {
- setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+ setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl start(CbConsumer<U> callback) {
+ public <T> ComponentBuilderImpl start(Cb<T> callback) {
if (callback != null) {
- setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+ setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl stop(CbConsumer<U> callback) {
+ public <T> ComponentBuilderImpl stop(Cb<T> callback) {
if (callback != null) {
- setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+ setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl destroy(CbConsumer<U> callback) {
+ public <T> ComponentBuilderImpl destroy(Cb<T> callback) {
if (callback != null) {
- setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst));
+ setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl init(CbTypeComponent<U> callback) {
+ public <T> ComponentBuilderImpl init(CbComponent<T> callback) {
if (callback != null) {
- setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+ setComponentCallbackRef(INIT, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl start(CbTypeComponent<U> callback) {
+ public <T> ComponentBuilderImpl start(CbComponent<T> callback) {
if (callback != null) {
- setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+ setComponentCallbackRef(START, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl stop(CbTypeComponent<U> callback) {
+ public <T> ComponentBuilderImpl stop(CbComponent<T> callback) {
if (callback != null) {
- setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+ setComponentCallbackRef(STOP, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
}
return this;
}
@SuppressWarnings("unchecked")
@Override
- public <U> ComponentBuilderImpl destroy(CbTypeComponent<U> callback) {
+ public <T> ComponentBuilderImpl destroy(CbComponent<T> callback) {
if (callback != null) {
- setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((U) inst, component));
+ setComponentCallbackRef(DESTROY, Helpers.getLambdaArgType(callback, 0), (inst, component) -> callback.accept((T) inst, component));
}
return this;
}
@Override
- public ComponentBuilderImpl initInstance(Runnable callback) {
+ public ComponentBuilderImpl initInstance(InstanceCb callback) {
if (callback != null) {
- setInstanceCallbackRef(INIT, (inst, component) -> callback.run());
+ setInstanceCallbackRef(INIT, (inst, component) -> callback.cb());
}
return this;
}
@Override
- public ComponentBuilderImpl startInstance(Runnable callback) {
+ public ComponentBuilderImpl startInstance(InstanceCb callback) {
if (callback != null) {
- setInstanceCallbackRef(START, (inst, component) -> callback.run());
+ setInstanceCallbackRef(START, (inst, component) -> callback.cb());
}
return this;
}
@Override
- public ComponentBuilderImpl stopInstance(Runnable callback) {
+ public ComponentBuilderImpl stopInstance(InstanceCb callback) {
if (callback != null) {
- setInstanceCallbackRef(STOP, (inst, component) -> callback.run());
+ setInstanceCallbackRef(STOP, (inst, component) -> callback.cb());
}
return this;
}
@Override
- public ComponentBuilderImpl destroyInstance(Runnable callback) {
+ public ComponentBuilderImpl destroyInstance(InstanceCb callback) {
if (callback != null) {
- setInstanceCallbackRef(DESTROY, (inst, component) -> callback.run());
+ setInstanceCallbackRef(DESTROY, (inst, component) -> callback.cb());
}
return this;
}
@Override
- public ComponentBuilderImpl initInstance(CbComponent callback) {
+ public ComponentBuilderImpl initInstance(InstanceCbComponent callback) {
if (callback != null) {
setInstanceCallbackRef(INIT, (inst, component) -> callback.accept(component));
}
@@ -575,7 +561,7 @@
}
@Override
- public ComponentBuilderImpl startInstance(CbComponent callback) {
+ public ComponentBuilderImpl startInstance(InstanceCbComponent callback) {
if (callback != null) {
setInstanceCallbackRef(START, (inst, component) -> callback.accept(component));
}
@@ -583,7 +569,7 @@
}
@Override
- public ComponentBuilderImpl stopInstance(CbComponent callback) {
+ public ComponentBuilderImpl stopInstance(InstanceCbComponent callback) {
if (callback != null) {
setInstanceCallbackRef(STOP, (inst, component) -> callback.accept(component));
}
@@ -591,7 +577,7 @@
}
@Override
- public ComponentBuilderImpl destroyInstance(CbComponent callback) {
+ public ComponentBuilderImpl destroyInstance(InstanceCbComponent callback) {
if (callback != null) {
setInstanceCallbackRef(DESTROY, (inst, component) -> callback.accept(component));
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java
index 89f48c6..2d8f2d9 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ConfigurationDependencyBuilderImpl.java
@@ -8,23 +8,28 @@
import org.apache.felix.dm.Component;
import org.apache.felix.dm.ConfigurationDependency;
+import org.apache.felix.dm.context.ComponentContext;
import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder;
-import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.CbConfigurationComponent;
import org.apache.felix.dm.lambda.callbacks.CbDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbDictionaryComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
public class ConfigurationDependencyBuilderImpl implements ConfigurationDependencyBuilder {
private String m_pid;
private boolean m_propagate;
private final Component m_component;
- private String m_updateMethodName;
+ private String m_updateMethodName = "updated";
private Object m_updateCallbackInstance;
private boolean m_hasMethodRefs;
private boolean m_hasReflectionCallback;
private final List<MethodRef<Object>> m_refs = new ArrayList<>();
private boolean m_hasComponentCallbackRefs;
- private boolean m_needsInstance = false;
+ private Class<?> m_configType;
@FunctionalInterface
interface MethodRef<I> {
@@ -40,13 +45,7 @@
m_pid = pid;
return this;
}
-
- @Override
- public ConfigurationDependencyBuilder pid(Class<?> pidClass) {
- m_pid = pidClass.getName();
- return this;
- }
-
+
@Override
public ConfigurationDependencyBuilder propagate() {
m_propagate = true;
@@ -59,58 +58,107 @@
return this;
}
- public ConfigurationDependencyBuilder cb(String update) {
+ public ConfigurationDependencyBuilder update(String update) {
checkHasNoMethodRefs();
m_hasReflectionCallback = true;
m_updateMethodName = update;
return this;
}
- public ConfigurationDependencyBuilder cbi(Object callbackInstance, String update) {
+ public ConfigurationDependencyBuilder update(Class<?> configType, String updateMethod) {
+ m_configType = configType;
+ return update(updateMethod);
+ }
+
+ public ConfigurationDependencyBuilder update(Object callbackInstance, String update) {
m_updateCallbackInstance = callbackInstance;
- cb(update);
+ update(update);
return this;
}
-
- public ConfigurationDependencyBuilder needsInstance(boolean needsInstance) {
- m_needsInstance = needsInstance;
- return this;
+
+ public ConfigurationDependencyBuilder update(Class<?> configType, Object callbackInstance, String update) {
+ m_updateCallbackInstance = callbackInstance;
+ return update(callbackInstance, update);
}
@Override
- public <T> ConfigurationDependencyBuilder cb(CbTypeDictionary<T> callback) {
- Class<T> type = Helpers.getLambdaArgType(callback, 0);
- return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, props); });
+ public <T> ConfigurationDependencyBuilder update(CbDictionary<T> callback) {
+ Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+ return setComponentCallbackRef(componentType, (instance, component, props) -> {
+ callback.accept((T) instance, props);
+ });
}
@Override
- public <T> ConfigurationDependencyBuilder cb(CbTypeComponentDictionary<T> callback) {
- Class<T> type = Helpers.getLambdaArgType(callback, 0);
- return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, component, props); });
+ public <T> ConfigurationDependencyBuilder update(CbDictionaryComponent<T> callback) {
+ Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+ return setComponentCallbackRef(componentType, (instance, component, props) -> {
+ callback.accept((T) instance, props, component);
+ });
}
@Override
- public ConfigurationDependencyBuilder cbi(CbDictionary callback) {
- return setInstanceCallbackRef((instance, component, props) -> { callback.accept(props); });
+ public <T, U> ConfigurationDependencyBuilder update(Class<U> configClass, CbConfiguration<T, U> callback) {
+ Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+ m_pid = m_pid == null ? configClass.getName() : m_pid;
+ return setComponentCallbackRef(componentType, (instance, component, props) -> {
+ U configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);
+ callback.accept((T) instance, configProxy);
+ });
+ }
+
+ @Override
+ public <T, U> ConfigurationDependencyBuilder update(Class<U> configClass, CbConfigurationComponent<T, U> callback) {
+ Class<T> componentType = Helpers.getLambdaArgType(callback, 0);
+ m_pid = m_pid == null ? configClass.getName() : m_pid;
+ return setComponentCallbackRef(componentType, (instance, component, props) -> {
+ U configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);
+ callback.accept((T) instance, configProxy, component);
+ });
+ }
+
+ @Override
+ public ConfigurationDependencyBuilder update(InstanceCbDictionary callback) {
+ return setInstanceCallbackRef((instance, component, props) -> {
+ callback.accept(props);
+ });
+ }
+
+ @Override
+ public ConfigurationDependencyBuilder update(InstanceCbDictionaryComponent callback) {
+ return setInstanceCallbackRef((instance, component, props) -> {
+ callback.accept(props, component);
+ });
+ }
+
+ public <T> ConfigurationDependencyBuilder update(Class<T> configClass, InstanceCbConfiguration<T> updated) {
+ m_pid = m_pid == null ? configClass.getName() : m_pid;
+ return setInstanceCallbackRef((instance, component, props) -> {
+ T configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);
+ updated.accept(configProxy);
+ });
+ }
+
+ public <T> ConfigurationDependencyBuilder update(Class<T> configClass, InstanceCbConfigurationComponent<T> updated) {
+ m_pid = m_pid == null ? configClass.getName() : m_pid;
+ return setInstanceCallbackRef((instance, component, props) -> {
+ T configProxy = ((ComponentContext) m_component).createConfigurationProxy(configClass, props);
+ updated.accept(configProxy, component);
+ });
}
@Override
- public ConfigurationDependencyBuilder cbi(CbComponentDictionary callback) {
- return setInstanceCallbackRef((instance, component, props) -> { callback.accept(component, props); });
- }
-
- @Override
public ConfigurationDependency build() {
+ String pid = m_pid == null ? (m_configType != null ? m_configType.getName() : null) : m_pid;
+ if (pid == null) {
+ throw new IllegalStateException("Pid not specified");
+ }
ConfigurationDependency dep = m_component.getDependencyManager().createConfigurationDependency();
Objects.nonNull(m_pid);
- dep.setPid(m_pid);
+ dep.setPid(pid);
dep.setPropagate(m_propagate);
if (m_updateMethodName != null) {
- if (m_updateCallbackInstance != null) {
- dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_needsInstance);
- } else {
- dep.setCallback(m_updateMethodName);
- }
+ dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_configType);
} else if (m_refs.size() > 0) {
// setup an internal callback object. When config is updated, we have to call each registered
// method references.
@@ -121,7 +169,7 @@
void updated(Component comp, Dictionary<String, Object> props) {
m_refs.forEach(mref -> mref.accept(null, comp, props));
}
- }, "updated", m_hasComponentCallbackRefs||m_needsInstance);
+ }, "updated", m_hasComponentCallbackRefs);
}
return dep;
}
@@ -129,6 +177,7 @@
private <T> ConfigurationDependencyBuilder setInstanceCallbackRef(MethodRef<T> ref) {
checkHasNoReflectionCallbacks();
m_hasMethodRefs = true;
+ m_updateMethodName = null;
m_refs.add((instance, component, props) -> ref.accept(null, component, props));
return this;
}
@@ -136,6 +185,7 @@
@SuppressWarnings("unchecked")
private <T> ConfigurationDependencyBuilder setComponentCallbackRef(Class<T> type, MethodRef<T> ref) {
checkHasNoReflectionCallbacks();
+ m_updateMethodName = null;
m_hasMethodRefs = true;
m_hasComponentCallbackRefs = true;
m_refs.add((instance, component, props) -> {
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java
index c3ee095..4bec193 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/FactoryPidAdapterBuilderImpl.java
@@ -9,12 +9,17 @@
import org.apache.felix.dm.Component;
import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.context.ComponentContext;
import org.apache.felix.dm.lambda.ComponentBuilder;
import org.apache.felix.dm.lambda.FactoryPidAdapterBuilder;
-import org.apache.felix.dm.lambda.callbacks.CbComponentDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.CbConfigurationComponent;
import org.apache.felix.dm.lambda.callbacks.CbDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentDictionary;
-import org.apache.felix.dm.lambda.callbacks.CbTypeDictionary;
+import org.apache.felix.dm.lambda.callbacks.CbDictionaryComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfiguration;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbConfigurationComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionary;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbDictionaryComponent;
public class FactoryPidAdapterBuilderImpl implements AdapterBase<FactoryPidAdapterBuilder>, FactoryPidAdapterBuilder {
private String m_factoryPid;
@@ -27,6 +32,7 @@
private boolean m_hasReflectionCallback;
private Consumer<ComponentBuilder<?>> m_compBuilder = (componentBuilder -> {});
private final List<MethodRef<Object>> m_refs = new ArrayList<>();
+ private Class<?> m_configType;
@FunctionalInterface
interface MethodRef<I> {
@@ -58,12 +64,6 @@
}
@Override
- public FactoryPidAdapterBuilder factoryPid(Class<?> pidClass) {
- m_factoryPid = pidClass.getName();
- return this;
- }
-
- @Override
public FactoryPidAdapterBuilder propagate() {
m_propagate = true;
return this;
@@ -75,39 +75,91 @@
return this;
}
- public FactoryPidAdapterBuilder cb(String update) {
+ @Override
+ public FactoryPidAdapterBuilder update(String update) {
checkHasNoMethodRefs();
m_hasReflectionCallback = true;
m_updateMethodName = update;
return this;
}
- public FactoryPidAdapterBuilder cb(Object callbackInstance, String update) {
- cb(update);
+ @Override
+ public FactoryPidAdapterBuilder update(Class<?> configType, String updateMethod) {
+ update(updateMethod);
+ m_configType = configType;
+ return this;
+ }
+
+ @Override
+ public FactoryPidAdapterBuilder update(Object callbackInstance, String update) {
+ update(update);
m_updateCallbackInstance = callbackInstance;
return this;
}
@Override
- public <U> FactoryPidAdapterBuilder cb(CbTypeDictionary<U> callback) {
- Class<U> type = Helpers.getLambdaArgType(callback, 0);
- return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((U) instance, props); });
+ public FactoryPidAdapterBuilder update(Class<?> configType, Object callbackInstance, String updateMethod) {
+ update(callbackInstance, updateMethod);
+ m_configType = configType;
+ return this;
}
@Override
- public <U> FactoryPidAdapterBuilder cb(CbTypeComponentDictionary<U> callback) {
- Class<U> type = Helpers.getLambdaArgType(callback, 0);
- return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((U) instance, component, props); });
+ public <T> FactoryPidAdapterBuilder update(CbDictionary<T> callback) {
+ Class<T> type = Helpers.getLambdaArgType(callback, 0);
+ return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, props); });
+ }
+
+ @Override
+ public <T, U> FactoryPidAdapterBuilder update(Class<U> configType, CbConfiguration<T, U> callback) {
+ Class<T> type = Helpers.getLambdaArgType(callback, 0);
+ m_factoryPid = m_factoryPid == null ? configType.getName() : m_factoryPid;
+ return setComponentCallbackRef(type, (instance, component, props) -> {
+ U configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);
+ callback.accept((T) instance, configProxy);
+ });
+ }
+
+ @Override
+ public <T> FactoryPidAdapterBuilder update(CbDictionaryComponent<T> callback) {
+ Class<T> type = Helpers.getLambdaArgType(callback, 0);
+ return setComponentCallbackRef(type, (instance, component, props) -> { callback.accept((T) instance, props, component); });
}
@Override
- public FactoryPidAdapterBuilder cbi(CbDictionary callback) {
+ public <T, U> FactoryPidAdapterBuilder update(Class<U> configType, CbConfigurationComponent<T, U> callback) {
+ Class<T> type = Helpers.getLambdaArgType(callback, 0);
+ m_factoryPid = m_factoryPid == null ? configType.getName() : m_factoryPid;
+ return setComponentCallbackRef(type, (instance, component, props) -> {
+ U configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);
+ callback.accept((T) instance, configProxy, component);
+ });
+ }
+
+ @Override
+ public FactoryPidAdapterBuilder update(InstanceCbDictionary callback) {
return setInstanceCallbackRef((instance, component, props) -> { callback.accept(props); });
}
+
+ @Override
+ public <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfiguration<T> callback) {
+ return setInstanceCallbackRef((instance, component, props) -> {
+ T configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);
+ callback.accept(configProxy);
+ });
+ }
@Override
- public FactoryPidAdapterBuilder cbi(CbComponentDictionary callback) {
- return setInstanceCallbackRef((instance, component, props) -> { callback.accept(component, props); });
+ public FactoryPidAdapterBuilder update(InstanceCbDictionaryComponent callback) {
+ return setInstanceCallbackRef((instance, component, props) -> { callback.accept(props, component); });
+ }
+
+ @Override
+ public <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfigurationComponent<T> callback) {
+ return setInstanceCallbackRef((instance, component, props) -> {
+ T configProxy = ((ComponentContext) component).createConfigurationProxy(configType, props);
+ callback.accept(configProxy, component);
+ });
}
@Override
@@ -124,14 +176,14 @@
};
c = m_dm.createFactoryConfigurationAdapterService(m_factoryPid, "updated", m_propagate, wrapCallback);
} else {
- c = m_dm.createFactoryConfigurationAdapterService(m_factoryPid, m_updateMethodName, m_propagate, m_updateCallbackInstance);
+ c = m_dm.createFactoryConfigurationAdapterService(m_factoryPid, m_updateMethodName, m_propagate, m_updateCallbackInstance, m_configType);
}
ComponentBuilderImpl cb = new ComponentBuilderImpl(c, false);
m_compBuilder.accept (cb);
return cb.build();
}
- private <U> FactoryPidAdapterBuilder setInstanceCallbackRef(MethodRef<U> ref) {
+ private <T> FactoryPidAdapterBuilder setInstanceCallbackRef(MethodRef<T> ref) {
checkHasNoReflectionCallbacks();
m_hasMethodRefs = true;
m_refs.add((instance, component, props) -> ref.accept(null, component, props));
@@ -139,7 +191,7 @@
}
@SuppressWarnings("unchecked")
- private <U> FactoryPidAdapterBuilder setComponentCallbackRef(Class<U> type, MethodRef<U> ref) {
+ private <T> FactoryPidAdapterBuilder setComponentCallbackRef(Class<T> type, MethodRef<T> ref) {
checkHasNoReflectionCallbacks();
m_hasMethodRefs = true;
m_refs.add((instance, component, props) -> {
@@ -147,7 +199,7 @@
.filter(impl -> Helpers.getClass(impl).equals(type))
.findFirst()
.orElseThrow(() -> new IllegalStateException("The method reference " + ref + " does not match any available component impl classes."));
- ref.accept((U) componentImpl, component, props);
+ ref.accept((T) componentImpl, component, props);
});
return this;
}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java
index 50eb73c..d879e9c 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/Helpers.java
@@ -12,6 +12,7 @@
import java.util.stream.Stream;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.context.ComponentContext;
import org.apache.felix.dm.lambda.callbacks.SerializableLambda;
/**
@@ -19,8 +20,31 @@
*/
public class Helpers {
private final static Pattern LAMBDA_INSTANCE_METHOD_TYPE = Pattern.compile("(L[^;]+)+");
+ private final static String DEFAULT_DEPENDENCY_MODE = "org.apache.felix.dependencymanager.lambda.dependencymode";
+ private final static String REQUIRED = "required";
+ private final static String OPTIONAL = "optional";
/**
+ * Tests if a dependency is required by default.
+ * By default, a dependency is required, but you can configure the mode of a dependency, by configure the
+ * DEFAULT_DEPENDENCY_MODE property in the bundle context properties. This property can take as value:
+ * <ul><li>"required" meaning that dependencies are required by default,
+ * <li>"optional" meaning that dependencies are optional by default.
+ * </ul>
+ * By default, a dependency is required.
+ */
+ static boolean isDependencyRequiredByDefault(Component component) {
+ String property = ((ComponentContext) component).getBundleContext().getProperty(DEFAULT_DEPENDENCY_MODE);
+ if (REQUIRED.equalsIgnoreCase(property)) {
+ return true;
+ } else if (OPTIONAL.equalsIgnoreCase(property)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
* Gets the class name of a given object.
* @param obj the object whose class has to be returned.
*/
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java
index 33188ac..deb6a47 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceCallbacksBuilderImpl.java
@@ -4,38 +4,30 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
import java.util.stream.Stream;
import org.apache.felix.dm.Component;
import org.apache.felix.dm.lambda.ServiceCallbacksBuilder;
-import org.apache.felix.dm.lambda.callbacks.CbComponent;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRef;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRefService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentService;
-import org.apache.felix.dm.lambda.callbacks.CbComponentServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbRef;
-import org.apache.felix.dm.lambda.callbacks.CbRefService;
import org.apache.felix.dm.lambda.callbacks.CbRefServiceRefService;
+import org.apache.felix.dm.lambda.callbacks.CbRefServiceRefServiceComponent;
import org.apache.felix.dm.lambda.callbacks.CbService;
+import org.apache.felix.dm.lambda.callbacks.CbServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.CbServiceComponentRef;
import org.apache.felix.dm.lambda.callbacks.CbServiceDict;
import org.apache.felix.dm.lambda.callbacks.CbServiceMap;
+import org.apache.felix.dm.lambda.callbacks.CbServiceRef;
import org.apache.felix.dm.lambda.callbacks.CbServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRef;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeComponentServiceService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRef;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeRefServiceRefService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeService;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceDict;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceMap;
-import org.apache.felix.dm.lambda.callbacks.CbTypeServiceService;
+import org.apache.felix.dm.lambda.callbacks.CbServiceServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbRefServiceRefService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbRefServiceRefServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceComponent;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceComponentRef;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceDict;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceMap;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceRef;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceService;
+import org.apache.felix.dm.lambda.callbacks.InstanceCbServiceServiceComponent;
import org.osgi.framework.ServiceReference;
/**
@@ -119,39 +111,29 @@
return (B) this;
}
- public B cb(String ... callbacks) {
- return cbi(null, callbacks);
- }
-
- public B cbi(Object callbackInstance, String ... callbacks) {
- Objects.nonNull(callbacks);
- switch (callbacks.length) {
- case 1:
- cb(callbackInstance, callbacks[0], null, null, null);
- break;
-
- case 2:
- cb(callbackInstance, callbacks[0], null, callbacks[1], null);
- break;
-
- case 3:
- cb(callbackInstance, callbacks[0], callbacks[1], callbacks[2], null);
- break;
-
- case 4:
- cb(callbackInstance, callbacks[0], callbacks[1], callbacks[2], callbacks[3]);
- break;
-
- default:
- throw new IllegalArgumentException("wrong number of arguments: " + callbacks.length + ". " +
- "Possible arguments: [add], [add, remove], [add, change, remove], or [add, change, remove, swap]");
- }
+ public B callbackInstance(Object callbackInstance) {
+ m_callbackInstance = callbackInstance;
return (B) this;
}
- private B cb(Object callbackInstance, String added, String changed, String removed, String swapped) {
+ public B add(String add) {
+ return callbacks(add, null, null, null);
+ }
+
+ public B change(String change) {
+ return callbacks(null, change, null, null);
+ }
+
+ public B remove(String remove) {
+ return callbacks(null, null, remove, null);
+ }
+
+ public B swap(String swap) {
+ return callbacks(null, null, null, swap);
+ }
+
+ private B callbacks(String added, String changed, String removed, String swapped) {
requiresNoMethodRefs();
- m_callbackInstance = callbackInstance;
m_added = added != null ? added : m_added;
m_changed = changed != null ? changed : m_changed;
m_removed = removed != null ? removed : m_removed;
@@ -160,15 +142,19 @@
return (B) this;
}
- public <T> B cb(CbTypeService<T, S> add) {
- return cb(add, null, null);
+ public <T> B add(CbService<T, S> add) {
+ return callbacks(add, null, null);
}
- public <T> B cb(CbTypeService<T, S> add, CbTypeService<T, S> remove) {
- return cb(add, null, remove);
+ public <T> B change(CbService<T, S> change) {
+ return callbacks(null, change, null);
}
- public <T> B cb(CbTypeService<T, S> add, CbTypeService<T, S> change, CbTypeService<T, S> remove) {
+ public <T> B remove(CbService<T, S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private <T> B callbacks(CbService<T, S> add, CbService<T, S> change, CbService<T, S> remove) {
if (add != null)
setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv));
if (change != null)
@@ -178,15 +164,19 @@
return (B) this;
}
- public B cbi(CbService<S> add) {
- return cbi(add, null, null);
+ public B add(InstanceCbService<S> add) {
+ return callbacks(add, null, null);
}
- public B cbi(CbService<S> add, CbService<S> remove) {
- return cbi(add, null, remove);
+ public B change(InstanceCbService<S> change) {
+ return callbacks(null, change, null);
}
- public B cbi(CbService<S> add, CbService<S> change, CbService<S> remove) {
+ public B remove(InstanceCbService<S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public B callbacks(InstanceCbService<S> add, InstanceCbService<S> change, InstanceCbService<S> remove) {
if (add != null)
setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv));
if (change != null)
@@ -196,15 +186,19 @@
return (B) this;
}
- public <T> B cb(CbTypeServiceMap<T, S> add) {
- return cb(add, null, null);
+ public <T> B add(CbServiceMap<T, S> add) {
+ return callbacks(add, null, null);
}
- public <T> B cb(CbTypeServiceMap<T, S> add, CbTypeServiceMap<T, S> remove) {
- return cb(add, null, remove);
+ public <T> B change(CbServiceMap<T, S> change) {
+ return callbacks(null, change, null);
}
-
- public <T> B cb(CbTypeServiceMap<T, S> add, CbTypeServiceMap<T, S> change, CbTypeServiceMap<T, S> remove) {
+
+ public <T> B remove(CbServiceMap<T, S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public <T> B callbacks(CbServiceMap<T, S> add, CbServiceMap<T, S> change, CbServiceMap<T, S> remove) {
if (add != null)
setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, new SRefAsMap(ref)));
if (change != null)
@@ -214,15 +208,19 @@
return (B) this;
}
- public B cbi(CbServiceMap<S> add) {
- return cbi(add, null, null);
+ public B add(InstanceCbServiceMap<S> add) {
+ return callbacks(add, null, null);
}
- public B cbi(CbServiceMap<S> add, CbServiceMap<S> remove) {
- return cbi(add, null, remove);
+ public B change(InstanceCbServiceMap<S> change) {
+ return callbacks(null, change, null);
}
- public B cbi(CbServiceMap<S> add, CbServiceMap<S> change, CbServiceMap<S> remove) {
+ public B remove(InstanceCbServiceMap<S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public B callbacks(InstanceCbServiceMap<S> add, InstanceCbServiceMap<S> change, InstanceCbServiceMap<S> remove) {
if (add != null)
setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, new SRefAsMap(ref)));
if (change != null)
@@ -232,15 +230,19 @@
return (B) this;
}
- public <T> B cb(CbTypeServiceDict<T, S> add) {
- return cb(add, null, null);
- }
-
- public <T> B cb(CbTypeServiceDict<T, S> add, CbTypeServiceDict<T, S> remove) {
- return cb(add, null, remove);
+ public <T> B add(CbServiceDict<T, S> add) {
+ return callbacks(add, null, null);
}
- public <T> B cb(CbTypeServiceDict<T, S> add, CbTypeServiceDict<T, S> change, CbTypeServiceDict<T, S> remove) {
+ public <T> B change(CbServiceDict<T, S> change) {
+ return callbacks(null, change, null);
+ }
+
+ public <T> B remove(CbServiceDict<T, S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public <T> B callbacks(CbServiceDict<T, S> add, CbServiceDict<T, S> change, CbServiceDict<T, S> remove) {
if (add != null)
setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, new SRefAsDictionary(ref)));
if (change != null)
@@ -250,15 +252,19 @@
return (B) this;
}
- public B cbi(CbServiceDict<S> add) {
- return cbi(add, null, null);
+ public B add(InstanceCbServiceDict<S> add) {
+ return callbacks(add, null, null);
}
- public B cbi(CbServiceDict<S> add, CbServiceDict<S> remove) {
- return cbi(add, null, remove);
+ public B change(InstanceCbServiceDict<S> change) {
+ return callbacks(null, change, null);
}
- public B cbi(CbServiceDict<S> add, CbServiceDict<S> change, CbServiceDict<S> remove) {
+ public B remove(InstanceCbServiceDict<S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public B callbacks(InstanceCbServiceDict<S> add, InstanceCbServiceDict<S> change, InstanceCbServiceDict<S> remove) {
if (add != null)
setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, new SRefAsDictionary(ref)));
if (change != null)
@@ -267,261 +273,178 @@
setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, new SRefAsDictionary(ref)));
return (B) this;
}
-
- public <T> B cb(CbTypeRefService<T, S> add) {
- return cb(add, null, null);
+
+ public <T> B add(CbServiceRef<T, S> add) {
+ return callbacks(add, null, null);
}
- public <T> B cb(CbTypeRefService<T, S> add, CbTypeRefService<T, S> remove) {
- return cb(add, null, remove);
+ public <T> B change(CbServiceRef<T, S> change) {
+ return callbacks(null, change, null);
}
- public <T> B cb(CbTypeRefService<T, S> add, CbTypeRefService<T, S> change, CbTypeRefService<T, S> remove) {
+ public <T> B remove(CbServiceRef<T, S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public <T> B callbacks(CbServiceRef<T, S> add, CbServiceRef<T, S> change, CbServiceRef<T, S> remove) {
if (add != null)
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, ref, srv));
+ setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, ref));
if (change != null)
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, ref, srv));
+ setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, srv, ref));
if (remove != null)
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, ref, srv));
+ setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, srv, ref));
return (B) this;
}
- public B cbi(CbRefService<S> add) {
- return cbi(add, null, null);
+ public B add(InstanceCbServiceRef<S> add) {
+ return callbacks(add, null, null);
}
- public B cbi(CbRefService<S> add, CbRefService<S> remove) {
- return cbi(add, null, remove);
+ public B change(InstanceCbServiceRef<S> change) {
+ return callbacks(null, change, null);
}
- public B cbi(CbRefService<S> add, CbRefService<S> change, CbRefService<S> remove) {
+ public B remove(InstanceCbServiceRef<S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public B callbacks(InstanceCbServiceRef<S> add, InstanceCbServiceRef<S> change, InstanceCbServiceRef<S> remove) {
if (add != null)
- setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(ref, srv));
+ setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, ref));
if (change != null)
- setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(ref, srv));
+ setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(srv, ref));
if (remove != null)
- setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(ref, srv));
+ setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, ref));
return (B) this;
}
- public <T> B cb(CbTypeRef<T, S> add) {
- return cb(add, null, null);
+ public <T> B add(CbServiceComponent<T, S> add) {
+ return callbacks(add, null, null);
}
- public <T> B cb(CbTypeRef<T, S> add, CbTypeRef<T, S> remove) {
- return cb(add, null, remove);
+ public <T> B change(CbServiceComponent<T, S> change) {
+ return callbacks(null, change, null);
}
- public <T> B cb(CbTypeRef<T, S> add, CbTypeRef<T, S> change, CbTypeRef<T, S> remove) {
+ public <T> B remove(CbServiceComponent<T, S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private <T> B callbacks(CbServiceComponent<T, S> add, CbServiceComponent<T, S> change, CbServiceComponent<T, S> remove) {
if (add != null)
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, ref));
+ setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, comp));
if (change != null)
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, ref));
+ setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, srv, comp));
if (remove != null)
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, ref));
+ setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, srv, comp));
return (B) this;
}
- public B cbi(CbRef<S> add) {
- return cbi(add, null, null);
+ public B add(InstanceCbServiceComponent<S> add) {
+ return callbacks(add, null, null);
}
- public B cbi(CbRef<S> add, CbRef<S> remove) {
- return cbi(add, null, remove);
+ public B change(InstanceCbServiceComponent<S> change) {
+ return callbacks(null, change, null);
}
- public B cbi(CbRef<S> add, CbRef<S> change, CbRef<S> remove) {
+ public B remove(InstanceCbServiceComponent<S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public B callbacks(InstanceCbServiceComponent<S> add, InstanceCbServiceComponent<S> change, InstanceCbServiceComponent<S> remove) {
if (add != null)
- setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(ref));
+ setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, comp));
if (change != null)
- setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(ref));
+ setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(srv, comp));
if (remove != null)
- setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(ref));
+ setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, comp));
return (B) this;
}
- public <T> B cb(CbTypeComponent<T> add) {
- return cb(add, null, null);
+ public <T> B add(CbServiceComponentRef<T, S> add) {
+ return callbacks(add, null, null);
}
- public <T> B cb(CbTypeComponent<T> add, CbTypeComponent<T> remove) {
- return cb(add, null, remove);
+ public <T> B change(CbServiceComponentRef<T, S> change) {
+ return callbacks(null, change, null);
}
- public <T> B cb(CbTypeComponent<T> add, CbTypeComponent<T> change, CbTypeComponent<T> remove) {
+ public <T> B remove(CbServiceComponentRef<T, S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ private <T> B callbacks(CbServiceComponentRef<T, S> add, CbServiceComponentRef<T, S> change, CbServiceComponentRef<T, S> remove) {
if (add != null)
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp));
+ setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, srv, comp, ref));
if (change != null)
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp));
+ setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, srv, comp, ref));
if (remove != null)
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp));
+ setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, srv, comp, ref));
return (B) this;
}
- public B cbi(CbComponent add) {
- return cbi(add, null, null);
+ public B add(InstanceCbServiceComponentRef<S> add) {
+ return callbacks(add, null, null);
}
- public B cbi(CbComponent add, CbComponent remove) {
- return cbi(add, null, remove);
+ public B change(InstanceCbServiceComponentRef<S> change) {
+ return callbacks(null, change, null);
}
- public B cbi(CbComponent add, CbComponent change, CbComponent remove) {
+ public B remove(InstanceCbServiceComponentRef<S> remove) {
+ return callbacks(null, null, remove);
+ }
+
+ public B callbacks(InstanceCbServiceComponentRef<S> add, InstanceCbServiceComponentRef<S> change, InstanceCbServiceComponentRef<S> remove) {
if (add != null)
- setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp));
+ setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(srv, comp, ref));
if (change != null)
- setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp));
+ setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(srv, comp, ref));
if (remove != null)
- setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp));
+ setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(srv, comp, ref));
return (B) this;
}
- public <T> B cb(CbTypeComponentRef<T, S> add) {
- return cb(add, null, null);
- }
-
- public <T> B cb(CbTypeComponentRef<T, S> add, CbTypeComponentRef<T, S> remove) {
- return cb(add, null, remove);
- }
-
- public <T> B cb(CbTypeComponentRef<T, S> add, CbTypeComponentRef<T, S> change, CbTypeComponentRef<T, S> remove) {
- if (add != null)
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp, ref));
- if (change != null)
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp, ref));
- if (remove != null)
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp, ref));
- return (B) this;
- }
-
- public B cbi(CbComponentRef<S> add) {
- return cbi(add, null, null);
- }
-
- public B cbi(CbComponentRef<S> add, CbComponentRef<S> remove) {
- return cbi(add, null, remove);
- }
-
- public B cbi(CbComponentRef<S> add, CbComponentRef<S> change, CbComponentRef<S> remove) {
- if (add != null)
- setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp, ref));
- if (change != null)
- setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp, ref));
- if (remove != null)
- setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp, ref));
- return (B) this;
- }
-
- public <T> B cb(CbTypeComponentService<T, S> add) {
- return cb(add, null, null);
- }
-
- public <T> B cb(CbTypeComponentService<T, S> add, CbTypeComponentService<T, S> remove) {
- return cb(add, null, remove);
- }
-
- public <T> B cb(CbTypeComponentService<T, S> add, CbTypeComponentService<T, S> change, CbTypeComponentService<T, S> remove) {
- if (add != null)
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp, srv));
- if (change != null)
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp, srv));
- if (remove != null)
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp, srv));
- return (B) this;
- }
-
- public B cbi(CbComponentService<S> add) {
- return cbi(add, null, null);
- }
-
- public B cbi(CbComponentService<S> add, CbComponentService<S> remove) {
- return cbi(add, null, remove);
- }
-
- public B cbi(CbComponentService<S> add, CbComponentService<S> change, CbComponentService<S> remove) {
- if (add != null)
- setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp, srv));
- if (change != null)
- setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp, srv));
- if (remove != null)
- setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp, srv));
- return (B) this;
- }
-
- public <T> B cb(CbTypeComponentRefService<T, S> add) {
- return cb(add, null, null);
- }
-
- public <T> B cb(CbTypeComponentRefService<T, S> add, CbTypeComponentRefService<T, S> remove) {
- return cb(add, null, remove);
- }
-
- public <T> B cb(CbTypeComponentRefService<T, S> add, CbTypeComponentRefService<T, S> change, CbTypeComponentRefService<T, S> remove) {
- if (add != null)
- setComponentCallbackRef(Cb.ADD, Helpers.getLambdaArgType(add, 0), (inst, comp, ref, srv) -> add.accept((T) inst, comp, ref, srv));
- if (change != null)
- setComponentCallbackRef(Cb.CHG, Helpers.getLambdaArgType(change, 0), (inst, comp, ref, srv) -> change.accept((T) inst, comp, ref, srv));
- if (remove != null)
- setComponentCallbackRef(Cb.REM, Helpers.getLambdaArgType(remove, 0), (inst, comp, ref, srv) -> remove.accept((T) inst, comp, ref, srv));
- return (B) this;
- }
-
- public B cbi(CbComponentRefService<S> add) {
- return cbi(add, null, null);
- }
-
- public B cbi(CbComponentRefService<S> add, CbComponentRefService<S> remove) {
- return cbi(add, null, remove);
- }
-
- public B cbi(CbComponentRefService<S> add, CbComponentRefService<S> change, CbComponentRefService<S> remove) {
- if (add != null)
- setInstanceCallbackRef(Cb.ADD, (inst, comp, ref, srv) -> add.accept(comp, ref, srv));
- if (change != null)
- setInstanceCallbackRef(Cb.CHG, (inst, comp, ref, srv) -> change.accept(comp, ref, srv));
- if (remove != null)
- setInstanceCallbackRef(Cb.REM, (inst, comp, ref, srv) -> remove.accept(comp, ref, srv));
- return (B) this;
- }
-
- public <T> B sw(CbTypeServiceService<T, S> swap) {
+ public <T> B swap(CbServiceService<T, S> swap) {
Class<T> type = Helpers.getLambdaArgType(swap, 0);
return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
swap.accept((T) inst, oserv, nserv));
}
- public <T> B sw(CbTypeComponentServiceService<T, S> swap) {
+ @Override
+ public <T> B swap(CbServiceServiceComponent<T, S> swap) {
Class<T> type = Helpers.getLambdaArgType(swap, 0);
return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
- swap.accept((T) inst, component, oserv, nserv));
+ swap.accept((T) inst, oserv, nserv, component));
}
- public <T> B sw(CbTypeRefServiceRefService<T, S> swap) {
+ public <T> B swap(CbRefServiceRefService<T, S> swap) {
Class<T> type = Helpers.getLambdaArgType(swap, 0);
return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
swap.accept((T) inst, oref, oserv, nref, nserv));
}
- public <T> B sw(CbTypeComponentRefServiceRefService<T, S> swap) {
+ public <T> B swap(CbRefServiceRefServiceComponent<T, S> swap) {
Class<T> type = Helpers.getLambdaArgType(swap, 0);
return setComponentSwapCallbackRef(type, (inst, component, oref, oserv, nref, nserv) ->
- swap.accept((T) inst, component, oref, oserv, nref, nserv));
+ swap.accept((T) inst, oref, oserv, nref, nserv, component));
}
- public B swi(CbServiceService<S> swap) {
+ public B swap(InstanceCbServiceService<S> swap) {
return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oserv, nserv));
}
- public B swi(CbComponentServiceService<S> swap) {
- return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(component, oserv, nserv));
+ public B swap(InstanceCbServiceServiceComponent<S> swap) {
+ return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oserv, nserv, component));
}
- public B swi(CbRefServiceRefService<S> swap) {
+ public B swap(InstanceCbRefServiceRefService<S> swap) {
return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oref, oserv, nref, nserv));
}
- public B swi(CbComponentRefServiceRefService<S> swap) {
- return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(component, oref, oserv, nref, nserv));
+ public B swap(InstanceCbRefServiceRefServiceComponent<S> swap) {
+ return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oref, oserv, nref, nserv, component));
}
protected <I> B setComponentCallbackRef(Cb cbType, Class<I> type, MethodRef<I, S> ref) {
diff --git a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java
index 6892b1b..7a512a3 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ServiceDependencyBuilderImpl.java
@@ -27,6 +27,7 @@
super(service);
m_serviceIface = service;
m_component = component;
+ m_required = Helpers.isDependencyRequiredByDefault(component);
}
public ServiceDependencyBuilder<S> filter(String filter) {