[java-metadata-aggregator] 02/02: MDA-276 - Unify SimplePipeline and CompositeStage

Ian Young ian at iay.org.uk
Wed Mar 29 15:21:50 UTC 2023


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch main
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=55c291cfde8e1d93835480222e5dbc17bf2a1289

commit 55c291cfde8e1d93835480222e5dbc17bf2a1289
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Wed Mar 29 15:45:38 2023 +0100

    MDA-276 - Unify SimplePipeline and CompositeStage
    
    https://shibboleth.atlassian.net/browse/MDA-276
---
 .../metadata/pipeline/CompositeStage.java          | 63 +++++++++++++++++++---
 .../metadata/pipeline/SimplePipeline.java          | 54 +------------------
 .../metadata/pipeline/CompositeStageTest.java      | 25 +++++++--
 .../metadata/pipeline/SimplePipelineTest.java      |  6 +--
 4 files changed, 81 insertions(+), 67 deletions(-)

diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/CompositeStage.java b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/CompositeStage.java
index 2497a3b..5845989 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/CompositeStage.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/CompositeStage.java
@@ -26,28 +26,36 @@ import javax.annotation.concurrent.ThreadSafe;
 import net.shibboleth.metadata.Item;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.primitive.DeprecationSupport;
+import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
 
 /**
  * A stage that is composed of other stages. This allows a collection of stages to be grouped together and for that
  * composition to the be referenced and reused.
- * 
+ *
+ * <p>
+ * Provides a simple implementation of the {@link Pipeline<T>} interface.
+ * </p>
+ *
  * @param <T> type of metadata this stage, and its composed stages, operate upon
  */
 @ThreadSafe
