felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1724525 - in /felix/sandbox/pderop/dependencymanager-lambda: org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/ org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ or...
Date Wed, 13 Jan 2016 23:17:12 GMT
Author: pderop
Date: Wed Jan 13 23:17:12 2016
New Revision: 1724525

URL: http://svn.apache.org/viewvc?rev=1724525&view=rev
Log:
Reduced API bloat in BundleDependencyBuilder interface.

Modified:
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/BundleDependencyTest.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/ModifiedBundleDependencyTest.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/BundleDependencyBuilder.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Cb.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/BundleDependencyBuilderImpl.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ComponentBuilderImpl.java
    felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ServiceCallbacksBuilderImpl.java

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/BundleDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/BundleDependencyTest.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/BundleDependencyTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/BundleDependencyTest.java
Wed Jan 13 23:17:12 2016
@@ -22,6 +22,7 @@ import static org.apache.felix.dm.builde
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.builder.lambda.Cb;
 import org.junit.Assert;
 import org.osgi.framework.Bundle;
 
@@ -59,8 +60,7 @@ public class BundleDependencyTest extend
         DependencyManager m = getDM();
         // create a service provider and consumer
         MyConsumer c = new MyConsumer();        
-        Component consumer = component(m, comp -> comp
-        		.impl(c).withBundle(bundle -> bundle.cb(MyConsumer::add, MyConsumer::remove)));
+        Component consumer = component(m, comp -> comp.impl(c).withBundle(bundle ->
bundle.cb(Cb.ADD, MyConsumer::add).cb(Cb.REM, MyConsumer::remove)));
         
         // check if at least one bundle was found
         c.check();
@@ -73,7 +73,7 @@ public class BundleDependencyTest extend
         Ensure e = new Ensure();
         String filter = "(Bundle-SymbolicName=" + BSN + ")";
         Component consumerWithFilter = component(m, comp -> comp.impl(new FilteredConsumer(e))
-            .withBundle(bundle-> bundle.filter(filter).cb(FilteredConsumer::add, FilteredConsumer::remove)));
+            .withBundle(bundle-> bundle.filter(filter).cb(Cb.ADD, FilteredConsumer::add).cb(Cb.REM,
FilteredConsumer::remove)));
         e.step(2);
         // remove the consumer again
         m.remove(consumerWithFilter);
@@ -100,7 +100,7 @@ public class BundleDependencyTest extend
         Ensure e = new Ensure();
         FilteredConsumerRequired impl = new FilteredConsumerRequired(e);
         Component consumerWithFilter = component(m, c -> c.impl(impl)
-            .withBundle(b -> b.filter("(Bundle-SymbolicName=" + BSN + ")").cb(impl::add,
impl::remove)));
+            .withBundle(b -> b.filter("(Bundle-SymbolicName=" + BSN + ")").cbi(Cb.ADD,
impl::add).cbi(Cb.REM, impl::remove)));
         e.waitForStep(1, 5000);
         // remove the consumer again
         m.remove(consumerWithFilter);
@@ -129,7 +129,7 @@ public class BundleDependencyTest extend
         Ensure e = new Ensure();
         FilteredConsumerRequiredWithComponentArg impl = new FilteredConsumerRequiredWithComponentArg(e);
         Component consumerWithFilter = component(m).impl(impl)
-        		.withBundle(b -> b.filter("(Bundle-SymbolicName=" + BSN + ")").cb(impl::add,
impl::remove)).build();
+        		.withBundle(b -> b.filter("(Bundle-SymbolicName=" + BSN + ")").cbi(Cb.ADD, impl::add).cbi(Cb.REM,
impl::remove)).build();
         // add a consumer with a filter
         m.add(consumerWithFilter);
         e.waitForStep(1, 5000);

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/ModifiedBundleDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/ModifiedBundleDependencyTest.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/ModifiedBundleDependencyTest.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/lambda/itest/ModifiedBundleDependencyTest.java
Wed Jan 13 23:17:12 2016
@@ -22,6 +22,7 @@ import static org.apache.felix.dm.builde
 
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.builder.lambda.Cb;
 import org.junit.Assert;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
