You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2020/05/14 17:30:06 UTC

[aries-component-dsl] branch master updated (3328177 -> 0787a70)

This is an automated email from the ASF dual-hosted git repository.

csierra pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git.


    from 3328177  [ARIES-Component-DSL][maven-release-plugin] 1.2.2 prepare for next development iteration
     new 32213bd  Fix applyTo
     new 144a204  Use combine in the test instead of flatMap
     new 0787a70  Add test for new applyTo fix

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/aries/component/dsl/OSGi.java  | 98 ++++++++++++----------
 .../aries/component/dsl/test/ComponentTest.java    | 36 ++++----
 .../apache/aries/component/dsl/test/DSLTest.java   | 50 ++++++++---
 3 files changed, 107 insertions(+), 77 deletions(-)


[aries-component-dsl] 02/03: Use combine in the test instead of flatMap

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git

commit 144a2045fdba1b7bfd76c88b72b3d161b5478aaa
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Thu May 14 18:53:10 2020 +0200

    Use combine in the test instead of flatMap
    
    it is more appropiate in this context
---
 .../aries/component/dsl/test/ComponentTest.java    | 36 +++++++++-------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/itests/src/main/java/org/apache/aries/component/dsl/test/ComponentTest.java b/itests/src/main/java/org/apache/aries/component/dsl/test/ComponentTest.java
index 4a40d03..d2ae68e 100644
--- a/itests/src/main/java/org/apache/aries/component/dsl/test/ComponentTest.java
+++ b/itests/src/main/java/org/apache/aries/component/dsl/test/ComponentTest.java
@@ -43,15 +43,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.function.Consumer;
 
