Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E708D18B6C for ; Tue, 12 Jan 2016 22:45:52 +0000 (UTC) Received: (qmail 56695 invoked by uid 500); 12 Jan 2016 22:45:52 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 56650 invoked by uid 500); 12 Jan 2016 22:45:52 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 56641 invoked by uid 99); 12 Jan 2016 22:45:52 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jan 2016 22:45:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 4310C1A0BF4 for ; Tue, 12 Jan 2016 22:45:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.246 X-Spam-Level: * X-Spam-Status: No, score=1.246 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id ad8O2oTg8wOS for ; Tue, 12 Jan 2016 22:45:40 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id F1C6A43B43 for ; Tue, 12 Jan 2016 22:45:39 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 64EACE1015 for ; Tue, 12 Jan 2016 22:45:39 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 297913A24A6 for ; Tue, 12 Jan 2016 22:45:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1724333 [4/7] - in /felix/sandbox/pderop/dependencymanager-lambda: ./ cnf/localrepo/ cnf/localrepo/org.apache.felix.dependencymanager/ org.apache.felix.dependencymanager.lambda.itest/ org.apache.felix.dependencymanager.lambda.itest/.settin... Date: Tue, 12 Jan 2016 22:45:38 -0000 To: commits@felix.apache.org From: pderop@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160112224539.297913A24A6@svn01-us-west.apache.org> Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/Activator.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/Activator.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/Activator.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/Activator.java Tue Jan 12 22:45:36 2016 @@ -19,35 +19,44 @@ package org.apache.felix.dependencymanager.lambda.samples.future; import static java.lang.System.out; +import static org.apache.felix.dm.builder.lambda.CB.ADD; + +import java.util.List; +import java.util.concurrent.CompletableFuture; import org.apache.felix.dm.builder.lambda.DependencyActivatorBase; import org.osgi.service.log.LogService; /** - * Defines two components: FelixSite which provides some informations about the Felix Web site, - * and Test, which depends in the FelixSite service. - * - * The FelixSite component will asynchronously download the Felix web page, and uses a "CompletableFuture" - * dependency, in order to block the activation of the FelixSite service, until the web page is downloaded and parsed. - * - * The download is done using some CompletableFuture asynchronous tasks. + * This examples show how to use the new "Future" dependency available from the dependencymanager-lambda library. + * The FelixLinksImpl component provides the list of available hrefs found from the Felix web site. + * The page is downloaded asynchronously using a CompletableFuture, and the component of the FelixLinksImpl + * will wait for the future to be completed before start. * * @author Felix Project Team */ public class Activator extends DependencyActivatorBase { + @Override public void init() throws Exception { out.println("type \"log info\" to see the logs emitted by this test."); - - // Define the FelixSiteInfo component that provides some informations about the Felix web site. + + // Creates a future that asynchronously download Felix web site. + String felix = "http://felix.apache.org/"; + CompletableFuture> futureLinks = CompletableFuture.supplyAsync(() -> FelixLinksImpl.download(felix)) + .thenApply(FelixLinksImpl::parseLinks); + + // Create the FelixLink service, it will be started once our previous future has completed. component(comp -> comp - .provides(SiteInfo.class) - .factory(() -> new SiteInfoImpl("http://felix.apache.org/")) - .withService(LogService.class, srv -> srv.onAdd(SiteInfoImpl::bind))); - - // Define the FelixSite component that depends on the FelixSiteInfo service + .impl(FelixLinksImpl.class) + .provides(FelixLinks.class) + .withService(LogService.class, srv -> srv.cb(ADD, FelixLinksImpl::bind)) + .withFuture(futureLinks, future -> future.cb(FelixLinksImpl::setLinks))); + + // Define a component that just displays the links found from the Felix web site. + // It depends on a log service and on the FelixLink service, which are both injected in class fields. component(comp -> comp - .impl(DisplaySite.class) - .withService(LogService.class).withService(SiteInfo.class)); + .impl(DisplayFelixLinks.class) + .withService(LogService.class, FelixLinks.class)); } } Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/DisplayFelixLinks.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/DisplayFelixLinks.java?rev=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/DisplayFelixLinks.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/DisplayFelixLinks.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,16 @@ +package org.apache.felix.dependencymanager.lambda.samples.future; + +import org.osgi.service.log.LogService; + +/** + * Displays all links found from Felix web site, using the FelixLinks service. + */ +public class DisplayFelixLinks { + volatile FelixLinks m_siteInfo; + volatile LogService m_log; + + void start() { + m_log.log(LogService.LOG_INFO, "DisplaySite.start(): links available from the Felix web site: " + m_siteInfo.getLinks()); + } + +} Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinks.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinks.java?rev=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinks.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinks.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,10 @@ +package org.apache.felix.dependencymanager.lambda.samples.future; + +import java.util.List; + +/** + * Service that displays all links found from the Felix web site. + */ +public interface FelixLinks { + List getLinks(); +} Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinksImpl.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinksImpl.java?rev=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinksImpl.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/future/FelixLinksImpl.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,63 @@ +package org.apache.felix.dependencymanager.lambda.samples.future; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.osgi.service.log.LogService; + +/** + * Provides all hrefs found from Felix web site. + */ +public class FelixLinksImpl implements FelixLinks { + private LogService m_log; + final static String HREF_PATTERN = "]*)\\s*>"; + List m_links; // web page hrefs (links). + + void bind(LogService log) { + m_log = log; + } + + // Called when our future has completed. + void setLinks(List links) { + m_links = links; + } + + // once our future has completed, our component is started. + void start() { + m_log.log(LogService.LOG_INFO, "Service starting: number of links found from Felix web site: " + m_links.size()); + } + + @Override + public List getLinks() { + return m_links; + } + + public static String download(String url) { + try (Scanner in = new Scanner(new URL(url).openStream())) { + StringBuilder builder = new StringBuilder(); + while (in.hasNextLine()) { + builder.append(in.nextLine()); + builder.append("\n"); + } + return builder.toString(); + } catch (IOException ex) { + RuntimeException rex = new RuntimeException(); + rex.initCause(ex); + throw rex; + } + } + + public static List parseLinks(String content) { + Pattern pattern = Pattern.compile(HREF_PATTERN, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(content); + List result = new ArrayList<>(); + while (matcher.find()) + result.add(matcher.group(1)); + return result; + } +} Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/hello/Activator.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/hello/Activator.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/hello/Activator.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/hello/Activator.java Tue Jan 12 22:45:36 2016 @@ -19,6 +19,7 @@ package org.apache.felix.dependencymanager.lambda.samples.hello; import static java.lang.System.out; +import static org.apache.felix.dm.builder.lambda.CB.ADD; import org.apache.felix.dm.builder.lambda.DependencyActivatorBase; import org.osgi.service.cm.ConfigurationAdmin; @@ -33,18 +34,19 @@ public class Activator extends Dependenc out.println("type \"log info\" to see the logs emitted by this test."); component(comp -> comp - .provides(ServiceProvider.class) - .onStart(ServiceProviderImpl::activate) - //.properties("foo", "bar", "gabu", "zo") // foo=bar, gabu=zo - .properties(foo -> "bar", gabu -> "zo") // property names are deduced from lambda parameter name .impl(ServiceProviderImpl.class) - .withService(LogService.class, srv -> srv.onAdd(ServiceProviderImpl::bind))); + .provides(ServiceProvider.class) + .properties(foo -> "bar", gabu -> "zo") // property names are deduced from lambda parameter names + .start(ServiceProviderImpl::activate) + .withService(LogService.class, srv -> srv.cb(ADD, ServiceProviderImpl::bind))); + // service can also be injected using reflection: + // .withService(LogService.class, srv -> srv.cb("bind"))); component(comp -> comp .impl(ServiceConsumer.class) .withService(LogService.class) .withService(ServiceProvider.class, srv -> srv.filter("(foo=bar)")) - .withConfiguration(conf -> conf.pid(ServiceConsumer.class).onUpdate(ServiceConsumer::updated))); + .withConfiguration(conf -> conf.pid(ServiceConsumer.class).cb(ServiceConsumer::updated))); component(comp -> comp.impl(Configurator.class).withService(ConfigurationAdmin.class)); } Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/Activator.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/Activator.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/Activator.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/Activator.java Tue Jan 12 22:45:36 2016 @@ -19,6 +19,7 @@ package org.apache.felix.dependencymanager.lambda.samples.rx.completable; import static java.lang.System.out; +import static org.apache.felix.dm.builder.lambda.CB.ADD; import org.apache.felix.dm.builder.lambda.DependencyActivatorBase; import org.osgi.service.log.LogService; @@ -40,14 +41,15 @@ public class Activator extends Dependenc out.println("type \"log info\" to see the logs emitted by this test."); // Define the FelixSiteInfo component that provides some informations about the Felix web site. + // (see the SiteInfoImpl::init method, which asynchronously download Felix). component(comp -> comp .provides(SiteInfo.class) .factory(() -> new SiteInfoImpl("http://felix.apache.org/")) - .withService(LogService.class, srv -> srv.onAdd(SiteInfoImpl::bind))); + .withService(LogService.class, srv -> srv.cb(ADD, SiteInfoImpl::bind))); // Define the FelixSite component that depends on the FelixSiteInfo service component(comp -> comp - .impl(DisplaySite.class) - .withService(LogService.class).withService(SiteInfo.class)); + .impl(DisplaySite.class) + .withService(LogService.class, SiteInfo.class)); } } Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/SiteInfoImpl.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/SiteInfoImpl.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/SiteInfoImpl.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/completable/SiteInfoImpl.java Tue Jan 12 22:45:36 2016 @@ -44,11 +44,8 @@ public class SiteInfoImpl implements Sit // that is used as a Dependency Manager "Future" dependency, in order to block the activation of // our component until the page has been downloaded and parsed. - Observable> links = downloadSite(m_url) - .map(this::getSiteLinks); - - component(c, comp -> comp - .withFuture(toFuture(links), futuredep -> futuredep.thenAccept(this::setLinks))); + Observable> links = downloadSite(m_url).map(this::getSiteLinks); + component(c, comp -> comp.withFuture(toFuture(links), futuredep -> futuredep.cb(this::setLinks))); } // Called when our future has completed. Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/observable/ObservableComponent.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/observable/ObservableComponent.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/observable/ObservableComponent.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dependencymanager/lambda/samples/rx/observable/ObservableComponent.java Tue Jan 12 22:45:36 2016 @@ -79,7 +79,7 @@ public class ObservableComponent { publisher.onSubscribe(EmptySubscription.INSTANCE); component(m_dm, builder -> builder .factory(() -> new DocumentViewer(title)) - .onStart(publisher::onNext)); + .start(publisher::onNext)); }); } } 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=1724333&r1=1724332&r2=1724333&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 Tue Jan 12 22:45:36 2016 @@ -4,220 +4,49 @@ import java.util.Dictionary; import java.util.function.Supplier; import org.apache.felix.dm.BundleDependency; -import org.apache.felix.dm.Component; -import org.apache.felix.dm.builder.lambda.Functions.Consumer; -import org.apache.felix.dm.builder.lambda.Functions.Consumer2; -import org.apache.felix.dm.builder.lambda.Functions.SerializableLambda; +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; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentBundle; import org.osgi.framework.Bundle; /** - * Defines a dependency on a bundle. + * Builder for a DependencyManager BundleDependency. + * TODO: add javadocs * * @author Felix Project Team */ -public interface BundleDependencyBuilder extends DependencyBuilder { - /** - * Defines a method reference on a component class method. The callback method takes Bundle parameter. - * @param the type of the component instance on which this method reference is applied - */ - @FunctionalInterface - public interface InstanceBundle extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the component instance on which the callback has to be called - * @param bundle to inject - */ - void call(I instance, Bundle bundle); - } - - /** - * Defines a method reference on a component instance. The callback method takes Component and a Bundle in parameters. - * @param the type of the component instance on which this method reference is applied - */ - @FunctionalInterface - public interface InstanceComponentBundle extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the component instance on which the callback has to be called - * @param component the component on which this dependency has been added. - * @param bundle the bundle to inject. - */ - void call(I instance, Component component, Bundle bundle); - } - - /** - * Sets the add callbacks for this dependency. The callback can be used as hooks whenever a dependency is added. - * When you specify callbacks, 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 added - * @return the bundle dependency - */ - public BundleDependencyBuilder onAdd(String callback); - - /** - * Sets the change callbacks for this dependency. The callback can be used as hooks whenever a dependency is changed. - * When you specify callbacks, 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 changed - * @return the bundle dependency - */ - public BundleDependencyBuilder onChange(String callback); +public interface BundleDependencyBuilder extends DependencyBuilder { - /** - * Sets the remove callbacks for this dependency. The callback can be used as hooks whenever a dependency is removed. - * When you specify callbacks, 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 - * @return the bundle dependency - */ - public BundleDependencyBuilder onRemove(String callback); - - /** - * Sets the callbacks for this dependency. These callbacks can be used as hooks whenever a dependency is added or - * removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a bundle was added - * @param removed the method to call when a bundle was removed - * @return the bundle dependency - */ - public BundleDependencyBuilder callbacks(String added, String removed); + BundleDependencyBuilder cbInst(Object callbackInstance); - /** - * Sets the callbacks for this dependency. These callbacks can be used as hooks whenever a dependency is added, changed or - * removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a bundle was added - * @param changed the method to call when a bundle was changed - * @param removed the method to call when a bundle was removed - * @return the bundle dependency - */ - public BundleDependencyBuilder callbacks(String added, String changed, String removed); - - /** - * Sets the callbacks for this dependency. These callbacks can be used as hooks whenever a dependency is added, changed or - * removed. They are called on the instance you provide. When you specify callbacks, the auto configuration feature is - * automatically turned off, because we're assuming you don't need it in this case. - * - * @param instance the instance to call the callbacks on - * @param added the method to call when a bundle was added - * @param changed the method to call when a bundle was changed - * @param removed the method to call when a bundle was removed - * @return the bundle dependency builder - */ - public BundleDependencyBuilder callbacks(Object instance, String added, String changed, String removed); - - /** - * Sets the add callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is added. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a bundle was added - * @return the bundle dependency - */ - public BundleDependencyBuilder onAdd(Consumer add); - - /** - * Sets the add callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is added. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a bundle was added - * @return the bundle dependency - */ - public BundleDependencyBuilder onAdd(InstanceBundle add); - - /** - * Sets the add callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is added. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a bundle was added. the callback is invoked with the component on which this dependency is added, and the added bundle. - * @return the bundle dependency - */ - public BundleDependencyBuilder onAdd(Consumer2 add); - - /** - * Sets the add callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is added. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call on one of the component instances when a bundle was added. the callback is invoked with the component on which this dependency is added, and the added bundle. - * @return the bundle dependency - */ - public BundleDependencyBuilder onAdd(InstanceComponentBundle add); - - /** - * Sets the change callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is changed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a bundle was changed - * @return the bundle dependency - */ - public BundleDependencyBuilder onChange(Consumer add); - - /** - * Sets the changed callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is changed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param change the method to call when a bundle was changed - * @return the bundle dependency - */ - public BundleDependencyBuilder onChange(InstanceBundle change); - - /** - * Sets the changed callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is changed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param change the method to call when a bundle was changed. the callback is invoked with the component on which this dependency is added, and the added bundle. - * @return the bundle dependency - */ - public BundleDependencyBuilder onChange(Consumer2 change); - - /** - * Sets the changed callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is changed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param change the method to call on one of the component instances when a bundle was changed. the callback is invoked with the component on which this dependency is added, and the added bundle. - * @return the bundle dependency - */ - public BundleDependencyBuilder onChange(InstanceComponentBundle change); + BundleDependencyBuilder cb(String add); + BundleDependencyBuilder cb(String add, String remove); + BundleDependencyBuilder cb(String add, String change, String remove); + + BundleDependencyBuilder cb(CbTypeBundle add); + BundleDependencyBuilder cb(CbTypeBundle add, CbTypeBundle remove); + BundleDependencyBuilder cb(CbTypeBundle add, CbTypeBundle change, CbTypeBundle remove); - /** - * Sets the remove callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param remove the method to call when a bundle was remove - * @return the bundle dependency - */ - public BundleDependencyBuilder onRemove(Consumer remove); + BundleDependencyBuilder cb(CbTypeComponentBundle add); + BundleDependencyBuilder cb(CbTypeComponentBundle add, CbTypeComponentBundle remove); + BundleDependencyBuilder cb(CbTypeComponentBundle add, CbTypeComponentBundle change, CbTypeComponentBundle remove); - /** - * Sets the remove callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param remove the method to call when a bundle was removed - * @return the bundle dependency - */ - public BundleDependencyBuilder onRemove(InstanceBundle remove); + BundleDependencyBuilder cb(CbBundle add); + BundleDependencyBuilder cb(CbBundle add, CbBundle remove); + BundleDependencyBuilder cb(CbBundle add, CbBundle change, CbBundle remove); - /** - * Sets the remove callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is remove. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param removed the method to call when a bundle was removed. the callback is invoked with the component on which this dependency is removed, and the added bundle. - * @return the bundle dependency - */ - public BundleDependencyBuilder onRemove(Consumer2 remove); + BundleDependencyBuilder cb(CbComponentBundle add); + BundleDependencyBuilder cb(CbComponentBundle add, CbComponentBundle remove); + BundleDependencyBuilder cb(CbComponentBundle add, CbComponentBundle change, CbComponentBundle remove); - /** - * Sets the remove callbacks instance for this dependency. These callbacks can be used as hooks whenever a dependency is removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param remove the method to call on one of the component instances when a bundle was removed. the callback is invoked with the component on which this dependency is added, and the added bundle. - * @return the bundle dependency - */ - public BundleDependencyBuilder onRemove(InstanceComponentBundle remove); + BundleDependencyBuilder compositeCb(CbTypeBundle add); + BundleDependencyBuilder compositeCb(CbTypeBundle add, CbTypeBundle remove); + BundleDependencyBuilder compositeCb(CbTypeBundle add, CbTypeBundle change, CbTypeBundle remove); + + BundleDependencyBuilder compositeCb(CbTypeComponentBundle add); + BundleDependencyBuilder compositeCb(CbTypeComponentBundle add, CbTypeComponentBundle remove); + BundleDependencyBuilder compositeCb(CbTypeComponentBundle add, CbTypeComponentBundle change, CbTypeComponentBundle remove); /** * Enables auto configuration for this dependency. This means the component implementation (composition) will be @@ -226,7 +55,7 @@ public interface BundleDependencyBuilder * @param autoConfig true to enable auto configuration * @return the bundle dependency builder */ - public BundleDependencyBuilder autoConfig(boolean autoConfig); + public BundleDependencyBuilder autoConfig(boolean autoConfig); /** * Enables auto configuration for this dependency. This means the component implementation (composition) will be @@ -234,7 +63,7 @@ public interface BundleDependencyBuilder * * @return the bundle dependency builder */ - public BundleDependencyBuilder autoConfig(); + public BundleDependencyBuilder autoConfig(); /** * Sets the dependency to be required. @@ -242,7 +71,7 @@ public interface BundleDependencyBuilder * @param required true if this bundle dependency is required * @return the bundle dependency builder */ - public BundleDependencyBuilder required(boolean required); + public BundleDependencyBuilder required(boolean required); /** * Sets the dependency to be required. @@ -250,7 +79,7 @@ public interface BundleDependencyBuilder * @param required true if this bundle dependency is required * @return the bundle dependency builder */ - public BundleDependencyBuilder required(); + public BundleDependencyBuilder required(); /** * Sets the bundle to depend on directly. @@ -258,7 +87,7 @@ public interface BundleDependencyBuilder * @param bundle the bundle to depend on * @return the bundle dependency builder */ - public BundleDependencyBuilder 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. @@ -267,7 +96,7 @@ public interface BundleDependencyBuilder * @return the bundle dependency builder * @throws IllegalArgumentException if the filter is invalid */ - public BundleDependencyBuilder 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 @@ -276,7 +105,7 @@ public interface BundleDependencyBuilder * @param mask the mask to use * @return the bundle dependency builder */ - public BundleDependencyBuilder mask(int mask); + public BundleDependencyBuilder mask(int mask); /** * Sets property propagation. If set to true any bundle manifest properties will be added @@ -285,7 +114,7 @@ public interface BundleDependencyBuilder * @param propagate true to propagate the bundle manifest properties * @return the bundle dependency builder */ - public BundleDependencyBuilder propagate(boolean propagate); + public BundleDependencyBuilder propagate(boolean propagate); /** * Sets property propagation. any bundle manifest properties will be added @@ -293,7 +122,7 @@ public interface BundleDependencyBuilder * * @return the bundle dependency builder */ - public BundleDependencyBuilder propagate(); + public BundleDependencyBuilder propagate(); /** * Sets an Object instance and a callback method used to propagate some properties to the provided service properties. @@ -305,7 +134,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 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. @@ -316,5 +145,6 @@ public interface BundleDependencyBuilder * @param instance the Object instance which is used to retrieve propagated service properties * @return this service dependency. builder */ - public BundleDependencyBuilder propagate(Supplier> instance); + public BundleDependencyBuilder propagate(Supplier> instance); + } Added: 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=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/CB.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/CB.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,21 @@ +package org.apache.felix.dm.builder.lambda; + +/** + * Defines various types of dependency callbacks. + */ +public enum CB { + /** + * Service is added. + */ + ADD, + + /** + * Service properties updated + */ + CHG, + + /** + * Service removed. + */ + REM +} Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilder.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilder.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilder.java Tue Jan 12 22:45:36 2016 @@ -1,14 +1,8 @@ package org.apache.felix.dm.builder.lambda; -import java.util.Dictionary; -import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.function.Supplier; -import org.apache.felix.dm.Component; -import org.apache.felix.dm.builder.lambda.Functions.Consumer; -import org.apache.felix.dm.builder.lambda.Functions.FluentProperties; - /** * Builds a DependencyManager Component using java8 constructs. This interface provides builder methods used to configure general Component * parameters, like:

@@ -28,10 +22,10 @@ import org.apache.felix.dm.builder.lambd * public class Activator extends DependencyActivatorBase { * public void init() throws Exception { * component(comp -> comp - * .provides(Service.class) * .factory(ServiceImplFactory::new, ServiceImplFactory::create) + * .provides(Service.class) * .withService(LogService.class, srv -> srv.required().onAdd(ServiceImpl::set)) - * .onStart(ServiceImpl::activate)); + * .start(ServiceImpl::activate)); * } * } * } @@ -41,29 +35,27 @@ import org.apache.felix.dm.builder.lambd * * TODO: add support for reflection for lifecycle callbacks (like in Dependency Manager). */ -public interface ComponentBuilder> { +public interface ComponentBuilder extends ComponentBuilderBase> { /** - * Configures the services registered by this component in the OSGgi registry - * @param ifaces the OSGi service(s) components. + * Configures the component implementation. Can be a class name, or a component implementation object. + * @param impl the component implementation (a class, or an Object). * @return this builder */ - B provides(Class ... ifaces); + ComponentBuilder impl(U impl); /** - * Configures the component implementation. Can be a classname, or a component implementation object. - * @param impl the component implementation (a class, or an Object). - * @return this builder + * TODO */ - B impl(Object impl); - + ComponentBuilder impl(Class implClass); + /** - * Configures a factory that can be used to create this component implemention. + * Configures a factory that can be used to create this component implementation. * Example: "factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())". * - * @param create the factory used to create the component implemenation. + * @param create the factory used to create the component implementation. * @return this builder */ - B factory(Supplier create); + ComponentBuilder factory(Supplier create); /** * Configures a factory used to create this component implementation using a Factory object and a method in the Factory object. @@ -75,8 +67,8 @@ public interface ComponentBuilder B factory(Supplier factory, Function create); - + ComponentBuilder factory(Supplier factory, Function 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. @@ -91,8 +83,8 @@ public interface ComponentBuilder B factory(Supplier factory, Supplier getComposition); - + ComponentBuilder factory(Supplier factory, Supplier getComposition); + /** * Configures a factory that also returns a composition of objects for this component implemenation. * @@ -108,221 +100,5 @@ public interface ComponentBuilder B factory(Supplier factory, Function create, Function getComposition); - - /** - * Sets the component's service properties - * @param properties the component's service properties - * @return this builder - */ - B properties(Dictionary properties); - - /** - * Sets the components's service properties using varargs. The number of parameters must be even, representing a list of pair property key-value. - * @param properties a varargs representing a list of key-value pairs. - * - * Example: properties("param1", "value1", "service.ranking", 3) - * @return this builder - */ - B properties(String name, Object value, Object ... rest); - - /** - * Sets the components's service properties using List of lamda properties. - * When you use this method, you must compile your source code using the "-parameters" option, and the "arg0" parameter - * name is now allowed. - * - * Example: properties(param1 -> "value1, param2 -> 2); - * @return this builder - */ - B properties(FluentProperties ... properties); - - /** - * Adds a required/autoconfig service dependency. - * @param service the dependency that is required and that will be injected in any field with the same dependency type. - * @return this builder - */ - B withService(Class service); - - /** - * Adds a service dependency. - * @param service the service - * @param consumer the lambda for building the service dependency - * @return this builder. - */ - B withService(Class service, Consumer> consumer); - - /** - * Adds a configuration dependency. - * @param consumer the lambda used to build the configuration dependency. - * @return this builder. - */ - B withConfiguration(Consumer consumer); - - /** - * Adds a bundle dependency. - * @param consumer the lambda used to build the bundle dependency. - * @return this builder. - */ - B withBundle(Consumer consumer); - - /** - * TODO - * @param future - * @return - */ - B withFuture(CompletableFuture future, Consumer> consumer); - - /** - * TODO comment - * - * @param callback - * @return - */ - B onInit(Runnable callback); - - /** - * Sets a reference on an instance method that is called when the component is initialized. - * - * Example: onInit(instance::init) - * - * @param callback a callback that will be called when the component is initialized - * @return this builder - */ - B onInit(Functions.Consumer callback); - - /** - * Sets a reference on a component implementation method that is called when the component is initialized. - * - * Example: onInit(MyComponentImpl::activate) - * - * @param callback a method reference called when the component is started - * @return this builder - */ - B onInit(Functions.Consumer2 callback); - - /** - * TODO comment - * - * @param callback - * @return - */ - B onStart(Runnable callback); - - /** - * Sets a reference on an instance method that is called when the component is started. - * - * Example: onStart(instance::start) - * - * @param callback a callback that will be called when the component is started - * @return this builder - */ - B onStart(Functions.Consumer callback); - - /** - * Sets a reference on a component implementation method that is called when the component is started. - * - * Example: onStart(MyComponentImpl::started) - * - * @param callback a method reference called when the component is started - * @return this builder - */ - B onStart(Functions.Consumer2 callback); - - /** - * TODO comment - * - * @param callback - * @return - */ - B onStop(Runnable callback); - - /** - * Sets a reference on an instance method that is called when the component is stopped. - * - * Example: onStop(instance::stop) - * - * @param callback a callback that will be called when the component is stopped - * @return this builder - */ - B onStop(Functions.Consumer callback); - - /** - * Sets a reference on a component implementation method that is called when the component is started. - * - * Example: onStart(MyComponentImpl::started) - * - * @param callback a method reference called when the component is started - * @return this builder - */ - B onStop(Functions.Consumer2 callback); - - /** - * TODO comment - * - * @param callback - * @return - */ - B onDestroy(Runnable callback); - - /** - * Sets a reference on an instance method that is called when the component is destroyed. - * - * Example: onDestroy(instance::destroy) - * - * @param callback a callback that will be called when the component is destroyed - * @return this builder - */ - B onDestroy(Functions.Consumer callback); - - /** - * Sets a reference on a component implementation method that is called when the component is destroyed. - * - * Example: onDestroy(MyComponentImpl::destroy) - * - * @param callback a method reference called when the component is destroyed - * @return this builder - */ - B onDestroy(Functions.Consumer2 callback); - - /** - * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in any field having the same OSGi object type. - * @param clazz the OSGi object type (BundleContext, Component, DependencyManager). - * @param autoConfig true if the OSGi object has to be injected, false if not - * @return this builder - */ - B autoInject(Class clazz, boolean autoConfig); - - /** - * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in a given field. - * @param clazz the OSGi object type (BundleContext, Component, DependencyManager). - * @param field the field that will be injected with the OSGI object - * @return this builder - */ - B autoInject(Class clazz, String field); - - /** - * Activates debug mode - * @param label the debug label - * @return this builder - */ - B debug(String label); - - /** - * Automatically adds this component to its DependencyManager object - * @param autoAdd true for automatically adding this component to the DependencyManager object, false if not - * @return this builder - */ - B autoAdd(boolean autoAdd); - - /** - * Is this component automatically added to its DependencyManager object ? - * @return this builder - */ - boolean autoAdd(); - - /** - * Builds the real DependencyManager Component from this Component. - * @return the real DependencyManager Component. - */ - Component build(); + ComponentBuilder factory(Supplier factory, Function create, Function getComposition); } Added: 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=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ComponentBuilderBase.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,164 @@ +package org.apache.felix.dm.builder.lambda; + +import java.util.Dictionary; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.builder.lambda.Functions.CbComponent; +import org.apache.felix.dm.builder.lambda.Functions.FluentProperties; + +/** + * Base class for all kinds of component builders. + * + * @param the type of the component implementation class + * @param the builder that extends this class. + */ +public interface ComponentBuilderBase> { + /** + * Configures the services registered by this component in the OSGgi registry + * @param ifaces the OSGi service(s) components. + * @return this builder + */ + B provides(Class ... ifaces); + + /** + * Configures the services registered by this component in the OSGgi registry + * @param ifaces the OSGi service(s) components. + * @return this builder + */ + B provides(String ... ifaces); + + /** + * Sets the component's service properties + * @param properties the component's service properties + * @return this builder + */ + B properties(Dictionary properties); + + /** + * Sets the components's service properties using varargs. The number of parameters must be even, representing a list of pair property key-value. + * @param properties a varargs representing a list of key-value pairs. + * + * Example: properties("param1", "value1", "service.ranking", 3) + * @return this builder + */ + B properties(String name, Object value, Object ... rest); + + /** + * Sets the components's service properties using List of lamda properties. + * When you use this method, you must compile your source code using the "-parameters" option, and the "arg0" parameter + * name is now allowed. + * + * Example: properties(param1 -> "value1, param2 -> 2); + * @return this builder + */ + B properties(FluentProperties ... properties); + + /** + * Adds a required/autoconfig service dependency. + * @param service the dependency that is required and that will be injected in any field with the same dependency type. + * @return this builder + */ + B withService(Class service, Class ... services); + + /** + * Adds a service dependency. + * @param service the service + * @param consumer the lambda for building the service dependency + * @return this builder. + */ + B withService(Class service, Consumer> consumer); + + /** + * Adds a configuration dependency. + * @param consumer the lambda used to build the configuration dependency. + * @return this builder. + */ + B withConfiguration(Consumer> consumer); + + /** + * Adds a bundle dependency. + * @param consumer the lambda used to build the bundle dependency. + * @return this builder. + */ + B withBundle(Consumer> consumer); + + /** + * TODO + * @param future + * @return + */ + B withFuture(CompletableFuture future, Consumer> consumer); + + B init(Consumer callback); + B init(BiConsumer callback); + B init(Class type, Consumer callback); + B init(Class type, BiConsumer callback); + B init(Runnable callback); + B init(CbComponent callback); + + B start(Consumer callback); + B start(BiConsumer callback); + B start(Class type, Consumer callback); + B start(Class type, BiConsumer callback); + B start(Runnable callback); + B start(CbComponent callback); + + B stop(Consumer callback); + B stop(BiConsumer callback); + B stop(Class type, Consumer callback); + B stop(Class type, BiConsumer callback); + B stop(Runnable callback); + B stop(CbComponent callback); + + B destroy(Consumer callback); + B destroy(BiConsumer callback); + B destroy(Class type, Consumer callback); + B destroy(Class type, BiConsumer callback); + B destroy(Runnable callback); + B destroy(CbComponent callback); + + /** + * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in any field having the same OSGi object type. + * @param clazz the OSGi object type (BundleContext, Component, DependencyManager). + * @param autoConfig true if the OSGi object has to be injected, false if not + * @return this builder + */ + B autoInject(Class clazz, boolean autoConfig); + + /** + * Configures OSGi object (BundleContext, Component, etc ...) that will be injected in a given field. + * @param clazz the OSGi object type (BundleContext, Component, DependencyManager). + * @param field the field that will be injected with the OSGI object + * @return this builder + */ + B autoInject(Class clazz, String field); + + /** + * Activates debug mode + * @param label the debug label + * @return this builder + */ + B debug(String label); + + /** + * Automatically adds this component to its DependencyManager object + * @param autoAdd true for automatically adding this component to the DependencyManager object, false if not + * @return this builder + */ + B autoAdd(boolean autoAdd); + + /** + * Is this component automatically added to its DependencyManager object ? + * @return this builder + */ + B autoAdd(); + + /** + * Builds the real DependencyManager Component from this Component. + * @return the real DependencyManager Component. + */ + Component build(); +} Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ConfigurationDependencyBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ConfigurationDependencyBuilder.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ConfigurationDependencyBuilder.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ConfigurationDependencyBuilder.java Tue Jan 12 22:45:36 2016 @@ -1,10 +1,10 @@ package org.apache.felix.dm.builder.lambda; -import static org.apache.felix.dm.builder.lambda.Functions.*; - -import java.util.Dictionary; - import org.apache.felix.dm.ConfigurationDependency; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentDictionary; +import org.apache.felix.dm.builder.lambda.Functions.CbDictionary; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentDictionary; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeDictionary; /** * Defines a builder for DependencyManager Configuration Dependency. @@ -22,11 +22,20 @@ import org.apache.felix.dm.Configuration * * TODO: javadoc */ -public interface ConfigurationDependencyBuilder extends DependencyBuilder { - ConfigurationDependencyBuilder pid(String pid); - ConfigurationDependencyBuilder pid(Class pidClass); - ConfigurationDependencyBuilder propagate(); - ConfigurationDependencyBuilder propagate(boolean propagate); - ConfigurationDependencyBuilder onUpdate(Consumer2> updated); - ConfigurationDependencyBuilder onUpdate(Consumer> updated); +public interface ConfigurationDependencyBuilder extends DependencyBuilder { + + ConfigurationDependencyBuilder pid(String pid); + ConfigurationDependencyBuilder pid(Class pidClass); + ConfigurationDependencyBuilder propagate(); + ConfigurationDependencyBuilder propagate(boolean propagate); + + ConfigurationDependencyBuilder cb(String updateMethod); + ConfigurationDependencyBuilder cb(Object callbackInstance, String updateMethod); + + ConfigurationDependencyBuilder cb(CbTypeDictionary callback); + ConfigurationDependencyBuilder cb(CbDictionary updated); + ConfigurationDependencyBuilder cb(CbComponentDictionary updated); + + ConfigurationDependencyBuilder compositeCb(CbTypeDictionary callback); + ConfigurationDependencyBuilder compositeCb(CbTypeComponentDictionary callback); } Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/DependencyActivatorBase.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/DependencyActivatorBase.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/DependencyActivatorBase.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/DependencyActivatorBase.java Tue Jan 12 22:45:36 2016 @@ -4,10 +4,10 @@ import java.util.function.Consumer; import org.apache.felix.dm.Component; import org.apache.felix.dm.DependencyManager; -import org.apache.felix.dm.builder.lambda.impl.AdapterBuilderImpl; -import org.apache.felix.dm.builder.lambda.impl.AspectBuilderImpl; import org.apache.felix.dm.builder.lambda.impl.ComponentBuilderImpl; import org.apache.felix.dm.builder.lambda.impl.FactoryPidAdapterBuilderImpl; +import org.apache.felix.dm.builder.lambda.impl.ServiceAdapterBuilderImpl; +import org.apache.felix.dm.builder.lambda.impl.ServiceAspectBuilderImpl; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -79,7 +79,7 @@ public abstract class DependencyActivato * The component is auto-added to the DependencyManager, unless the lambda calls the ComponentBuilder.autoAdd(false) method. * @return a newly built DM component. */ - protected Component component(Consumer>> consumer) { + protected Component component(Consumer> consumer) { return component(m_manager, consumer); } @@ -89,7 +89,7 @@ public abstract class DependencyActivato * The component is auto-added to the DependencyManager, unless the lambda calls the AspectBuilder.autoAdd(false) method. * @return a newly built DM component. */ - protected Component aspect(Class aspect, Consumer> consumer) { + protected Component aspect(Class aspect, Consumer> consumer) { return aspect(m_manager, aspect, consumer); } @@ -99,7 +99,7 @@ public abstract class DependencyActivato * The component is auto-added to the DependencyManager, unless the lambda calls the AdapterBuilder.autoAdd(false) method. * @return a newly built DM component. */ - protected Component adapter(Class adaptee, Consumer> consumer) { + protected Component adapter(Class adaptee, Consumer> consumer) { return adapter(m_manager, adaptee, consumer); } @@ -109,7 +109,7 @@ public abstract class DependencyActivato * The component is auto-added to the DependencyManager, unless the lambda calls the FactoryPidAdapterBuilder.autoAdd(false) method. * @return a newly built DM component. */ - protected Component factoryPidAdapter(Consumer consumer) { + protected Component factoryPidAdapter(Consumer> consumer) { return factoryPidAdapter(m_manager, consumer); } @@ -123,11 +123,11 @@ public abstract class DependencyActivato * * @return the built DM component. */ - public static Component component(DependencyManager dm, Consumer>> consumer) { - ComponentBuilder componentBuilder = new ComponentBuilderImpl(dm); + public static Component component(DependencyManager dm, Consumer> consumer) { + ComponentBuilder componentBuilder = new ComponentBuilderImpl<>(dm); consumer.accept(componentBuilder); Component comp = componentBuilder.build(); - if (componentBuilder.autoAdd()) { + if (((ComponentBuilderImpl) componentBuilder).isAutoAdd()) { dm.add(comp); } return comp; @@ -138,8 +138,8 @@ public abstract class DependencyActivato * @param comp an existing DM component * @param consumer the lambda that will be used to update the component */ - public static void component(Component comp, Consumer> consumer) { - ComponentBuilder componentBuilder = new ComponentBuilderImpl(comp, true /* update component */); + public static void component(Component comp, Consumer> consumer) { + ComponentBuilder componentBuilder = new ComponentBuilderImpl<>(comp, true /* update component */); consumer.accept(componentBuilder); componentBuilder.build(); } @@ -152,11 +152,11 @@ public abstract class DependencyActivato * @return a new DM aspect component. The aspect component is auto-added into the dm object, unless the lambda calls * the AspectBuilder.autoAdd(false) method. */ - public static Component aspect(DependencyManager dm, Class aspect, Consumer> consumer) { - AspectBuilder aspectBuilder = new AspectBuilderImpl<>(dm, aspect); + public static Component aspect(DependencyManager dm, Class aspect, Consumer> consumer) { + ServiceAspectBuilderImpl aspectBuilder = new ServiceAspectBuilderImpl<>(dm, aspect); consumer.accept(aspectBuilder); Component comp = aspectBuilder.build(); - if (aspectBuilder.autoAdd()) { + if (aspectBuilder.isAutoAdd()) { dm.add(comp); } return comp; @@ -170,11 +170,11 @@ public abstract class DependencyActivato * @return a new DM adapter component. The adapter component is auto-added into the dm object, unless the lambda calls * the AspectBuilder.autoAdd(false) method is called. */ - public static Component adapter(DependencyManager dm, Class adaptee, Consumer> consumer) { - AdapterBuilder adapterBuilder = new AdapterBuilderImpl<>(dm, adaptee); + public static Component adapter(DependencyManager dm, Class adaptee, Consumer> consumer) { + ServiceAdapterBuilderImpl adapterBuilder = new ServiceAdapterBuilderImpl<>(dm, adaptee); consumer.accept(adapterBuilder); Component comp = adapterBuilder.build(); - if (adapterBuilder.autoAdd()) { + if (adapterBuilder.isAutoAdd()) { dm.add(comp); } return comp; @@ -187,11 +187,11 @@ public abstract class DependencyActivato * @return a new DM factory configuration adapter component. The adapter component is auto-added into the dm object, unless the lambda calls * the FactoryPidAdapterBuilder.autoAdd(false) method is called */ - public static Component factoryPidAdapter(DependencyManager dm, Consumer consumer) { - FactoryPidAdapterBuilder factoryPidAdapter = new FactoryPidAdapterBuilderImpl(dm); + public static Component factoryPidAdapter(DependencyManager dm, Consumer> consumer) { + FactoryPidAdapterBuilderImpl factoryPidAdapter = new FactoryPidAdapterBuilderImpl<>(dm); consumer.accept(factoryPidAdapter); Component comp = factoryPidAdapter.build(); - if (factoryPidAdapter.autoAdd()) { + if (factoryPidAdapter.isAutoAdd()) { dm.add(comp); } return comp; Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FactoryPidAdapterBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FactoryPidAdapterBuilder.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FactoryPidAdapterBuilder.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FactoryPidAdapterBuilder.java Tue Jan 12 22:45:36 2016 @@ -1,8 +1,12 @@ package org.apache.felix.dm.builder.lambda; -import java.util.Dictionary; +import java.util.function.Function; +import java.util.function.Supplier; -import org.apache.felix.dm.builder.lambda.Functions.Consumer2; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentDictionary; +import org.apache.felix.dm.builder.lambda.Functions.CbDictionary; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentDictionary; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeDictionary; /** * Defines the interface for a Dependency Manager Factory Configuration Adapter. @@ -21,10 +25,86 @@ import org.apache.felix.dm.builder.lambd * * TODO: javadoc */ -public interface FactoryPidAdapterBuilder extends ComponentBuilder { - FactoryPidAdapterBuilder factoryPid(String pid); - FactoryPidAdapterBuilder factoryPid(Class pidClass); - FactoryPidAdapterBuilder propagate(); - FactoryPidAdapterBuilder propagate(boolean propagate); - FactoryPidAdapterBuilder onUpdate(Consumer2> callback); +public interface FactoryPidAdapterBuilder extends ComponentBuilderBase> { + /** + * Configures the component implementation. Can be a class name, or a component implementation object. + * @param impl the component implementation (a class, or an Object). + * @return this builder + */ + FactoryPidAdapterBuilder impl(U impl); + + /** + * TODO + */ + FactoryPidAdapterBuilder impl(Class implClass); + + /** + * Configures a factory that can be used to create this component implementation. + * Example: "factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())". + * + * @param create the factory used to create the component implementation. + * @return this builder + */ + FactoryPidAdapterBuilder factory(Supplier create); + + /** + * Configures a factory used to create this component implementation using a Factory object and a method in the Factory object. + * Example: + * + * factory(Factory::new, Factory::create) + * + * @param factory the function used to create the Factory itself + * @param create the method reference on the Factory method that is used to create the Component implementation + * @return this builder + */ + FactoryPidAdapterBuilder factory(Supplier factory, Function 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. + * + * Example: + * + * CompositionManager mngr = new CompositionManager(); + * ... + * factory(mngr::create, mngr::getComposition) + * + * @param factory + * @param getComposition + * @return this builder + */ + FactoryPidAdapterBuilder factory(Supplier factory, Supplier getComposition); + + /** + * Configures a factory that also returns a composition of objects for this component implemenation. + * + * Example: + * + * factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition). + * + * 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. + * + * @param factory the function used to create the Factory itself + * @param create the Factory method used to create the main component implementation object + * @param getComposition the Factory method used to return the list of objects that are also part of the component implementation. + * @return this builder + */ + FactoryPidAdapterBuilder factory(Supplier factory, Function create, Function getComposition); + + FactoryPidAdapterBuilder factoryPid(String pid); + FactoryPidAdapterBuilder factoryPid(Class pidClass); + FactoryPidAdapterBuilder propagate(); + FactoryPidAdapterBuilder propagate(boolean propagate); + + FactoryPidAdapterBuilder cb(String updateMethod); + FactoryPidAdapterBuilder cb(Object callbackInstance, String updateMethod); + + FactoryPidAdapterBuilder cb(CbTypeDictionary callback); + FactoryPidAdapterBuilder cb(CbTypeComponentDictionary callback); + FactoryPidAdapterBuilder cb(CbDictionary callback); + FactoryPidAdapterBuilder cb(CbComponentDictionary callback); + + FactoryPidAdapterBuilder compositeCb(CbTypeDictionary callback); + FactoryPidAdapterBuilder compositeCb(CbTypeComponentDictionary callback); }