@@ -139,7 +140,8 @@ public class ModifiedBundleDependencyTes
         BImpl impl = new BImpl(e);
         String filter = "(Bundle-SymbolicName=org.apache.felix.metatype)";
         int mask = Bundle.INSTALLED|Bundle.ACTIVE|Bundle.RESOLVED|Bundle.STARTING;
-        Component b = component(m).provides(B.class).impl(impl).withBundle(bundle -> bundle.filter(filter).mask(mask).cb(impl::add,
impl::change, impl::remove)).build();        	
+        Component b = component(m).provides(B.class).impl(impl)
+            .withBundle(bundle -> bundle.filter(filter).mask(mask).cbi(Cb.ADD, impl::add).cbi(Cb.CHG,
impl::change).cbi(Cb.REM, impl::remove)).build();        	
         
         Bundle dmtest = getBundle("org.apache.felix.metatype");
         try {

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/BundleDependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/BundleDependencyBuilder.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/BundleDependencyBuilder.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/BundleDependencyBuilder.java
Wed Jan 13 23:17:12 2016
@@ -16,37 +16,19 @@ import org.osgi.framework.Bundle;
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public interface BundleDependencyBuilder<T> extends DependencyBuilder<BundleDependency>
{
+public interface BundleDependencyBuilder extends DependencyBuilder<BundleDependency>
{
 
-    BundleDependencyBuilder<T> cbInst(Object callbackInstance);
+    BundleDependencyBuilder cbInst(Object callbackInstance);
     
-    BundleDependencyBuilder<T> cb(String add);
-    BundleDependencyBuilder<T> cb(String add, String remove);
-    BundleDependencyBuilder<T> cb(String add, String change, String remove);
+    BundleDependencyBuilder cb(String add);
+    BundleDependencyBuilder cb(String add, String remove);
+    BundleDependencyBuilder cb(String add, String change, String remove);
     
-    BundleDependencyBuilder<T> cb(CbTypeBundle<T> add);
-    BundleDependencyBuilder<T> cb(CbTypeBundle<T> add, CbTypeBundle<T>
remove);
-    BundleDependencyBuilder<T> cb(CbTypeBundle<T> add, CbTypeBundle<T>
change, CbTypeBundle<T> remove);
-
-    BundleDependencyBuilder<T> cb(CbTypeComponentBundle<T> add); 
-    BundleDependencyBuilder<T> cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T>
remove); 
-    BundleDependencyBuilder<T> cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T>
change, CbTypeComponentBundle<T> remove); 
-
-    BundleDependencyBuilder<T> cb(CbBundle add);
-    BundleDependencyBuilder<T> cb(CbBundle add, CbBundle remove);
-    BundleDependencyBuilder<T> cb(CbBundle add, CbBundle change, CbBundle remove);
-
-    BundleDependencyBuilder<T> cb(CbComponentBundle add);
-    BundleDependencyBuilder<T> cb(CbComponentBundle add, CbComponentBundle remove);
-    BundleDependencyBuilder<T> cb(CbComponentBundle add, CbComponentBundle change,
CbComponentBundle remove);
-
-    <U> BundleDependencyBuilder<T> compositeCb(CbTypeBundle<U> add);
-    <U> BundleDependencyBuilder<T> compositeCb(CbTypeBundle<U> add, CbTypeBundle<U>
remove);
-    <U> BundleDependencyBuilder<T> compositeCb(CbTypeBundle<U> add, CbTypeBundle<U>
change, CbTypeBundle<U> remove);
+    <T> BundleDependencyBuilder cb(Cb callbackType, CbTypeBundle<T> callback);
+    <T> BundleDependencyBuilder cb(Cb callbackType, CbTypeComponentBundle<T>
callback); 
     
-    <U> BundleDependencyBuilder<T> compositeCb(CbTypeComponentBundle<U>
add); 
-    <U> BundleDependencyBuilder<T> compositeCb(CbTypeComponentBundle<U>
add, CbTypeComponentBundle<U> remove); 
-    <U> BundleDependencyBuilder<T> compositeCb(CbTypeComponentBundle<U>
add, CbTypeComponentBundle<U> change, CbTypeComponentBundle<U> remove); 
+    BundleDependencyBuilder cbi(Cb callbackType, CbBundle callback);
+    BundleDependencyBuilder cbi(Cb callbackType, CbComponentBundle callback);
 
     /**
      * Enables auto configuration for this dependency. This means the component implementation
(composition) will be
@@ -55,7 +37,7 @@ public interface BundleDependencyBuilder
      * @param autoConfig <code>true</code> to enable auto configuration
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> autoConfig(boolean autoConfig);
+    public BundleDependencyBuilder autoConfig(boolean autoConfig);
 
     /**
      * Enables auto configuration for this dependency. This means the component implementation
(composition) will be
@@ -63,7 +45,7 @@ public interface BundleDependencyBuilder
      * 
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> autoConfig();
+    public BundleDependencyBuilder autoConfig();
 
     /**
      * Sets the dependency to be required.
@@ -71,7 +53,7 @@ public interface BundleDependencyBuilder
      * @param required <code>true</code> if this bundle dependency is required
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> required(boolean required);
+    public BundleDependencyBuilder required(boolean required);
 
     /**
      * Sets the dependency to be required.
@@ -79,7 +61,7 @@ public interface BundleDependencyBuilder
      * @param required <code>true</code> if this bundle dependency is required
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> required();
+    public BundleDependencyBuilder required();
 
     /**
      * Sets the bundle to depend on directly.
@@ -87,7 +69,7 @@ public interface BundleDependencyBuilder
      * @param bundle the bundle to depend on
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> bundle(Bundle bundle);
+    public BundleDependencyBuilder bundle(Bundle bundle);
 
     /**
      * Sets the filter condition to depend on. Filters are matched against the full manifest
of a bundle.
@@ -96,7 +78,7 @@ public interface BundleDependencyBuilder
      * @return the bundle dependency builder
      * @throws IllegalArgumentException if the filter is invalid
      */
-    public BundleDependencyBuilder<T> filter(String filter) throws IllegalArgumentException;
+    public BundleDependencyBuilder filter(String filter) throws IllegalArgumentException;
 
     /**
      * Sets the bundle state mask to depend on. The OSGi BundleTracker explains this mask
in more detail, but
@@ -105,7 +87,7 @@ public interface BundleDependencyBuilder
      * @param mask the mask to use
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> mask(int mask);
+    public BundleDependencyBuilder mask(int mask);
 
     /**
      * Sets property propagation. If set to <code>true</code> any bundle manifest
properties will be added
@@ -114,7 +96,7 @@ public interface BundleDependencyBuilder
      * @param propagate <code>true</code> to propagate the bundle manifest properties
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> propagate(boolean propagate);
+    public BundleDependencyBuilder propagate(boolean propagate);
     
     /**
      * Sets property propagation. any bundle manifest properties will be added
@@ -122,7 +104,7 @@ public interface BundleDependencyBuilder
      * 
      * @return the bundle dependency builder
      */
-    public BundleDependencyBuilder<T> propagate();
+    public BundleDependencyBuilder propagate();
     
     /**
      * Sets an Object instance and a callback method used to propagate some properties to
the provided service properties.
@@ -134,7 +116,7 @@ public interface BundleDependencyBuilder
      * @param method the method to invoke for retrieving the properties to be propagated
to the service properties.
      * @return this service dependency. builder
      */
-    public BundleDependencyBuilder<T> propagate(Object instance, String method);
+    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.
@@ -145,6 +127,6 @@ public interface BundleDependencyBuilder
      * @param instance the Object instance which is used to retrieve propagated service properties

      * @return this service dependency. builder
      */
-    public BundleDependencyBuilder<T> propagate(Supplier<Dictionary<?, ?>>
instance);
+    public BundleDependencyBuilder propagate(Supplier<Dictionary<?, ?>> instance);
     
 }

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Cb.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Cb.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Cb.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Cb.java
Wed Jan 13 23:17:12 2016
@@ -7,15 +7,32 @@ public enum Cb {
     /**
      * Service is added.
      */
-    ADD,
+    ADD {
+        @Override
+        public String getCallback() {
+            return "add";
+        }  
+    },
     
     /**
      * Service properties updated
      */
-    CHG, 
+    CHG {
+        @Override
+        public String getCallback() {
+            return "change";
+        }  
+    },
     
     /**
      * Service removed.
      */
-    REM
+    REM {
+        @Override
+        public String getCallback() {
+            return "remove";
+        }  
+    };
+   
+    public abstract String getCallback();
 }

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java
Wed Jan 13 23:17:12 2016
@@ -89,7 +89,7 @@ public interface ComponentBuilderBase<T,
      * @param consumer the lambda used to build the bundle dependency.
      * @return this builder.
      */