-import static org.apache.aries.component.dsl.OSGi.all;
-import static org.apache.aries.component.dsl.OSGi.bundleContext;
-import static org.apache.aries.component.dsl.OSGi.combine;
-import static org.apache.aries.component.dsl.OSGi.configurations;
-import static org.apache.aries.component.dsl.OSGi.just;
-import static org.apache.aries.component.dsl.OSGi.onClose;
-import static org.apache.aries.component.dsl.OSGi.register;
-import static org.apache.aries.component.dsl.OSGi.serviceReferences;
-import static org.apache.aries.component.dsl.OSGi.services;
+import static org.apache.aries.component.dsl.OSGi.*;
 import static org.apache.aries.component.dsl.Utils.highest;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -84,18 +76,20 @@ public class ComponentTest {
     @Test
     public void testComponent() throws IOException {
         OSGi<?> program =
-            configurations("org.components.MyComponent").flatMap(props ->
-            services(Service.class).flatMap(ms ->
-            just(new Component(props, ms)).flatMap(component ->
-            register(Component.class, component, new HashMap<>()).then(
-            all(
-                dynamic(
-                    highestService(ServiceOptional.class),
-                    component::setOptional, c -> component.setOptional(null)),
-                dynamic(
-                    services(ServiceForList.class),
-                    component::addService, component::removeService)
-        )))));
+            combine(
+                Component::new,
+                configurations("org.components.MyComponent"),
+                services(Service.class))
+            .flatMap(component ->
+                register(Component.class, component, new HashMap<>()).then(
+                all(
+                    dynamic(
+                        highestService(ServiceOptional.class),
+                        component::setOptional, c -> component.setOptional(null)),
+                    dynamic(
+                        services(ServiceForList.class),
+                        component::addService, component::removeService)
+            )));
 
         ServiceTracker<Component, Component> serviceTracker =
             new ServiceTracker<>(_bundleContext, Component.class, null);


[aries-component-dsl] 01/03: Fix applyTo

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git

commit 32213bd0cbb93555a3232fa6f52c99ad2af1a4b4
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Thu May 14 18:51:14 2020 +0200

    Fix applyTo
    
    it left some terminators unclosed.
---
 .../java/org/apache/aries/component/dsl/OSGi.java  | 98 ++++++++++++----------
 1 file changed, 53 insertions(+), 45 deletions(-)

diff --git a/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java b/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java
index 0d20246..ac55128 100644
--- a/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java
+++ b/component-dsl/src/main/java/org/apache/aries/component/dsl/OSGi.java
@@ -68,15 +68,7 @@ import org.osgi.framework.ServiceObjects;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.BiFunction;
@@ -496,56 +488,72 @@ public interface OSGi<T> extends OSGiRunnable<T> {
 
 	default  <S> OSGi<S> applyTo(OSGi<Function<T, S>> fun) {
 		return fromOsgiRunnable((bundleContext, op) -> {
-			ConcurrentDoublyLinkedList<T> identities =
-				new ConcurrentDoublyLinkedList<>();
+			ConcurrentDoublyLinkedList<T> identities = new ConcurrentDoublyLinkedList<>();
+			ConcurrentDoublyLinkedList<Function<T,S>> functions = new ConcurrentDoublyLinkedList<>();
+			IdentityHashMap<T, IdentityHashMap<Function<T, S>, Runnable>>
+				terminators = new IdentityHashMap<>();
 
-			ConcurrentDoublyLinkedList<Function<T, S>> funs =
-				new ConcurrentDoublyLinkedList<>();
-
-			OSGiResult myResult = run(
+			OSGiResult funRun = fun.run(
 				bundleContext,
-				t -> {
-					ConcurrentDoublyLinkedList.Node node =
-						identities.addLast(t);
+				f -> {
+					synchronized(identities) {
+						ConcurrentDoublyLinkedList.Node node = functions.addLast(f);
+
+						for (T t : identities) {
+							IdentityHashMap<Function<T, S>, Runnable> terminatorMap =
+								terminators.computeIfAbsent(
+									t, __ -> new IdentityHashMap<>());
+							terminatorMap.put(f, op.apply(f.apply(t)));
+						}
 
-					List<Runnable> terminators = funs.stream().map(
-						f -> op.apply(f.apply(t))
-					).collect(
-						Collectors.toList()
-					);
+						return () -> {
+							synchronized (identities) {
+								node.remove();
 
-					return () -> {
-						node.remove();
+								identities.forEach(t -> {
+									Runnable terminator = terminators.get(t).remove(f);
 
-						terminators.forEach(Runnable::run);
-					};
+									terminator.run();
+								});
+							}
+						};
+					}
 				}
 			);
 
-			OSGiResult funRun = fun.run(
+			OSGiResult myRun = run(
 				bundleContext,
-				f -> {
-					ConcurrentDoublyLinkedList.Node node = funs.addLast(f);
+				t -> {
+					synchronized (identities) {
+						ConcurrentDoublyLinkedList.Node node = identities.addLast(t);
+
+						for (Function<T, S> f : functions) {
+							IdentityHashMap<Function<T, S>, Runnable> terminatorMap =
+								terminators.computeIfAbsent(
+									t, __ -> new IdentityHashMap<>());
+							terminatorMap.put(f, op.apply(f.apply(t)));
+						}
 
-					List<Runnable> terminators = identities.stream().map(
-						t -> op.apply(f.apply(t))
-					).collect(
-						Collectors.toList()
-					);
+						return () -> {
+							synchronized (identities) {
+								node.remove();
 
-					return () -> {
-						node.remove();
+								functions.forEach(f -> {
+									Runnable terminator = terminators.get(t).remove(f);
 
-						terminators.forEach(Runnable::run);
-					};
-				});
+									terminator.run();
+								});
+							}
+						};
+					}
+				}
+			);
 
-			return
-				() -> {
-					myResult.close();
+			return () -> {
+				myRun.close();
 
-					funRun.close();
-				};
+				funRun.close();
+			};
 		});
 	}
 


[aries-component-dsl] 03/03: Add test for new applyTo fix

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git

commit 0787a70a68077ddadc4c2d4a830ab04ee4fa2350
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Thu May 14 18:55:36 2020 +0200

    Add test for new applyTo fix
---
 .../apache/aries/component/dsl/test/DSLTest.java   | 50 +++++++++++++++++-----
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java b/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
index a5cf8df..6fed6bf 100644
--- a/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
+++ b/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
@@ -51,17 +51,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
-import static org.apache.aries.component.dsl.OSGi.NOOP;
-import static org.apache.aries.component.dsl.OSGi.coalesce;
-import static org.apache.aries.component.dsl.OSGi.configuration;
-import static org.apache.aries.component.dsl.OSGi.configurations;
-import static org.apache.aries.component.dsl.OSGi.just;
-import static org.apache.aries.component.dsl.OSGi.nothing;
-import static org.apache.aries.component.dsl.OSGi.onClose;
-import static org.apache.aries.component.dsl.OSGi.once;
-import static org.apache.aries.component.dsl.OSGi.register;
-import static org.apache.aries.component.dsl.OSGi.serviceReferences;
-import static org.apache.aries.component.dsl.OSGi.services;
+import static org.apache.aries.component.dsl.OSGi.*;
 import static org.apache.aries.component.dsl.Utils.accumulate;
 import static org.apache.aries.component.dsl.Utils.highest;
 import static org.junit.Assert.assertEquals;
@@ -236,6 +226,44 @@ public class DSLTest {
     }
 
     @Test
+    public void testCombine() {
+        List<Integer> list = new ArrayList<>();
+
+        ProbeImpl<Integer> probe1 = new ProbeImpl<>();
+        ProbeImpl<Integer> probe2 = new ProbeImpl<>();
+
+        OSGi<Integer> program = combine(
+            (x, y) -> x * y, probe1, probe2
+        ).effects(
+            list::add, list::remove
+        );
+
+        OSGiResult run = program.run(bundleContext);
+
+        Publisher<? super Integer> publisher1 = probe1.getPublisher();
+        Publisher<? super Integer> publisher2 = probe2.getPublisher();
+
+        OSGiResult osgiResult1 = publisher1.publish(3);
+        OSGiResult osgiResult2 = publisher2.publish(5);
+
+        assertTrue(list.contains(15));
+
+        osgiResult1.close();
+
+        assertFalse(list.contains(15));
+
+        publisher1.publish(3);
+
+        assertTrue(list.contains(15));
+
+        osgiResult2.close();
+
+        assertFalse(list.contains(15));
+
+        run.close();
+    }
+
+    @Test
     public void testEffectsOrder() {
         ArrayList<Object> effects = new ArrayList<>();