felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierre De Rop (JIRA)" <j...@apache.org>
Subject [jira] [Created] (FELIX-5425) Add support for OSGi Promise in DM-lambda
Date Thu, 24 Nov 2016 15:08:59 GMT
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:

 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<String> 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
          .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.

   void doService() {

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

View raw message