aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject svn commit: r1784747 - in /aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional: OSGi.java internal/OSGiImpl.java
Date Tue, 28 Feb 2017 14:48:52 GMT
Author: csierra
Date: Tue Feb 28 14:48:52 2017
New Revision: 1784747

URL: http://svn.apache.org/viewvc?rev=1784747&view=rev
Log:
foreach can't be implemented in terms of map

since foreach is primarily intented for effects it is better to signal
that. Otherwise we are invoking the foreach block both when the
preceding services are added or removed, which is probably always wrong.

I leave the possibility to add a callback only when the service is
added, since there exist an onClose handler.

Modified:
    aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
    aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/OSGiImpl.java

Modified: aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java?rev=1784747&r1=1784746&r2=1784747&view=diff
==============================================================================
--- aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
(original)
+++ aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
Tue Feb 28 14:48:52 2017
@@ -54,7 +54,10 @@ public interface OSGi<T> extends OSGiRun
 
 	<S> OSGi<S> then(OSGi<S> next);
 
-	OSGi<Void> foreach(Consumer<? super T> action);
+	OSGi<Void> foreach(Consumer<? super T> onAdded);
+
+	OSGi<Void> foreach(
+		Consumer<? super T> onAdded, Consumer<? super T> onRemoved);
 
 	static OSGi<BundleContext> bundleContext() {
 

Modified: aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/OSGiImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/OSGiImpl.java?rev=1784747&r1=1784746&r2=1784747&view=diff
==============================================================================
--- aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/OSGiImpl.java
(original)
+++ aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/OSGiImpl.java
Tue Feb 28 14:48:52 2017
@@ -108,8 +108,24 @@ public class OSGiImpl<T> implements OSGi
 	}
 
 	@Override
-	public OSGi<Void> foreach(Consumer<? super T> consumer) {
-		return this.map(f ->  {consumer.accept(f); return null;});
+	public OSGi<Void> foreach(Consumer<? super T> onAdded) {
+		return foreach(onAdded, ign -> {});
+	}
+
+	@Override
+	public OSGi<Void> foreach(
+		Consumer<? super T> onAdded, Consumer<? super T> onRemoved) {
+
+		return new OSGiImpl<>(((bundleContext) -> {
+			OSGiResultImpl<T> osgiResult = _operation.run(bundleContext);
+
+			return new OSGiResultImpl<>(
+				osgiResult.added.map(
+					t -> t.map(o -> {onAdded.accept(o); return null;})),
+				osgiResult.removed.map(
+					t -> t.map(o -> {onRemoved.accept(o); return null;})),
+				osgiResult.start, osgiResult.close);
+		}));
 	}
 
 	@Override



Mime
View raw message