-    B withBundle(Consumer<BundleDependencyBuilder<T>> consumer);        
+    B withBundle(Consumer<BundleDependencyBuilder> consumer);        
 
     /**
      * TODO

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java
Wed Jan 13 23:17:12 2016
@@ -99,7 +99,7 @@ public class Functions {
     }
     
     @FunctionalInterface
-    public interface CbBundle {
+    public interface CbBundle extends SerializableLambda {
         void accept(Bundle bundle);
         
         default CbBundle andThen(CbBundle after) {

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java
Wed Jan 13 23:17:12 2016
@@ -137,7 +137,7 @@ public interface AdapterBase<T, B extend
         return (B) this;
     }
     
-    default B withBundle(Consumer<BundleDependencyBuilder<T>> consumer) {
+    default B withBundle(Consumer<BundleDependencyBuilder> consumer) {
         andThenBuild(compBuilder -> compBuilder.withBundle(consumer));
         return (B) this;
     }

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/BundleDependencyBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/BundleDependencyBuilderImpl.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/BundleDependencyBuilderImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/BundleDependencyBuilderImpl.java
Wed Jan 13 23:17:12 2016
@@ -13,6 +13,7 @@ import org.apache.felix.dm.BundleDepende
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.builder.lambda.BundleDependencyBuilder;
+import org.apache.felix.dm.builder.lambda.Cb;
 import org.apache.felix.dm.builder.lambda.Functions.CbBundle;
 import org.apache.felix.dm.builder.lambda.Functions.CbComponentBundle;
 import org.apache.felix.dm.builder.lambda.Functions.CbTypeBundle;
@@ -20,7 +21,7 @@ import org.apache.felix.dm.builder.lambd
 import org.osgi.framework.Bundle;
 
 @SuppressWarnings("unchecked")
-public class BundleDependencyBuilderImpl<T> implements BundleDependencyBuilder<T>
{
+public class BundleDependencyBuilderImpl implements BundleDependencyBuilder {
 	private String m_added;
 	private String m_changed;
 	private String m_removed;
@@ -38,24 +39,24 @@ public class BundleDependencyBuilderImpl
 	private final Component m_component;
     
 	/**
-	 * This interface (lambda) is called when we want to invoke a method reference. the lambda
is called with all necessary dependency 
-	 * informations.
-	 * 
-	 * When the lambda is called, it will invoke the proper callback on the given component
instance.
-	 *
-	 * @param <I> type of a component instance
-	 */
-	@FunctionalInterface
-    interface MethodRef<I> {
-    	public void accept(I instance, Component c, Bundle bundle);
-    }
-
-	/**
 	 * List of service (add/change/remove) callbacks (method references).
 	 */
 	private final Map<String, List<MethodRef<Object>>> m_refs = new HashMap<>();
 
 	/**
+     * This interface (lambda) is called when we want to invoke a method reference. the lambda
is called with all necessary dependency 
+     * informations.
+     * 
+     * When the lambda is called, it will invoke the proper callback on the given component
instance.
+     *
+     * @param <I> type of a component instance
+     */
+    @FunctionalInterface
+    interface MethodRef<I> {
+        public void accept(I instance, Component c, Bundle bundle);
+    }
+
+	/**
 	 * Class used to call a supplier that returns Propagated properties
 	 */
 	private class Propagate {
@@ -70,62 +71,62 @@ public class BundleDependencyBuilderImpl
     }
 
     @Override
