felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1727487 [7/7] - in /felix/sandbox/pderop/dependencymanager-lambda: org.apache.felix.dependencymanager.lambda.itest/ org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/builder/ org.apache.felix.dependencymanager.lambda....
Date Fri, 29 Jan 2016 06:50:11 GMT
Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/README
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/README?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/README (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/README Fri Jan 29 06:50:09 2016
@@ -0,0 +1,106 @@
+The purpose of this sample is to experiment RxJava(2.0) and DependencyManager lambda; and to check if some hooks have 
+to be added into DM-lambda in order to build some RxJava applications on top it.
+
+So, in this sample, we have a use case where RxJava is used to download and parse an URL from the web, in order to count the number of
+hrefs (links) contained in the URL page, and we do this from a component.init() method. 
+Now, the problem is that the page is downloaded asynchronously using RxJava, and when the component init() method returns, 
+any services implemented by the component are registered. Moreover, the component start() method is called while the download is still pending.
+
+So, ultimately, we would need some kind of required dependency on something in order to make sure that the component remains in the 
+init state, until the page has been downloaded and parsed.
+
+Now, there is something new to DM-lambda: a new kind of dependency has been introduced: you can now
+define a dependency on a "CompletableFuture", using the "ComponentBuilder.withFuture" method.
+Such dependency allows to block the activation of a component (its a required dependency) until a given completableFuture completes.
+
+Here is an example: you have a Download component and from the Activator, you declare this:
+
+public class Activator extends DependencyActivatorBase {
+    public void init() throws Exception {
+		CompletableFuture<String> pageFuture = 
+				CompletableFuture.supplyAsync(() -> downloadSite("http://felix.apache.org/"))
+
+        component(comp -> comp
+        	.provides(DownloadService.class)
+        	.impl(Download.class)
+            .withService(LogService.class, srv -> srv.onAdd(FelixSiteImpl::bind))
+            .withFuture(pageFuture, depbuilder -> depbuilder.thenAccept(Download::setContent)));
+        
+    }
+}
+
+Here, notice the new "withFuture" dependency: it's a required dependency that takes a CompletableFuture (pageFuture), and also the 
+callback that will be invoked when the future will have completed (thenAccept).
+The "thenAccept" method has the same purpose as the one from the CompletableFuture.thenAccept method.
+
+So, now, the nice thing is that wrapping an RxObservable to CompletableFuture is simple and can be done using the following helper class:
+
+class ObservableCompletableFuture<T> extends CompletableFuture<T> {
+    private final Disposable m_subscription;
+
+    public ObservableCompletableFuture(Observable<T> observable) {
+        m_subscription = observable
+        		.subscribeOn(Schedulers.io())
+        		.subscribe(this::complete, this::completeExceptionally);        		
+    }
+        
+    @Override
+    public boolean cancel(boolean mayInterruptIfRunning) {
+        m_subscription.dispose();
+        return super.cancel(mayInterruptIfRunning);
+    }
+}
+
+This simple class takes in the constructor an Observable<T>, and subscribes to it.
+So, when the Observable completes, the "this::complete" calls the CompletableFuture.complete() method in order 
+to propagate the completion of the Observable to the CompletableFuture.
+
+Now let's go with a concrete example: Using this class above allows to build nice DM components without boilerplate code, like this:
+
+1) from the Activator, you can for example define a service providing component like this:
+
+Activator.java:
+
+    	// Define the FelixSiteInfo component that provides some informations about the Felix web site.
+        component(comp -> comp
+        	.provides(SiteInfo.class)
+        	.impl(SiteInfoImpl.class)
+            .withService(LogService.class, srv -> srv.onAdd(SiteInfoImpl::bind)));
+
+ 2) and from the SiteInfoImpl.init() method:
+ 
+ FelixSiteImpl.java:
+ 
+ 	void init(Component c) {
+		// Asynchronously calculate the number of links from the Felix web site.
+		// We use Rx to define an asynchrous Observable task, and we wrap it to a CompletableFuture
+		// that is used as a Dependency Manager "Future" dependency, in order to block the activation of
+		// our component until the felix site has been downloaded and parsed.
+		
+		Observable<List<String>> links = downloadSite("http://felix.apache.org/")
+			.map(this::getSiteLinks);
+								
+        component(c, comp -> comp
+        		.withFuture(toFuture(links), futuredep -> futuredep.thenAccept(this::setLinks)));        		
+	}
+ 
+ 	// Called when our future has completed.
+	void setLinks(List<String> links) {
+		m_felixLinks = 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 Apache Felix site=" + m_felixLinks.size());
+	}
+	
+The important part to understand is the following:
+
+
+         component(c, comp -> comp
+        		.withFuture(toFuture(links), futuredep -> futuredep.thenAccept(this::setLinks)));        		
+ 
+here, we wrap the links (which is an Observable<List<String>> into the ObservableCompletableFuture helper that was 
+presented previously. And when the CompletableFuture will complete , it will call the "thenAccept(this::setLinks)" method in order to inject 
+the result into the component before the component.start() method, exactly in the same manner when a required dependency is injected before start().

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/SiteInfo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/SiteInfo.java?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/SiteInfo.java (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/SiteInfo.java Fri Jan 29 06:50:09 2016
@@ -0,0 +1,16 @@
+package org.apache.felix.dm.lambda.samples.rx.completable;
+
+import java.util.List;
+
+/**
+ * A Service which provides informations about the Felix web site.
+ */
+public interface SiteInfo {
+	
+	/**
+	 * Returns the links (href) available from the Felix web site.
+	 * @return the links available from the Felix web site
+	 */
+	List<String> getLinks();
+	
+}

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/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/dm/lambda/samples/rx/completable/SiteInfoImpl.java?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/SiteInfoImpl.java (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/completable/SiteInfoImpl.java Fri Jan 29 06:50:09 2016
@@ -0,0 +1,95 @@
+package org.apache.felix.dm.lambda.samples.rx.completable;
+
+import static org.apache.felix.dm.lambda.DependencyManagerActivator.component;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.concurrent.CompletableFuture;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.felix.dm.Component;
+import org.osgi.service.log.LogService;
+
+import io.reactivex.Observable;
+
+/**
+ * A Component which provides general informations about a given web site
+ * (this simple example just displays the number of links it finds from a given URL.
+ * The url is downloaded asynchronously using a CompletableFuture class.
+ * The Component is also using a "withFuture" dependency that allows to wait for the 
+ * completion of the CompletableFuture, before registering the SiteInfo OSGi service.
+ */
+public class SiteInfoImpl implements SiteInfo {
+	final static String HREF_PATTERN = "<a\\s+href\\s*=\\s*(\"[^\"]*\"|[^\\s>]*)\\s*>";
+	LogService m_log;
+	String m_url;
+	List<String> m_links; // List of hrefs contained in the web page referenced by m_url URL.
+	
+
+	public SiteInfoImpl(String url) {
+		m_url = url;
+	}
+
+	void bind(LogService log) {
+		m_log = log;
+	}
+	
+	void init(Component c) {
+		// Asynchronously calculate the number of links from the web site.
+		// We use Rx to define an asynchronous Observable task, and we wrap it to a CompletableFuture
+		// 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<List<String>> links = downloadSite(m_url).map(this::getSiteLinks);
+        component(c, comp -> comp.withFuture(toFuture(links), futuredep -> futuredep.cbi(this::setLinks)));
+	}
+	
+	// Called when our future has completed.
+	void setLinks(List<String> 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 site=" + m_links.size());
+	}
+	
+	@Override
+	public List<String> getLinks() {
+		return m_links;
+	}
+
+	private Observable<String> downloadSite(String url) {
+		return Observable.create(subscriber -> {		
+			try (Scanner in = new Scanner(new URL(url).openStream())) {
+				StringBuilder builder = new StringBuilder();
+				while (in.hasNextLine()) {
+					builder.append(in.nextLine());
+					builder.append("\n");
+				}
+				subscriber.onNext(builder.toString());
+			} catch (IOException ex) {
+				RuntimeException rex = new RuntimeException();
+				rex.initCause(ex);
+				throw rex;
+			}
+		});
+	}
+	
+	private List<String> getSiteLinks(String content) {		 
+		Pattern pattern = Pattern.compile(HREF_PATTERN, Pattern.CASE_INSENSITIVE);
+		Matcher matcher = pattern.matcher(content);
+		List<String> result = new ArrayList<>();
+		while (matcher.find())
+			result.add(matcher.group(1));
+		return (result);
+	}
+	
+    public static <T> CompletableFuture<T> toFuture(Observable<T> observable) {
+    	return new ObservableCompletableFuture<T>(observable);
+    }
+}

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/Activator.java?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/Activator.java (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/Activator.java Fri Jan 29 06:50:09 2016
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.lambda.samples.rx.observable;
+
+import static java.lang.System.out;
+
+import org.apache.felix.dm.lambda.DependencyManagerActivator;
+import org.osgi.service.log.LogService;
+
+public class Activator extends DependencyManagerActivator {
+
+	@Override
+	protected void activate() throws Exception {
+    	out.println("type \"log info\" to see the logs emitted by this test.");
+		component(comp -> comp.impl(ObservableComponent.class).withSrv(LogService.class));
+	}
+
+}

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/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/dm/lambda/samples/rx/observable/ObservableComponent.java?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/ObservableComponent.java (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/ObservableComponent.java Fri Jan 29 06:50:09 2016
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.lambda.samples.rx.observable;
+
+import static org.apache.felix.dm.lambda.DependencyManagerActivator.component;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.service.log.LogService;
+
+import io.reactivex.Observable;
+import io.reactivex.internal.subscriptions.EmptySubscription;
+
+public class ObservableComponent {
+	DependencyManager m_dm; // injected
+	LogService m_log; // injected
+	
+	public static class DocumentViewer  {
+		final String m_title;
+		public DocumentViewer(String title) {
+			m_title = title;
+		}
+		void start() {
+			// Display the title in the GUI
+		}
+	}
+	
+	// Returns a List of website URLs based on a text search
+	Observable<List<String>> query(String text) {
+		if (text.equals("rxjava")) {
+			return Observable.just(Arrays.asList("https://github.com/ReactiveX/RxJava", "https://en.wikipedia.org/wiki/Reactive_programming"));
+		} else {
+			return Observable.just(Collections.emptyList());
+		}
+	 }	
+	
+	 Observable<String> getTitle(String url) {
+		if (url.equals("https://github.com/ReactiveX/RxJava")) {
+			return Observable.just("ReactiveX/RxJava");
+		} else if (url.equals("https://en.wikipedia.org/wiki/Reactive_programming")) {
+			return Observable.just("Reactive Programming");
+		} else {
+			return Observable.just((String) null);
+		}
+	 }
+
+	void start() {
+		m_log.log(LogService.LOG_INFO, "query ...");		
+		query("rxjava")
+			.flatMap(urls -> Observable.fromStream(urls.stream()))
+			.flatMap(url -> getTitle(url))
+			.filter(title -> title != null)
+			.flatMap(title -> createObservableComponent(title))
+			.subscribe(component -> m_log.log(LogService.LOG_INFO, "Component started :" + component));        
+	}
+		
+	Observable<Component> createObservableComponent(String title) {
+		return Observable.create(publisher -> {		
+	        publisher.onSubscribe(EmptySubscription.INSTANCE);
+			component(m_dm, builder -> builder
+					.factory(() -> new DocumentViewer(title))
+					.startInstance(publisher::onNext));
+		});
+	}
+}

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/README
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/README?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/README (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/rx/observable/README Fri Jan 29 06:50:09 2016
@@ -0,0 +1,32 @@
+The purpose of this sample is to experiment RxJava(2.0) and DependencyManager lambda; and to check if some hooks have 
+to be added into DM-lambda in order to build some RxJava applications on top it.
+
+So, in this sample, A DM component is built from code (see ObservableComponent.java) using RxJava style.
+That is: using some Rx "Observables" and a chain of map() calls to build the DM component.
+
+So, basically, The sample first transforms a DM Component into an "Observable".
+Turning any object to an Rx Observable is easy, using the Observable<T>.create(Publisher publisher) method.
+For example:
+
+	Observable<Component> createObservableComponent(String componentParameters) {
+		return Observable.create(publisher -> {		
+	        publisher.onSubscribe(EmptySubscription.INSTANCE);
+			component(m_dm, builder -> builder
+					.factory(() -> new SomeDMComponent(componentParameters))
+					.onStart(publisher::onNext)); // will trigger next action in the map() chain only AFTER component is started.
+		});
+	}
+
+So, the component can then be created using a flow of map() transformations calls like in the following example:
+
+		query("rxjava")                                            // returns Observable<List<String>> (list of URLs).
+			.flatMap(urls -> Observable.fromStream(urls.stream())) // Loop on each URL returned by the query
+			.flatMap(url -> getTitle(url))                         // get the title of the current URL page content
+			.filter(title -> title != null)                        // Ignore page without title
+			.flatMap(title -> createObservableComponent(title))    // and create a component for the current title			
+			.subscribe(component -> System.out.println("Component has started: " + component));        
+
+The query(String search) returns an Observable<List<String>> representing the URLS in the web that match the given text search.
+The subscriber will be called only after the Component has been started, because the createObservableComponent method only calls 
+the "publisher::onNext" method once the component is fully active (see "onStart(publisher::onNext))" call in the 
+createObservableComponent function.

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleAdapterBuilder.java Fri Jan 29 06:50:09 2016
@@ -12,8 +12,8 @@ import org.apache.felix.dm.lambda.callba
  * class field with a Bundle type):
  * 
  * <blockquote><pre>
- * public class Activator extends DependencyActivatorBase {
- *     public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *     public void activate() throws Exception { 
  *       bundleAdapter(adapt -> adapt
  *           .impl(MyBundleAdapterImpl.class)
  *           .provides(MyBundleAdapter.class)
@@ -24,8 +24,8 @@ import org.apache.felix.dm.lambda.callba
  * Example that creates a MyBundleAdapter service for each started bundle (the bundle is added using a method reference):
  * 
  * <blockquote><pre>
- * public class Activator extends DependencyActivatorBase {
- *     public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *     public void activate() throws Exception { 
  *       bundleAdapter(adapt -> adapt
  *           .impl(MyBundleAdapterImpl.class)
  *           .provides(MyBundleAdapter.class)

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/BundleDependencyBuilder.java Fri Jan 29 06:50:09 2016
@@ -16,8 +16,8 @@ import org.osgi.framework.Bundle;
  * Example that uses a Bundle Dependency:
  * 
  * <blockquote><pre>
- * public class Activator extends DependencyActivatorBase {
- *     public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *     public void activate() throws Exception { 
  *         component(comp -> comp
  *             .impl(MyComponent.class)
  *             .withBundle(b -> b.filter("(Bundle-SymbolicName=" + BSN + ")").cb(MyComponent::add, MyComponent::remove)));

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ComponentBuilder.java Fri Jan 29 06:50:09 2016
@@ -11,7 +11,6 @@ import org.apache.felix.dm.Component;
 import org.apache.felix.dm.lambda.callbacks.CbComponent;
 import org.apache.felix.dm.lambda.callbacks.CbConsumer;
 import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
-import org.apache.felix.dm.lambda.callbacks.FluentProperties;
 
 /**
  * Component builder. This interface is also the base interface for extended components like aspects, adapters, etc ...
@@ -20,8 +19,8 @@ import org.apache.felix.dm.lambda.callba
  * on a class field which type matches the ConfigurationAdmin interface:
  * 
  * <blockquote><pre>
- * public class Activator extends DependencyActivatorBase {
- *   public void init() throws Exception {
+ * public class Activator extends DependencyManagerActivator {
+ *   public void activate() throws Exception {
  *       component(comp -> comp.impl(Configurator.class).withSrv(ConfigurationAdmin.class));
  *   }
  * } </pre></blockquote>

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ConfigurationDependencyBuilder.java Fri Jan 29 06:50:09 2016
@@ -14,8 +14,8 @@ import org.apache.felix.dm.lambda.callba
  * callback is declared using a method reference (see the "cb(ServiceImpl::modified)" code):
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *     public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *     public void activate() throws Exception { 
  *         component(comp -> comp
  *           .impl(ServiceImpl.class)
  *           .withConf(conf -> conf.pid(ServiceConsumer.class).cb(ServiceImpl::modified)));  

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/DependencyManagerActivator.java Fri Jan 29 06:50:09 2016
@@ -0,0 +1,396 @@
+package org.apache.felix.dm.lambda;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Consumer;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.lambda.impl.BundleAdapterBuilderImpl;
+import org.apache.felix.dm.lambda.impl.BundleDependencyBuilderImpl;
+import org.apache.felix.dm.lambda.impl.CompletableFutureDependencyImpl;
+import org.apache.felix.dm.lambda.impl.ComponentBuilderImpl;
+import org.apache.felix.dm.lambda.impl.ConfigurationDependencyBuilderImpl;
+import org.apache.felix.dm.lambda.impl.FactoryPidAdapterBuilderImpl;
+import org.apache.felix.dm.lambda.impl.ServiceAdapterBuilderImpl;
+import org.apache.felix.dm.lambda.impl.ServiceAspectBuilderImpl;
+import org.apache.felix.dm.lambda.impl.ServiceDependencyBuilderImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Defines a base for Activators in order to build DependencyManager Components using a java8 style.<p>
+ * 
+ * Code example using auto configured fields:
+ * 
+ * <pre> {@code
+ * 
+ * import static org.apache.felix.dm.builder.lambda.DependencyActivatorBase.*;
+ *
+ * public class Activator extends DependencyManagerActivator {    
+ *     public void activate() throws Exception {
+ *         component(comp -> comp
+ *             .provides(Service.class, property -> "value")
+ *             .impl(ServiceImpl.class)            
+ *             .withSrv(LogService.class, ConfigurationAdmni.class) // both services are required and injected in class fields with compatible types.           
+ *     }
+ * }
+ * }</pre>
+ *
+ * Code example using reflection callbacks:<p>
+ * <pre> {@code
+ * 
+ * import static org.apache.felix.dm.builder.lambda.DependencyActivatorBase.*;
+ *
+ * public class Activator extends DependencyManagerActivator {    
+ *     public void activate() throws Exception {
+ *         component(comp -> comp
+ *             .provides(Service.class, property -> "value")
+ *             .impl(ServiceImpl.class)            
+ *             .withSrv(LogService.class, log -> log.cb("setLog"))              
+ *             .withSrv(ConfigurationAdmni.class, cm -> cm.cb("setConfigAdmin")))                
+ *     }
+ * }
+ * }</pre>
+ *
+ * Code example using method references:<p>
+ * 
+ * <pre> {@code
+ * 
+ * import static org.apache.felix.dm.lambda.DependencyActivatorBase.*;
+ *
+ * public class Activator extends DependencyManagerActivator {    
+ *     public void activate() throws Exception {
+ *         component(comp -> comp
+ *             .provides(Service.class, property -> "value")
+ *             .impl(ServiceImpl.class)            
+ *             .withSrv(LogService.class, log -> log.cb(ServiceImpl::setLog))              
+ *             .withSrv(ConfigurationAdmni.class, cm -> cm.cb(ServiceImpl::setConfigAdmin)))                
+ *     }
+ * }
+ * }</pre>
+ */
+public abstract class DependencyManagerActivator implements BundleActivator {    
+	/**
+	 * DependencyManager object used to create/register real DM Components that are built by this activator.
+	 */
+    protected DependencyManager m_manager;
+    
+    /**
+     * Bundle Context asociated to the activator bundle.
+     */
+    protected BundleContext m_ctx;
+
+    /**
+     * Our Activator is starting.
+     */
+    @Override
+    public void start(BundleContext context) throws Exception {
+        m_manager = new DependencyManager(context);
+        m_ctx = context;
+        activate();
+    }
+
+    /**
+     * Our Activator is stopped.
+     */
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        deactivate();
+    }
+
+    /**
+     * Sub classes must override this method in order to build some DM components.
+     * @throws Exception
+     */
+    protected abstract void activate() throws Exception;
+
+    /**
+     * Sub classes may override this method that is called when the Activator is stopped.
+     * @param manager
+     * @throws Exception
+     */
+    protected void deactivate() throws Exception {
+    }
+    
+    /**
+     * Returns the DependencyManager used to create/managed DM Components
+     * @return the DependencyManager associated to this Activator
+     */
+    protected DependencyManager getDependencyManager() {
+        return m_manager;
+    }
+    
+    /**
+     * Returns the bundle context.
+     */
+    protected BundleContext getBundleContext() {
+        return m_ctx;
+    }
+    
+    /**
+     * Creates a Component builder that can be used to create a DM Component. 
+     * @return a Component builder that can be used to create a DM Component.
+     */
+    protected ComponentBuilder<?> component() {
+        return new ComponentBuilderImpl(m_manager);
+    }
+    
+    /**
+     * Creates a service Aspect builder that can be used to create a DM Aspect Component. 
+     * @return a service Aspect builder that can be used to create a DM Aspect Component.
+     */
+    protected <T> ServiceAspectBuilder<T> aspect(Class<T> aspectType) {
+        ServiceAspectBuilderImpl<T> aspectBuilder = new ServiceAspectBuilderImpl<>(m_manager, aspectType);
+        return aspectBuilder;
+    }
+    
+    /**
+     * Creates a service Adapter builder that can be used to create a DM Adapter Component. 
+     * @return a service Adapter builder that can be used to create a DM Adapter Component.
+     */
+    protected <T> ServiceAdapterBuilder<T> adapter(Class<T> adapteeType) {
+        ServiceAdapterBuilderImpl<T> adapterBuilder = new ServiceAdapterBuilderImpl<>(m_manager, adapteeType);
+        return adapterBuilder;
+    }
+    
+    /**
+     * Builds a DM Component using a Java8 style ComponentBuilder.
+     * @param consumer the lambda that will use the ComponentBuilder for building the DM component. 
+     * 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<ComponentBuilder<?>> consumer) {
+        return component(m_manager, consumer);
+    }
+        
+    /**
+     * Builds a DM Aspect Component using a Java8 style AspectBuilder.
+     * @param consumer the lambda that will use the AspectBuilder for building the DM aspect component. 
+     * The component is auto-added to the DependencyManager, unless the lambda calls the AspectBuilder.autoAdd(false) method.
+     * @return a newly built DM component.
+     */
+    protected <T> Component aspect(Class<T> aspect, Consumer<ServiceAspectBuilder<T>> consumer) {
+        return aspect(m_manager, aspect, consumer);
+    }
+
+    /**
+     * Builds a DM Adapter Component using a Java8 style AdapterBuilder.
+     * @param consumer the lambda that will use the AdapterBuilder for building the DM adapter component. 
+     * The component is auto-added to the DependencyManager, unless the lambda calls the AdapterBuilder.autoAdd(false) method.
+     * @return a newly built DM component.
+     */
+    protected <T> Component adapter(Class<T> adaptee, Consumer<ServiceAdapterBuilder<T>> consumer) {
+        return adapter(m_manager, adaptee, consumer);
+    }
+    
+    /**
+     * Builds a DM Factory Configuration Adapter Component using a Java8 style FactoryPidAdapterBuilder.
+     * @param consumer the lambda that will use the FactoryPidAdapterBuilder for building the DM factory configuration adapter component. 
+     * 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<FactoryPidAdapterBuilder> consumer) {
+        return factoryPidAdapter(m_manager, consumer);
+    }
+
+    /**
+     * Builds a DM Bundle Adapter Component.
+     * @param consumer the lambda used to build the actual bundle adapter. 
+     * The component is auto-added to the DependencyManager, unless the lambda calls the BundleAdapter.autoAdd(false) method.
+     * @return a newly built DM component.
+     */
+    protected Component bundleAdapter(Consumer<BundleAdapterBuilder> consumer) {
+        return bundleAdapter(m_manager, consumer);
+    }
+       
+    // These static methods can be used when building DM components outside of an activator.
+	
+    /**
+     * Creates a Component builder that can be used to create a Component. 
+     * @return a Component builder that can be used to create a Component.
+     */
+    public static ComponentBuilder<?> component(DependencyManager dm) {
+        return new ComponentBuilderImpl(dm);
+    }
+    
+    /**
+     * Creates a service Aspect builder that can be used to create an Aspect Component. 
+     * @param dm the DependencyManager object used to register the built component
+     * @param aspect the type of the aspect service
+     * @return a service Aspect builder that can be used to create an Aspect Component.
+     */
+    public static <T> ServiceAspectBuilder<T> aspect(DependencyManager dm, Class<T> aspect) {
+        ServiceAspectBuilderImpl<T> aspectBuilder = new ServiceAspectBuilderImpl<>(dm, aspect);
+        return aspectBuilder;
+    }
+    
+    /**
+     * Creates a service Adapter builder that can be used to create an Adapter Component. 
+     * @param dm the DependencyManager object used to register the built component
+     * @param adaptee the type of the adaptee service
+     * @return a service Adapter builder that can be used to create an Adapter Component.
+     */
+    public static <T> ServiceAdapterBuilder<T> adapter(DependencyManager dm, Class<T> adaptee) {
+        ServiceAdapterBuilderImpl<T> adapterBuilder = new ServiceAdapterBuilderImpl<>(dm, adaptee);
+        return adapterBuilder;
+    }
+
+    /**
+     * Creates a factory pid adapter that can be used to create a factory adapter Component. 
+     * @param dm the DependencyManager object used to register the built component
+     * @return a factory pid adapter that can be used to create a factory adapter Component. 
+     */
+    public static FactoryPidAdapterBuilder factoryPidAdapter(DependencyManager dm) {
+        return new FactoryPidAdapterBuilderImpl(dm);
+    }
+   
+    /**
+     * Creates a bundle adapter builder that can be used to create a DM bundle adapter Component. 
+     * @param dm
+     * @return a bundle adapter builder that can be used to create a DM bundle adapter Component.
+     */
+    public static BundleAdapterBuilder bundleAdapter(DependencyManager dm) {
+        return new BundleAdapterBuilderImpl(dm);
+    }
+   
+    /**
+     * Creates a DM ServiceDependency builder.
+     * 
+     * @param component the component on which you want to build a new service dependency using the returned builder
+     * @param service the service dependency type.
+     * @return a DM ServiceDependency builder.
+     */
+    public static <T> ServiceDependencyBuilder<T> serviceDependency(Component component, Class<T> service) {
+        return new ServiceDependencyBuilderImpl<>(component, service);
+    }
+    
+    /**
+     * Creates a DM Configuration Dependency builder.
+     * 
+     * @param component the component on which you want to build a new configuration dependency using the returned builder
+     * @return a DM Configuration Dependency builder.
+     */
+    public static ConfigurationDependencyBuilder confDependency(Component component) {
+        return new ConfigurationDependencyBuilderImpl(component);
+    }
+    
+    /**
+     * Creates a DM Bundle Dependency builder.
+     * 
+     * @param component the component on which you want to build a new bundle dependency using the returned builder
+     * @return a DM Configuration Dependency builder.
+     */
+    public static BundleDependencyBuilder bundleDependency(Component component) {
+        return new BundleDependencyBuilderImpl(component);
+    }
+
+    /**
+     * Creates a DM CompletableFuture Dependency builder.
+     * 
+     * @param component the component on which you want to build a new completable future dependency using the returned builder.
+     * @param future the future the dependency built using the returned builder will depend on.
+     * @return a CompletableFuture dependency builder.
+     */
+    public static <F> FutureDependencyBuilder<F> futureDependency(Component component, CompletableFuture<F> future) {
+        return new CompletableFutureDependencyImpl<>(component, future);
+    }
+
+    /**
+     * Builds a component using a lambda and a component builder
+     * @param dm the DependencyManager where the component is auto-added (unless the component.autoAdd(false) is called)
+     * @param consumer a lambda that is called to build the component. When the lambda is called, it will be provided with a 
+     * ComponentBuilder object that is used to build the actual DM component.
+     * 
+     * @return the built DM component.
+     */
+    public static Component component(DependencyManager dm, Consumer<ComponentBuilder<?>> consumer) {
+        ComponentBuilder<?> componentBuilder = new ComponentBuilderImpl(dm);
+        consumer.accept(componentBuilder);
+        Component comp = componentBuilder.build();
+        if (((ComponentBuilderImpl) componentBuilder).isAutoAdd()) {
+        	dm.add(comp);
+        }
+        return comp;
+    }
+
+    /**
+     * Update an existing component. Typically, this method can be used from a Component.init method, where more dependencies has to be added.
+     * @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<ComponentBuilder<?>> consumer) {
+        ComponentBuilder<?> componentBuilder = new ComponentBuilderImpl(comp, true /* update component */);
+        consumer.accept(componentBuilder);
+        componentBuilder.build();
+    }
+    
+    /**
+     * Builds an aspect DM Component.
+     * @param dm the DependencyManager object used to register the built component
+     * @param aspect the type of the aspect service
+     * @param consumer a lambda used to build the DM aspect component
+     * @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 <T> Component aspect(DependencyManager dm, Class<T> aspect, Consumer<ServiceAspectBuilder<T>> consumer) {
+        ServiceAspectBuilderImpl<T> aspectBuilder = new ServiceAspectBuilderImpl<>(dm, aspect);
+        consumer.accept(aspectBuilder);
+        Component comp = aspectBuilder.build();
+        if (aspectBuilder.isAutoAdd()) {
+        	dm.add(comp);
+        }
+        return comp;
+    }    
+        
+    /**
+     * Builds an adapter DM Component.
+     * @param dm the DependencyManager object used to register the built component
+     * @param adaptee the type of the adapted service
+     * @param consumer a lambda used to build the DM adapter component
+     * @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 <T> Component adapter(DependencyManager dm, Class<T> adaptee, Consumer<ServiceAdapterBuilder<T>> consumer) {
+        ServiceAdapterBuilderImpl<T> adapterBuilder = new ServiceAdapterBuilderImpl<>(dm, adaptee);
+        consumer.accept(adapterBuilder);
+        Component comp = adapterBuilder.build();
+        if (adapterBuilder.isAutoAdd()) {
+        	dm.add(comp);
+        }
+        return comp;
+    }
+      
+    /**
+     * Builds a bundle adapter DM Component.
+     * @param dm the DependencyManager object used to register the built component
+     * @param consumer a lambda used to build the bundle adapter component
+     * @return a new bundle 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 <T> Component bundleAdapter(DependencyManager dm, Consumer<BundleAdapterBuilder> consumer) {
+        BundleAdapterBuilderImpl adapterBuilder = new BundleAdapterBuilderImpl(dm);
+        consumer.accept(adapterBuilder);
+        Component comp = adapterBuilder.build();
+        if (adapterBuilder.isAutoAdd()) {
+            dm.add(comp);
+        }
+        return comp;
+    }
+
+    /**
+     * Builds a DM factory configuration adapter.
+     * @param dm the DependencyManager object used to create DM components.
+     * @param consumer a lambda used to build the DM factory configuration adapter component
+     * @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 <T> Component factoryPidAdapter(DependencyManager dm, Consumer<FactoryPidAdapterBuilder> consumer) {
+        FactoryPidAdapterBuilderImpl factoryPidAdapter = new FactoryPidAdapterBuilderImpl(dm);
+        consumer.accept(factoryPidAdapter);
+        Component comp = factoryPidAdapter.build();
+        if (factoryPidAdapter.isAutoAdd()) {
+        	dm.add(comp);
+        }
+        return comp;
+    }
+}

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FactoryPidAdapterBuilder.java Fri Jan 29 06:50:09 2016
@@ -11,8 +11,8 @@ import org.apache.felix.dm.lambda.callba
  * Example that defines a factory configuration adapter service for the "foo.bar" factory pid:
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *     public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *     public void activate() throws Exception { 
  *         factoryPidAdapter(adapter -> adapter
  *             .impl(DictionaryImpl.class)
  *             .factoryPid("foo.bar").cb(ServiceImpl::updated)

Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperties.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperties.java?rev=1727487&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperties.java (added)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FluentProperties.java Fri Jan 29 06:50:09 2016
@@ -0,0 +1,31 @@
+package org.apache.felix.dm.lambda;
+
+import org.apache.felix.dm.lambda.callbacks.SerializableLambda;
+
+/**
+ * Lambda allowing to define fluent service properties, like param1 -> "value1", etc ...
+ * Property names are deduces from the lambda parameter name.
+ * 
+ * <bold>Caution: Fluent properties requires the usage of the "-parameter" javac option.
+ * Under eclipse, you can enable this option using:
+ * Windows -> Preference -> Compiler -> Classfile Generation -> Store information about method parameters.
+ * 
+ * <p> Example of a component which provides fluent properties:
+ * 
+ * <blockquote><pre>
+ * public class Activator extends DependencyManagerActivator {
+ *   public void activate() throws Exception {
+ *       component(comp -> comp.impl(MyComponentImpl.class).provides(MyService.class, foo->"bar", foo2 -> 123));
+ *   }
+ * } </pre></blockquote>
+ */
+@FunctionalInterface
+public interface FluentProperties extends SerializableLambda {
+    /**
+     * Represents a fluent property
+     * 
+     * @param name the property name
+     * @return the property value
+     */
+    public Object apply(String name);
+}

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/FutureDependencyBuilder.java Fri Jan 29 06:50:09 2016
@@ -21,8 +21,8 @@ import org.apache.felix.dm.lambda.callba
  * 
  * <pre> {@code
  * 
- * public class Activator extends DependencyActivatorBase {
- *   public void init() throws Exception {    	
+ * public class Activator extends DependencyManagerActivator {
+ *   public void activate() throws Exception {    	
  *      String url = "http://felix.apache.org/";
  *      CompletableFuture<String> page = CompletableFuture.supplyAsync(() -> downloadSite(url));				
  *

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAdapterBuilder.java Fri Jan 29 06:50:09 2016
@@ -9,8 +9,8 @@ package org.apache.felix.dm.lambda;
  * Code example that adapts a "Device" service to an HttpServlet service. the adapter accepts a lambda that is provided with an AdapterBuilder
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *    public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *    public void activate() throws Exception { 
  *        adapter(Device.class, adapt -> adapt
  *              .impl(DeviceServlet.class).provides(HttpServlet.class).properties(alias -> "/device");      
  *    }

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceAspectBuilder.java Fri Jan 29 06:50:09 2016
@@ -9,8 +9,8 @@ package org.apache.felix.dm.lambda;
  * Code example that provides an aspect service for an English dictionary service (the aspect service is injected in the DictionaryAspect::bind method):
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *    public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *    public void activate() throws Exception { 
  *       aspect(DictionaryService.class, asp -> asp
  *          .filter("(lang=en)").rank(10).impl(DictionaryAspect.class)
  *          .cb(dict -> dict.cb(DictionaryAspect::bind))

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/ServiceCallbacksBuilder.java Fri Jan 29 06:50:09 2016
@@ -65,8 +65,8 @@ import org.apache.felix.dm.lambda.callba
  * The withSrv(...)" declaration defines a method reference on the "ComponentImpl::bindLogService" method (using a lambda):
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *    public void init() throws Exception { 
+ * public class Activator extends DependencyManagerActivator {
+ *    public void activate() throws Exception { 
  *       component(comp -> comp.impl(ComponentImpl.class).withSrv(LogService.class, log -> log.cb(ComponentImpl::bindLogService)));
  *    }
  * }}</pre>
@@ -74,8 +74,8 @@ import org.apache.felix.dm.lambda.callba
  * <p> Same example, but we inject the dependency in an object instance that we already have in hand:
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *    public void init() throws Exception {
+ * public class Activator extends DependencyManagerActivator {
+ *    public void activate() throws Exception {
  *       ComponentImpl impl = new ComponentImpl();
  *       component(comp -> comp.impl(impl).withSrv(LogService.class, log -> log.cbi(impl::bindLogService)));
  *    }
@@ -84,8 +84,8 @@ import org.apache.felix.dm.lambda.callba
  * <p> Here, we inject a service using method reflection (as it is the case in original DM api):
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *    public void init() throws Exception {
+ * public class Activator extends DependencyManagerActivator {
+ *    public void activate() throws Exception {
  *       component(comp -> comp.impl(ComponentImpl::class).withSrv(LogService.class, log -> log.cb("bindLogService")));
  *    }
  * }}</pre>
@@ -93,8 +93,8 @@ import org.apache.felix.dm.lambda.callba
  * <p> Same example, but we inject the dependency in an object instance that we already have in hand:
  * 
  * <pre> {@code
- * public class Activator extends DependencyActivatorBase {
- *    public void init() throws Exception {
+ * public class Activator extends DependencyManagerActivator {
+ *    public void activate() throws Exception {
  *       ComponentImpl impl = new ComponentImpl();
  *       component(comp -> comp.impl(impl).withSrv(LogService.class, log -> log.cbi(impl, "bindLogService")));
  *    }

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/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/lambda/impl/AdapterBase.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/AdapterBase.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/AdapterBase.java Fri Jan 29 06:50:09 2016
@@ -9,12 +9,12 @@ import java.util.function.Supplier;
 import org.apache.felix.dm.lambda.BundleDependencyBuilder;
 import org.apache.felix.dm.lambda.ComponentBuilder;
 import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder;
+import org.apache.felix.dm.lambda.FluentProperties;
 import org.apache.felix.dm.lambda.FutureDependencyBuilder;
 import org.apache.felix.dm.lambda.ServiceDependencyBuilder;
 import org.apache.felix.dm.lambda.callbacks.CbComponent;
 import org.apache.felix.dm.lambda.callbacks.CbConsumer;
 import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
-import org.apache.felix.dm.lambda.callbacks.FluentProperties;
 
 /**
  * Methods common to extended components like adapters or aspects.

Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/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/lambda/impl/ComponentBuilderImpl.java?rev=1727487&r1=1727486&r2=1727487&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java (original)
+++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/lambda/impl/ComponentBuilderImpl.java Fri Jan 29 06:50:09 2016
@@ -1,5 +1,10 @@
 package org.apache.felix.dm.lambda.impl;
 
+import static org.apache.felix.dm.lambda.impl.ComponentBuilderImpl.ComponentCallback.DESTROY;
+import static org.apache.felix.dm.lambda.impl.ComponentBuilderImpl.ComponentCallback.INIT;
+import static org.apache.felix.dm.lambda.impl.ComponentBuilderImpl.ComponentCallback.START;
+import static org.apache.felix.dm.lambda.impl.ComponentBuilderImpl.ComponentCallback.STOP;
+
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
@@ -21,13 +26,12 @@ import org.apache.felix.dm.lambda.Bundle
 import org.apache.felix.dm.lambda.ComponentBuilder;
 import org.apache.felix.dm.lambda.ConfigurationDependencyBuilder;
 import org.apache.felix.dm.lambda.DependencyBuilder;
+import org.apache.felix.dm.lambda.FluentProperties;
 import org.apache.felix.dm.lambda.FutureDependencyBuilder;
 import org.apache.felix.dm.lambda.ServiceDependencyBuilder;
 import org.apache.felix.dm.lambda.callbacks.CbComponent;
 import org.apache.felix.dm.lambda.callbacks.CbConsumer;
 import org.apache.felix.dm.lambda.callbacks.CbTypeComponent;
-import org.apache.felix.dm.lambda.callbacks.FluentProperties;
-import static org.apache.felix.dm.lambda.impl.ComponentBuilderImpl.ComponentCallback.*;
 
 public class ComponentBuilderImpl implements ComponentBuilder<ComponentBuilderImpl> {
     private final List<DependencyBuilder<?>> m_dependencyBuilders = new ArrayList<>();



Mime
View raw message