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 635731821B for ; Thu, 4 Feb 2016 16:49:31 +0000 (UTC) Received: (qmail 18663 invoked by uid 500); 4 Feb 2016 16:42:42 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 18630 invoked by uid 500); 4 Feb 2016 16:42:42 -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 18621 invoked by uid 99); 4 Feb 2016 16:42:42 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Feb 2016 16:42:42 +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 F33571A04F2 for ; Thu, 4 Feb 2016 16:42:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.371 X-Spam-Level: * X-Spam-Status: No, score=1.371 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.429] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id VGbcbao20zqG for ; Thu, 4 Feb 2016 16:42:40 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 3C71420D37 for ; Thu, 4 Feb 2016 16:42:40 +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 BA65EE046B for ; Thu, 4 Feb 2016 16:42: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 BCB723A0F0B for ; Thu, 4 Feb 2016 16:42:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r979472 - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html Date: Thu, 04 Feb 2016 16:42:39 -0000 To: commits@felix.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160204164239.BCB723A0F0B@svn01-us-west.apache.org> Author: buildbot Date: Thu Feb 4 16:42:39 2016 New Revision: 979472 Log: Staging update by buildbot for felix Modified: websites/staging/felix/trunk/content/ (props changed) websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html Propchange: websites/staging/felix/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Thu Feb 4 16:42:39 2016 @@ -1 +1 @@ -1728416 +1728505 Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html ============================================================================== --- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html (original) +++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html Thu Feb 4 16:42:39 2016 @@ -91,6 +91,7 @@ h2:hover > .headerlink, h3:hover > .head

Since the R7 version, a new dm-lambda library has been introduced in the DM distribution. This new library allows to programmatically declare OSGi components using a bit more fluent, concise and type-safe API that is based on Java8 Lambda expressions and other goodies like method references.

+

(Please notice that using the dm-lambda library requires the usage of a recent Java8 jvm (the library has been tested with java version "1.8.0_71").

Principle

The new library is based on the builder design pattern applied to java8 lambdas. Basically, you call a chain of methods from a fluent builder, and at the end of the chain, you call "build()" which returns the actual DM objects that you already know from @@ -143,7 +144,7 @@ for dm-lambda activators:

Now, most of the time, in an Activator you usually create a Component and immediately add it to the dm object. -So, in order to reduce the code size, you can then use a special overloaded factory method that accepts a lambda which takes as +So, in order to reduce the code size, you can then use a component() method that accepts a lambda which takes as argument a Consumer<ComponentBuilder> parameter. So, the lambda has just to invoke the chain of necessary methods from the builder, without having to call the last "build" method. The constructed Component is then automatically added to the dm object.

@@ -231,12 +232,12 @@ But like in the current DM API, you can

The cb method accepts a varargs of strings (up to 4 method names):

    -
  1. when using one argument, the first argument is used as the add callback.
  2. -
  3. when using two argument, the first argument is used as the add callback, and the second one as the remove callback.
  4. -
  5. when using three arguments, the first argument is used as the add callback, the second one as the "change" callback, and the third one as the remove callback.
  6. -
  7. when using four arguments, the given argument is used as the add callback, the second one as the "change" callback, the third one as the remove callback, and the last one as the swap callback.
  8. +
  9. when using one argument, it is used as the add callback.
  10. +
  11. when using two arguments, the first arg is used as the add callback, and the second one as the remove callback.
  12. +
  13. when using three arguments, the first arg is used as the add callback, the second one as the change callback, and the third one as the remove callback.
  14. +
  15. when using four arguments, the first arg is used as the add callback, the second one as the change callback, the third one as the remove callback, and the last one as the swap callback.
-

The add/change/remove callbacks accepts the following kind of method signatures ("S" represents the type of the service dependency):

+

The add/change/remove callbacks accept the following kind of method signatures ("S" represents the type of the service dependency):

method(S service)
 method(S service, Map<String, Object> serviceProperties)
 method(S service, Dictionary<String, Object> serviceProperties)
@@ -495,6 +496,12 @@ then have to cache the injected Tracked
 

Also, notice that when the page is injected in the setPage() method, you absolutely don't need to deal with synchronization at all because in DM, all lifecycle and dependency callbacks are safely scheduled in a "serial queue" associated to the component.

+

Another Example with CompletableFuture and RxJava.

+

We just introduced the new FutureDependency. Allowing to use a CompletableFuture as a dependency is useful because CF is a powerful abstraction +that allows to wrap any asynchronous events or async libraries with a standard jdk tool (CompletableFuture). +In this section, we present a way to "wait for" RxJava "Observables" using DM.

+

RxJava, like the CompletableFuture java8 tool, allows to react on events, but using non blocking push paradigm.

+

TODO: finish this section.

Comparing two activators using old and new API:

Assume we have a ServiceConsumer which depends on the following services:

    @@ -617,7 +624,7 @@ and the service is registered.

    Caution: if you are using a corporate http proxy, you have to fix the Activator in order to configure the ip addr and port number of your http proxy.

    - Rev. 1728413 by pderop on Thu, 4 Feb 2016 07:44:09 +0000 + Rev. 1728505 by pderop on Thu, 4 Feb 2016 16:42:10 +0000
    Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project