From b81b063819b776ce688395ecb3d0826bb7dd7051 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Wed, 10 Jun 2015 13:20:49 +0200 Subject: [PATCH] clean-up of the CompositeStage. All unneeded methods are now empty. --- .../framework/AbstractCompositeStage.java | 97 ++++++------------- .../framework/AnalysisConfiguration.java | 1 + 2 files changed, 31 insertions(+), 67 deletions(-) diff --git a/src/main/java/teetime/framework/AbstractCompositeStage.java b/src/main/java/teetime/framework/AbstractCompositeStage.java index e1266907..cdc59573 100644 --- a/src/main/java/teetime/framework/AbstractCompositeStage.java +++ b/src/main/java/teetime/framework/AbstractCompositeStage.java @@ -15,17 +15,12 @@ */ package teetime.framework; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; +import java.util.LinkedList; import java.util.List; -import java.util.Set; -import teetime.framework.pipe.IPipeFactory; -import teetime.framework.pipe.SingleElementPipeFactory; import teetime.framework.signal.ISignal; import teetime.framework.validation.InvalidPortConnection; +import teetime.util.Connection; /** * Represents a minimal stage that composes several other stages. @@ -39,114 +34,82 @@ import teetime.framework.validation.InvalidPortConnection; @Deprecated public abstract class AbstractCompositeStage extends Stage { - private static final IPipeFactory INTRA_PIPE_FACTORY = new SingleElementPipeFactory(); - - private final Set<Stage> containingStages = new HashSet<Stage>(); - private final Set<Stage> lastStages = new HashSet<Stage>(); + private final List<Connection> connections = new LinkedList<Connection>(); protected abstract Stage getFirstStage(); - protected final Collection<? extends Stage> getLastStages() { - return lastStages; + protected <T> void connectPorts(final OutputPort<? extends T> out, final InputPort<T> in) { + connections.add(new Connection(out, in)); } - @Override - protected final void executeStage() { - getFirstStage().executeStage(); + public List<Connection> getConnections() { + return connections; } @Override - protected final void onSignal(final ISignal signal, final InputPort<?> inputPort) { - getFirstStage().onSignal(signal, inputPort); + public final void validateOutputPorts(final List<InvalidPortConnection> invalidPortConnections) { + throw new IllegalStateException("This method must never be called"); + } @Override - protected final TerminationStrategy getTerminationStrategy() { - return getFirstStage().getTerminationStrategy(); + protected final void executeStage() { + throw new IllegalStateException("This method must never be called"); } @Override - protected final void terminate() { - getFirstStage().terminate(); + protected final void onSignal(final ISignal signal, final InputPort<?> inputPort) { + throw new IllegalStateException("This method must never be called"); } @Override - protected final boolean shouldBeTerminated() { - return getFirstStage().shouldBeTerminated(); + protected final TerminationStrategy getTerminationStrategy() { + throw new IllegalStateException("This method must never be called"); } @Override - protected final InputPort<?>[] getInputPorts() { - return getFirstStage().getInputPorts(); + protected final void terminate() { + throw new IllegalStateException("This method must never be called"); } @Override - protected OutputPort<?>[] getOutputPorts() { - List<OutputPort<?>> outputPorts = new ArrayList<OutputPort<?>>(); - for (final Stage s : getLastStages()) { - outputPorts.addAll(Arrays.asList(s.getOutputPorts())); - } - return outputPorts.toArray(new OutputPort[0]); + protected final boolean shouldBeTerminated() { + throw new IllegalStateException("This method must never be called"); } @Override public final StageState getCurrentState() { - return getFirstStage().getCurrentState(); + throw new IllegalStateException("This method must never be called"); } @Override - public final void validateOutputPorts(final List<InvalidPortConnection> invalidPortConnections) { - for (final Stage s : getLastStages()) { - s.validateOutputPorts(invalidPortConnections); - } + protected final InputPort<?>[] getInputPorts() { + throw new IllegalStateException("This method must never be called"); } @Override - final void setOwningThread(final Thread owningThread) { - getFirstStage().setOwningThread(owningThread); - super.setOwningThread(owningThread); - } - - protected <T> void connectPorts(final OutputPort<? extends T> out, final InputPort<T> in) { - INTRA_PIPE_FACTORY.create(out, in); - containingStages.add(out.getOwningStage()); - containingStages.add(in.getOwningStage()); + protected final OutputPort<?>[] getOutputPorts() { + throw new IllegalStateException("This method must never be called"); } @Override - public final Thread getOwningThread() { - return getFirstStage().getOwningThread(); + public final void onValidating(final List<InvalidPortConnection> invalidPortConnections) { + throw new IllegalStateException("This method must never be called"); } @Override public final void onInitializing() throws Exception { - getFirstStage().onInitializing(); - } - - @Override - public final void onValidating(final List<InvalidPortConnection> invalidPortConnections) { - getFirstStage().onValidating(invalidPortConnections); + throw new IllegalStateException("This method must never be called"); } @Override public final void onStarting() throws Exception { - for (Stage stage : containingStages) { - if (stage.getOutputPorts().length == 0) { - lastStages.add(stage); - break; - } - for (OutputPort<?> outputPort : stage.getOutputPorts()) { - if (!containingStages.contains(outputPort.getPipe().getTargetPort().getOwningStage())) { - lastStages.add(stage); - } - } - } - getFirstStage().onStarting(); + throw new IllegalStateException("This method must never be called"); } @Override public final void onTerminating() throws Exception { - getFirstStage().onTerminating(); + throw new IllegalStateException("This method must never be called"); } } diff --git a/src/main/java/teetime/framework/AnalysisConfiguration.java b/src/main/java/teetime/framework/AnalysisConfiguration.java index 4a4c8901..24f9bd19 100644 --- a/src/main/java/teetime/framework/AnalysisConfiguration.java +++ b/src/main/java/teetime/framework/AnalysisConfiguration.java @@ -63,6 +63,7 @@ public abstract class AnalysisConfiguration { protected void addThreadableStage(final Stage stage) { if (stage instanceof AbstractCompositeStage) { this.threadableStageJobs.add(((AbstractCompositeStage) stage).getFirstStage()); + this.connections.addAll(((AbstractCompositeStage) stage).getConnections()); } else { this.threadableStageJobs.add(stage); } -- GitLab