-    public BundleDependencyBuilder<T> autoConfig(boolean autoConfig) {
+    public BundleDependencyBuilder autoConfig(boolean autoConfig) {
         m_autoConfig = autoConfig;
         m_autoConfigInvoked = true;
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> autoConfig() {
+    public BundleDependencyBuilder autoConfig() {
         autoConfig(true);
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> required(boolean required) {
+    public BundleDependencyBuilder required(boolean required) {
         m_required = required;
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> required() {
+    public BundleDependencyBuilder required() {
         required(true);
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> bundle(Bundle bundle) {
+    public BundleDependencyBuilder bundle(Bundle bundle) {
         m_bundle = bundle;
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> filter(String filter) throws IllegalArgumentException
{
+    public BundleDependencyBuilder filter(String filter) throws IllegalArgumentException
{
         m_filter = filter;
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> mask(int mask) {
+    public BundleDependencyBuilder mask(int mask) {
         m_stateMask = mask;
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> propagate(boolean propagate) {
+    public BundleDependencyBuilder propagate(boolean propagate) {
         m_propagate = propagate;
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> propagate() {
+    public BundleDependencyBuilder propagate() {
         propagate(true);
         return this;
     }
 
     @Override
-    public BundleDependencyBuilder<T> propagate(Object instance, String method) {
+    public BundleDependencyBuilder propagate(Object instance, String method) {
         if (m_propagateSupplier != null || m_propagate) throw new IllegalStateException("Propagate
callback already set.");
         Objects.nonNull(method);
         Objects.nonNull(instance);
@@ -135,20 +136,20 @@ public class BundleDependencyBuilderImpl
     }
 
     @Override
-    public BundleDependencyBuilder<T> propagate(Supplier<Dictionary<?, ?>>
instance) {
+    public BundleDependencyBuilder propagate(Supplier<Dictionary<?, ?>> instance)
{
         if (m_propagateInstance != null || m_propagate) throw new IllegalStateException("Propagate
callback already set.");
         m_propagateSupplier = instance;
         return this;
     }
     
     @Override
-    public BundleDependencyBuilder<T> cb(String add) {
+    public BundleDependencyBuilder cb(String add) {
         cb(add, null, null);
         return this;
     }
     
     @Override
-    public BundleDependencyBuilder<T> cb(String add, String remove) {
+    public BundleDependencyBuilder cb(String add, String remove) {
         cb(add, null, remove);
         return this;
     }
@@ -163,134 +164,31 @@ public class BundleDependencyBuilderImpl
     }
 
     @Override
-    public BundleDependencyBuilder<T> cbInst(Object instance) {
+    public BundleDependencyBuilder cbInst(Object instance) {
         m_instance = instance;
         return this;
     }    
 
     @Override
-    public BundleDependencyBuilder<T> cb(CbTypeBundle<T> add) {      
-        return cb(add, null, null);
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbTypeBundle<T> add, CbTypeBundle<T>
remove) {    
-        return cb(add, null, remove);
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbTypeBundle<T> add, CbTypeBundle<T>
change, CbTypeBundle<T> remove) {    
-        if (add != null) {
-            setComponentCallbackRef("add",
-                (inst, component, bundle) -> add.accept ((T) inst, bundle));
-        }
-        if (change != null) {
-            setComponentCallbackRef("change",
-                (inst, component, bundle) -> change.accept ((T) inst, bundle));
-        }
-        if (remove != null) {
-            setComponentCallbackRef("remove",
-                (inst, component, bundle) -> remove.accept ((T) inst, bundle));
-        }
-        return this;
+    public <T> BundleDependencyBuilder cb(Cb callbackType, CbTypeBundle<T> callback)
{      
+        return setComponentCallbackRef(callbackType.getCallback(), Helpers.getLambdaGenericType(callback,
0),
+            (inst, component, bundle) -> callback.accept ((T) inst, bundle));
     }
 
     @Override
-    public BundleDependencyBuilder<T> cb(CbTypeComponentBundle<T> add) {
-        return cb(add, null, null);
+    public <T> BundleDependencyBuilder cb(Cb callbackType, CbTypeComponentBundle<T>
callback) {
+        return setComponentCallbackRef(callbackType.getCallback(), Helpers.getLambdaGenericType(callback,
0),
+            (inst, component, bundle) -> callback.accept ((T) inst, component, bundle));
     }
     
     @Override
-    public BundleDependencyBuilder<T> cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T>
remove) {
-        return cb(add, null, remove);
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbTypeComponentBundle<T> add, CbTypeComponentBundle<T>
change, CbTypeComponentBundle<T> remove) {
-        if (add != null) {
-            setComponentCallbackRef("add", (inst, component, bundle) -> add.accept ((T)
inst, component, bundle));
-        }
-        if (change != null) {
-            setComponentCallbackRef("change", (inst, component, bundle) -> change.accept
((T) inst, component, bundle));
-        }
-        if (remove != null) {
-            setComponentCallbackRef("remove", (inst, component, bundle) -> remove.accept
((T) inst, component, bundle));
-        }
-        return this;            
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbBundle add) {
-        return cb (add, null, null);      
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbBundle add, CbBundle remove) {
-        return cb (add, null, remove);      
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbBundle add, CbBundle change, CbBundle remove)
{
-        if (add != null) setCallbackRef("add", (inst, component, bundle) -> add.accept(bundle));
-        if (change != null)  setCallbackRef("change", (inst, component, bundle) -> change.accept(bundle));
-        if (remove != null) setCallbackRef("remove", (inst, component, bundle) -> remove.accept(bundle));
-        return this;
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbComponentBundle add) {
-        return cb(add, null, null);      
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbComponentBundle add, CbComponentBundle remove)
{
-        return cb(add, null, remove);      
-    }
-
-    @Override
-    public BundleDependencyBuilder<T> cb(CbComponentBundle add, CbComponentBundle change,
CbComponentBundle remove) {
-        if (add != null) setCallbackRef("add", (inst, component, bundle) -> add.accept(component,
bundle));      
-        if (change != null) setCallbackRef("change", (inst, component, bundle) -> change.accept(component,
bundle));      
-        if (remove != null) setCallbackRef("remove", (inst, component, bundle) -> remove.accept(component,
bundle));      
-        return this;
-    }
-
-    @Override
-    public <U> BundleDependencyBuilder<T> compositeCb(CbTypeBundle<U> add)
{ 
-        return compositeCb(add, null, null);
-    }
-
-    @Override
-    public <U> BundleDependencyBuilder<T> compositeCb(CbTypeBundle<U> add,
CbTypeBundle<U> remove) {      
-        return compositeCb(add, null, remove);
-    }
-
-    @Override
-    public <U> BundleDependencyBuilder<T> compositeCb(CbTypeBundle<U> add,
CbTypeBundle<U> change, CbTypeBundle<U> remove) {
-        Class<U> type = Helpers.getLambdaGenericType(add, 0);
-        if (add != null) setCompositeCallbackRef("add", type, (inst, component, bundle) ->
add.accept ((U) inst, bundle));
-        if (change != null) setCompositeCallbackRef("change", type, (inst, component, bundle)
-> change.accept ((U) inst, bundle));
-        if (remove != null) setCompositeCallbackRef("remove", type, (inst, component, bundle)
-> remove.accept ((U) inst, bundle));
-        return this;
-  }
-
-    @Override
-    public <U> BundleDependencyBuilder<T> compositeCb(CbTypeComponentBundle<U>
add) {
-        return compositeCb(add, null, null);
+    public BundleDependencyBuilder cbi(Cb callbackType, CbBundle callback) {
+        return setInstanceCallbackRef(callbackType.getCallback(), (inst, component, bundle)
-> callback.accept(bundle));
     }
 
     @Override
-    public <U> BundleDependencyBuilder<T> compositeCb(CbTypeComponentBundle<U>
add, CbTypeComponentBundle<U> remove) {
-        return compositeCb(add, null, remove);
-    }
-
-    @Override
-    public <U> BundleDependencyBuilder<T> compositeCb(CbTypeComponentBundle<U>
add, CbTypeComponentBundle<U> change, CbTypeComponentBundle<U> remove) {
-        Class<U> type = Helpers.getLambdaGenericType(add, 0);
-        if (add != null) setCompositeCallbackRef("add", type, (inst, component, bundle) ->
add.accept ((U) inst, component, bundle));
-        if (change != null) setCompositeCallbackRef("change", type, (inst, component, bundle)
-> change.accept ((U) inst, component, bundle));
-        if (remove != null) setCompositeCallbackRef("remove", type, (inst, component, bundle)
-> remove.accept ((U) inst, component, bundle));
-        return this;
+    public BundleDependencyBuilder cbi(Cb callbackType, CbComponentBundle callback) {
+        return setInstanceCallbackRef(callbackType.getCallback(), (inst, component, bundle)
-> callback.accept(component, bundle));
     }
 
 	@Override
@@ -331,7 +229,7 @@ public class BundleDependencyBuilderImpl
         return dep;
 	}
 
-	private <U> BundleDependencyBuilder<T> setCallbackRef(String cb, MethodRef<U>
ref) {
+	private <T> BundleDependencyBuilder setInstanceCallbackRef(String cb, MethodRef<T>
ref) {
 		requiresNoStringCallbacks();
 		if (! m_autoConfigInvoked) m_autoConfig = false;
 		List<MethodRef<Object>> list = m_refs.computeIfAbsent(cb, l -> new ArrayList<>());
@@ -339,31 +237,20 @@ public class BundleDependencyBuilderImpl
 		return this;
 	}
 	
-	private BundleDependencyBuilder<T> setComponentCallbackRef(String cb, MethodRef<T>
ref) {
+	private <T> BundleDependencyBuilder setComponentCallbackRef(String cb, Class<T>
type, MethodRef<T> ref) {
 		requiresNoStringCallbacks();
 		if (! m_autoConfigInvoked) m_autoConfig = false;
 		List<MethodRef<Object>> list = m_refs.computeIfAbsent(cb, l -> new ArrayList<>());
 		list.add((instance, component, bundle) -> {
-            Object inst = component.getInstance();
-            ref.accept((T) inst, component, bundle);
-		});
-		return this;
-	}
-	
-    private <I> BundleDependencyBuilder<T> setCompositeCallbackRef(String cb,
Class<I> type, MethodRef<I> ref) {
-        requiresNoStringCallbacks();
-        if (! m_autoConfigInvoked) m_autoConfig = false;
-        List<MethodRef<Object>> list = m_refs.computeIfAbsent(cb, l -> new
ArrayList<>());
-        list.add((instance, component, bundle) -> {
             Stream.of(component.getInstances()).forEach(inst -> {
                 if (Helpers.getClass(inst).equals(type)) {
-                    ref.accept((I) inst, component, bundle);
+                    ref.accept((T) inst, component, bundle);
                 }
             });
-        });
-        return this;
-    }
-    
+		});
+		return this;
+	}
+	    
 	@SuppressWarnings("unused")
 	private Object createCallbackInstance() {
 		Object cb = null;

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ComponentBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ComponentBuilderImpl.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ComponentBuilderImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ComponentBuilderImpl.java
Wed Jan 13 23:17:12 2016
@@ -349,8 +349,8 @@ public class ComponentBuilderImpl<T> imp
     }
     
     @Override
-    public ComponentBuilderImpl<T> withBundle(Consumer<BundleDependencyBuilder<T>>
consumer) {
-    	BundleDependencyBuilder<T> dep = new BundleDependencyBuilderImpl<>(m_component);
+    public ComponentBuilderImpl<T> withBundle(Consumer<BundleDependencyBuilder>
consumer) {
+    	BundleDependencyBuilder dep = new BundleDependencyBuilderImpl(m_component);
         consumer.accept(dep);
         m_dependencyBuilders.add(dep);
         return this;

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ServiceCallbacksBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ServiceCallbacksBuilderImpl.java?rev=1724525&r1=1724524&r2=1724525&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ServiceCallbacksBuilderImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/ServiceCallbacksBuilderImpl.java
Wed Jan 13 23:17:12 2016
@@ -145,112 +145,112 @@ public abstract class ServiceCallbacksBu
 	}
 
     public <T> B cb(Cb cbType, CbTypeService<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, service));
     }
     
     public <T> B cb(Cb cbType, CbTypeServiceMap<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, service,
new SRefAsMap(ref)));
     }
 
     public <T> B cb(Cb cbType, CbTypeServiceDict<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, service,
new SRefAsDictionary(ref))); 
     }
     
     public <T> B cb(Cb cbType, CbTypeRef<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, ref));

     }
 
     public <T> B cb(Cb cbType, CbTypeRefService<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, ref,
service)); 
     }
 
     public <T> B cb(Cb cbType, CbTypeComponent<T> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, component));

     }
 
     public <T> B cb(Cb cbType, CbTypeComponentService<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, component,
service)); 
     }
 
     public <T> B cb(Cb cbType, CbTypeComponentServiceMap<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, component,
service, new SRefAsMap(ref))); 
     }
 
     public <T> B cb(Cb cbType, CbTypeComponentServiceDict<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, component,
service, new SRefAsDictionary(ref)));  
     }
 
     public <T> B cb(Cb cbType, CbTypeComponentRef<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, component,
ref));  
     }
 
     public <T> B cb(Cb cbType, CbTypeComponentRefService<T, S> callback) {
-        return setComponentCallbackRef(getCallback(cbType), Helpers.getLambdaGenericType(callback,
0), 
+        return setComponentCallbackRef(cbType.getCallback(), Helpers.getLambdaGenericType(callback,
0), 
             (instance, component, ref, service) -> callback.accept((T) instance, component,
ref, service));   
     }
 
     public B cbi(Cb cbType, CbService<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(service));   
     }
     
     public B cbi(Cb cbType, CbServiceMap<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(service, new SRefAsMap(ref)));
  
     }
 
     public B cbi(Cb cbType, CbServiceDict<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(service, new SRefAsDictionary(ref)));
  
     }
 
     public B cbi(Cb cbType, CbRef<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(ref));   
     }
 
     public B cbi(Cb cbType, CbRefService<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(ref, service));   
     }
 
     public B cbi(Cb cbType, CbComponent callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(component));   
     }
 
     public B cbi(Cb cbType, CbComponentService<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(component, service));
  
     }
 
     public B cbi(Cb cbType, CbComponentServiceMap<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(component, service,
new SRefAsMap(ref)));           
     }
 
     public B cbi(Cb cbType, CbComponentServiceDict<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(component, service,
new SRefAsDictionary(ref)));           
     }
 
     public B cbi(Cb cbType, CbComponentRef<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(component, ref)); 
         
     }
 
     public B cbi(Cb cbType, CbComponentRefService<S> callback) {
-        return setInstanceCallbackRef(getCallback(cbType), 
+        return setInstanceCallbackRef(cbType.getCallback(), 
             (instance, component, ref, service) -> callback.accept(component, ref, service));
          
     }
 
@@ -318,7 +318,7 @@ public abstract class ServiceCallbacksBu
             ref.accept((T) component.getInstance(), component, sref, service);
         });
         return (B) this;
-     }
+    }
 
     public <I> B setComponentSwapCallbackRef(Class<I> type, SwapMethodRef<I,
S> ref) {
        requiresNoCallbacks();
@@ -396,14 +396,4 @@ public abstract class ServiceCallbacksBu
 		   throw new IllegalStateException("can't mix method references and string callbacks.");
 	   }
     }   
-    
-    private String getCallback(Cb cbType) {
-        switch (cbType) {
-        case ADD: return "add";
-        case CHG: return "change";
-        case REM: return "remove";
-        default:
-            throw new IllegalArgumentException("Invalid CbType: " + cbType);
-        }
-    }
 }




Mime
View raw message