aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject svn commit: r1802373 - in /aries/trunk/component-dsl: component-dsl/src/main/java/org/apache/aries/osgi/functional/ component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/ itests/src/main/java/org/apache/aries/osgi/functional/test/
Date Wed, 19 Jul 2017 10:49:03 GMT
Author: csierra
Date: Wed Jul 19 10:49:03 2017
New Revision: 1802373

URL: http://svn.apache.org/viewvc?rev=1802373&view=rev
Log:
Simplify distribute into all

Added:
    aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/DistributeOSGi.java
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
    aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/ComponentTest.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=1802373&r1=1802372&r2=1802373&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
Wed Jul 19 10:49:03 2017
@@ -28,6 +28,7 @@ import org.apache.aries.osgi.functional.
 import org.apache.aries.osgi.functional.internal.ChangeContextOSGiImpl;
 import org.apache.aries.osgi.functional.internal.ConfigurationOSGiImpl;
 import org.apache.aries.osgi.functional.internal.ConfigurationsOSGiImpl;
+import org.apache.aries.osgi.functional.internal.DistributeOSGi;
 import org.apache.aries.osgi.functional.internal.JustOSGiImpl;
 import org.apache.aries.osgi.functional.internal.NothingOSGiImpl;
 import org.apache.aries.osgi.functional.internal.OnCloseOSGiImpl;
@@ -162,9 +163,11 @@ public interface OSGi<T> extends OSGiRun
 		return new ServiceReferenceOSGi<>(filterString, clazz);
 	}
 
-	OSGi<T> filter(Predicate<T> predicate);
+	static OSGi<Void> all(OSGi<?> ... programs) {
+		return new DistributeOSGi(programs);
+	}
 
-	OSGi<Void> distribute(Function<T, OSGi<?>>... funs);
+	OSGi<T> filter(Predicate<T> predicate);
 
 	OSGi<T> route(Consumer<Router<T>> routerConsumer);
 

Added: aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/DistributeOSGi.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/DistributeOSGi.java?rev=1802373&view=auto
==============================================================================
--- aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/DistributeOSGi.java
(added)
+++ aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/DistributeOSGi.java
Wed Jul 19 10:49:03 2017
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
+ * <p>
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * <p>
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ */
+
+package org.apache.aries.osgi.functional.internal;
+
+import org.apache.aries.osgi.functional.OSGi;
+import org.apache.aries.osgi.functional.OSGiResult;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * @author Carlos Sierra Andrés
+ */
+public class DistributeOSGi extends OSGiImpl<Void> {
+
+    public DistributeOSGi(OSGi<?>... programs) {
+        super(bundleContext -> {
+            Pipe<Tuple<Void>, Tuple<Void>> added = Pipe.create();
+
+            Consumer<Tuple<Void>> addedSource = added.getSource();
+
+            List<OSGiResult<?>> results = new ArrayList<>();
+
+            Pipe<Tuple<Void>, Tuple<Void>> removed = Pipe.create();
+
+            Consumer<Tuple<Void>> removedSource = removed.getSource();
+
+            return new OSGiResultImpl<>(
+                added, removed,
+                () -> {
+                    results.addAll(
+                        Arrays.stream(programs).
+                            map(o -> o.run(bundleContext)).
+                            collect(Collectors.toList()));
+
+                    addedSource.accept(Tuple.create(null));
+                },
+                () -> {
+                    removedSource.accept(Tuple.create(null));
+
+                    results.forEach(OSGiResult::close);
+                }
+            );
+        });
+    }
+}

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=1802373&r1=1802372&r2=1802373&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
Wed Jul 19 10:49:03 2017
@@ -279,66 +279,6 @@ public class OSGiImpl<T> implements OSGi
 		}));
 	}
 
-	@Override
-	@SafeVarargs
-	final public OSGi<Void> distribute(Function<T, OSGi<?>>... funs) {
-		return new OSGiImpl<>(bundleContext -> {
-			Pipe<Tuple<Void>, Tuple<Void>> added = Pipe.create();
-
-			Consumer<Tuple<Void>> addedSource = added.getSource();
-
-			IdentityHashMap<Object, List<OSGiResult<?>>> results =
-				new IdentityHashMap<>();
-
-			Pipe<Tuple<Void>, Tuple<Void>> removed = Pipe.create();
-
-			Consumer<Tuple<Void>> removedSource = removed.getSource();
-
-			AtomicReference<OSGiResult<?>> atomicReference =
-				new AtomicReference<>();
-
-			return new OSGiResultImpl<>(
-				added, removed,
-				() -> {
-					OSGiResultImpl<T> osgiResult = _operation.run(
-						bundleContext);
-
-					osgiResult.added.map(t -> {
-						results.put(
-							t.original,
-							Arrays.stream(funs).
-								map(f -> f.apply(t.t)).
-								map(o -> o.run(bundleContext)).
-								collect(Collectors.toList())
-						);
-
-						addedSource.accept(Tuple.create(null));
-
-						return null;
-					});
-
-					osgiResult.removed.map(t -> {
-						results.get(t.original).forEach(OSGiResult::close);
-
-						removedSource.accept(Tuple.create(null));
-
-						return null;
-					});
-
-					osgiResult.start.run();
-
-					atomicReference.set(osgiResult);
-				},
-				() -> {
-					results.values().forEach(
-						l -> l.forEach(OSGiResult::close));
-
-					atomicReference.get().close();
-				}
-			);
-		});
-	}
-
 	private static class Pair<X, Y> {
 		private final X _first;
 		private final Y _second;

Modified: aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/ComponentTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/ComponentTest.java?rev=1802373&r1=1802372&r2=1802373&view=diff
==============================================================================
--- aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/ComponentTest.java
(original)
+++ aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/ComponentTest.java
Wed Jul 19 10:49:03 2017
@@ -42,6 +42,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.function.Consumer;
 
+import static org.apache.aries.osgi.functional.OSGi.all;
 import static org.apache.aries.osgi.functional.OSGi.apply;
 import static org.apache.aries.osgi.functional.OSGi.bundleContext;
 import static org.apache.aries.osgi.functional.OSGi.configurations;
@@ -84,14 +85,15 @@ public class ComponentTest {
             configurations("org.components.MyComponent").flatMap(props ->
             services(Service.class).flatMap(ms ->
             just(new Component(props, ms)).flatMap(component ->
-            register(Component.class, component, new HashMap<>()).distribute(
-            ign -> dynamic(
-                highestService(ServiceOptional.class),
-                component::setOptional, c -> component.setOptional(null)),
-            ign -> dynamic(
-                services(ServiceForList.class),
-                component::addService, component::removeService)
-        ))));
+            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);
@@ -203,14 +205,15 @@ public class ComponentTest {
                 services(Service.class)).
                 flatMap(
                     comp ->
-                register(Component.class, comp, new HashMap<>()).distribute(
-                    ign -> dynamic(
-                        highestService(ServiceOptional.class),
-                        comp::setOptional, c -> comp.setOptional(null)),
-                    ign -> dynamic(
-                        services(ServiceForList.class),
-                        comp::addService, comp::removeService)
-                ));
+                register(Component.class, comp, new HashMap<>()).then(
+                    all(
+                        dynamic(
+                            highestService(ServiceOptional.class),
+                            comp::setOptional, c -> comp.setOptional(null)),
+                        dynamic(
+                            services(ServiceForList.class),
+                            comp::addService, comp::removeService)
+                )));
 
         ServiceTracker<Component, Component> serviceTracker =
             new ServiceTracker<>(_bundleContext, Component.class, null);



Mime
View raw message