Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B79D5200BCB for ; Thu, 24 Nov 2016 16:09:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B6469160B11; Thu, 24 Nov 2016 15:09:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F3401160B20 for ; Thu, 24 Nov 2016 16:09:00 +0100 (CET) Received: (qmail 50285 invoked by uid 500); 24 Nov 2016 15:09:00 -0000 Mailing-List: contact dev-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 dev@felix.apache.org Received: (qmail 50202 invoked by uid 99); 24 Nov 2016 15:08:59 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2016 15:08:59 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id C000F2C03DF for ; Thu, 24 Nov 2016 15:08:59 +0000 (UTC) Date: Thu, 24 Nov 2016 15:08:59 +0000 (UTC) From: "Pierre De Rop (JIRA)" To: dev@felix.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (FELIX-5425) Add support for OSGi Promise in DM-lambda MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 24 Nov 2016 15:09:01 -0000 Pierre De Rop created FELIX-5425: ------------------------------------ Summary: Add support for OSGi Promise in DM-lambda Key: FELIX-5425 URL: https://issues.apache.org/jira/browse/FELIX-5425 Project: Felix Issue Type: New Feature Components: Dependency Manager Lambda Affects Versions: org.apache.felix.dependencymanager-r8 Reporter: Pierre De Rop Assignee: Pierre De Rop Priority: Minor When you use the new DM-lambda API, and when a component needs to get the result of an asynchronous operation before being activated and registered in the OSGi service registry, you can now use a new "future dependency" which allows to define a CompletableFuture (jdk8), and when the CF completes, then the result is injected in the component (like if it was a ServiceDependency), then the component is started and registered. For example, if your component needs to download a web page before being activated and registered, you can do this: {code} public class Activator extends DependencyManagerActivator { public void init(BundleContext ctx, DependencyManager dm) throws Exception { // Download a web page asynchronously, using a CompletableFuture: String url = "http://felix.apache.org/"; CompletableFuture page = CompletableFuture.supplyAsync(() -> downloadSite(url)); // The component depends on a log service and on the content of the Felix site. // The lambda passed to the "withFuture" method configures the callback that is // invoked with the result of the CompletableFuture (the page content). component(comp -> comp .provides(MyService.class) .impl(MyComponent.class) .withService(LogService.class) .withFuture(page, result -> result.complete(MyComponent::setPage))); } } public class MyComponent implements MyService { volatile LogService log; // injected. void setPage(String page) { // injected by the FutureDependency. } void start() { // the web page has been downloaded and we can now register in the OSGI registry. } @Override void doService() { ... } } {code} Now, it should be investigated if the DM-lambda API could also support the OSGI Promise API (in addition to the jdk8 CompletableFuture). -- This message was sent by Atlassian JIRA (v6.3.4#6332)