-public class CompositeStage<T> extends AbstractStage<T> {
+public class CompositeStage<T> extends AbstractStage<T> implements Pipeline<T> {
 
     /** Stages which compose this stage. */
     @Nonnull @NonnullElements @Unmodifiable @GuardedBy("this")
     private List<Stage<T>> composedStages = List.of();
 
-
     /**
      * Gets an unmodifiable list of the stages that compose this stage.
      * 
      * @return list the stages that compose this stage, never null nor containing null elements
+     *
+     * @since 0.10.0
      */
     @Nonnull @NonnullElements @Unmodifiable
-    public final synchronized List<Stage<T>> getComposedStages() {
+    public final synchronized List<Stage<T>> getStages() {
         return composedStages;
     }
 
@@ -55,19 +63,62 @@ public class CompositeStage<T> extends AbstractStage<T> {
      * Sets the list of stages that compose this stage.
      * 
      * @param stages list of the stages that compose this stage
+     *
+     * @since 0.10.0
      */
-    public synchronized void setComposedStages(
+    public final synchronized void setStages(
             @Nonnull @NonnullElements @Unmodifiable final List<Stage<T>> stages) {
         checkSetterPreconditions();
         composedStages = List.copyOf(stages);
     }
 
+    /**
+     * Gets an unmodifiable list of the stages that compose this stage.
+     * 
+     * @return list the stages that compose this stage, never null nor containing null elements
+     *
+     * @deprecated Replaced by {@link #getStages}.
+     * @see #getStages
+     */
+    @Deprecated(since="0.10.0", forRemoval=true)
+    @Nonnull @NonnullElements @Unmodifiable
+    public final List<Stage<T>> getComposedStages() {
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "getComposedStages", "CompositeStage", "getStages");
+        return getStages();
+    }
+
+    /**
+     * Sets the list of stages that compose this stage.
+     * 
+     * @param stages list of the stages that compose this stage
+     *
+     * @deprecated Replaced by {@link setStages}.
+     * @see #setStages
+     */
+    @Deprecated(since="0.10.0", forRemoval=true)
+    public final void setComposedStages(
+            @Nonnull @NonnullElements @Unmodifiable final List<Stage<T>> stages) {
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "setComposedStages", "CompositeStage", "setStages");
+        setStages(stages);
+    }
+
     @Override
     protected void doExecute(@Nonnull @NonnullElements final List<Item<T>> items)
             throws StageProcessingException {
-        for (final Stage<T> stage : getComposedStages()) {
+        for (final Stage<T> stage : getStages()) {
             stage.execute(items);
         }
     }
 
+    @Override
+    protected synchronized void doInitialize() throws ComponentInitializationException {
+        super.doInitialize();
+
+        for (final Stage<T> stage : composedStages) {
+            if (!stage.isInitialized()) {
+                stage.initialize();
+            }
+        }
+    }
+
 }
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/SimplePipeline.java b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/SimplePipeline.java
index 7dee36e..f70e19a 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/SimplePipeline.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/SimplePipeline.java
@@ -17,66 +17,14 @@
 
 package net.shibboleth.metadata.pipeline;
 
-import java.util.Collections;
-import java.util.List;
-
-import javax.annotation.Nonnull;
-import javax.annotation.concurrent.GuardedBy;
 import javax.annotation.concurrent.ThreadSafe;
 
-import net.shibboleth.metadata.Item;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
-import net.shibboleth.shared.annotation.constraint.Unmodifiable;
-import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
-import net.shibboleth.shared.component.ComponentInitializationException;
-
 /**
  * A very simple implementation of {@link Pipeline}.
  * 
  * @param <T> the type of item upon which this stage operates
  */
 @ThreadSafe
-public class SimplePipeline<T> extends AbstractIdentifiableInitializableComponent
-        implements Pipeline<T> {
-
-    /** Stages for this pipeline. */
-    @Nonnull @NonnullElements @GuardedBy("this")
-    private List<Stage<T>> pipelineStages = Collections.emptyList();
-
-    @Override
-    @Nonnull @NonnullElements @Unmodifiable
-    public final synchronized List<Stage<T>> getStages() {
-        return pipelineStages;
-    }
-
-    /**
-     * Sets the stages that make up this pipeline.
-     * 
-     * @param stages stages that make up this pipeline
-     */
-    public synchronized void setStages(
-            @Nonnull @NonnullElements @Unmodifiable final List<Stage<T>> stages) {
-        checkSetterPreconditions();
-        pipelineStages = List.copyOf(stages);
-    }
-
-    @Override
-    public void execute(@Nonnull @NonnullElements final List<Item<T>> items)
-            throws PipelineProcessingException {
-
-        for (final Stage<T> stage : getStages()) {
-            stage.execute(items);
-        }
-    }
-
-    @Override
-    protected synchronized void doInitialize() throws ComponentInitializationException {
-        super.doInitialize();
+public class SimplePipeline<T> extends CompositeStage<T> {
 
-        for (final Stage<T> stage : pipelineStages) {
-            if (!stage.isInitialized()) {
-                stage.initialize();
-            }
-        }
-    }
 }
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java
index 283e7d4..7f8be95 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java
@@ -17,7 +17,7 @@ public class CompositeStageTest {
         final var stage = new CompositeStage<String>();
         stage.setId("test");
         stage.initialize();
-        Assert.assertEquals(stage.getComposedStages().size(), 0);
+        Assert.assertEquals(stage.getStages().size(), 0);
         
         final var items = List.<Item<String>>of(new MockItem("hello"));
         stage.execute(items);
@@ -34,9 +34,9 @@ public class CompositeStageTest {
 
         final var stage = new CompositeStage<String>();
         stage.setId("test");
-        stage.setComposedStages(List.of(marker));
+        stage.setStages(List.of(marker));
         stage.initialize();
-        Assert.assertEquals(stage.getComposedStages().size(), 1);
+        Assert.assertEquals(stage.getStages().size(), 1);
 
         final var items = List.<Item<String>>of(new MockItem("hello"));
         stage.execute(items);
@@ -53,9 +53,9 @@ public class CompositeStageTest {
 
         final var stage = new CompositeStage<String>();
         stage.setId("test");
-        stage.setComposedStages(List.of(marker, marker));
+        stage.setStages(List.of(marker, marker));
         stage.initialize();
-        Assert.assertEquals(stage.getComposedStages().size(), 2);
+        Assert.assertEquals(stage.getStages().size(), 2);
 
         final var items = List.<Item<String>>of(new MockItem("hello"));
         stage.execute(items);
@@ -72,4 +72,19 @@ public class CompositeStageTest {
         stage.destroy();
     }
 
+    @Test
+    public void testDeprecatedMethods() throws Exception {
+        final var marker = new MarkerStage<String>();
+        marker.setId("marker");
+        marker.initialize();
+
+        final var stage = new CompositeStage<String>();
+        stage.setId("test");
+        Assert.assertEquals(stage.getComposedStages().size(), 0);
+
+        stage.setComposedStages(List.of(marker));
+        Assert.assertEquals(stage.getStages().size(), 1);
+
+        stage.destroy();
+    }
 }
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java
index 3d4c8eb..3dc5996 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java
@@ -20,6 +20,8 @@ package net.shibboleth.metadata.pipeline;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.annotation.Nonnull;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.MockItem;
 import net.shibboleth.shared.component.ComponentInitializationException;
@@ -88,8 +90,6 @@ public class SimplePipelineTest {
         Assert.assertEquals(((CountingStage<String>) stages.get(1)).getInvocationCount(), 1);
         Assert.assertEquals(((CountingStage<String>) stages.get(2)).getInvocationCount(), 1);
 
-        Item<String> md = metadata.iterator().next();
-
         try {
             List<Stage<String>> pipelineStages = pipeline.getStages();
             pipelineStages.clear();
@@ -106,7 +106,7 @@ public class SimplePipelineTest {
         pipeline.destroy();
     }
 
-    protected List<Stage<String>> buildStages() {
+    protected @Nonnull List<Stage<String>> buildStages() {
         final Item<String> md1 = new MockItem("one");
         final Item<String> md2 = new MockItem("two");
         final List<Item<String>> items = new ArrayList<>();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list