diff --git a/src/main/java/teetime/framework/AbstractCompositeStage.java b/src/main/java/teetime/framework/AbstractCompositeStage.java index 26e8685ef260a18ca2dcf1705cf71f98bff4ba92..07aa5c982b47eee8eafaa7d1b782409f57ab5309 100644 --- a/src/main/java/teetime/framework/AbstractCompositeStage.java +++ b/src/main/java/teetime/framework/AbstractCompositeStage.java @@ -32,11 +32,8 @@ public abstract class AbstractCompositeStage { private final ConfigurationContext context; - public AbstractCompositeStage(final ConfigurationContext context) { - if (null == context) { - throw new IllegalArgumentException("Context may not be null."); - } - this.context = context; + public AbstractCompositeStage() { + this.context = new ConfigurationContext(); } protected ConfigurationContext getContext() { diff --git a/src/main/java/teetime/framework/Configuration.java b/src/main/java/teetime/framework/Configuration.java index bfaf92150fc223a0abc6347e96cf0f812ff4488b..f97226447347bc629138231a0845a5a223aceedd 100644 --- a/src/main/java/teetime/framework/Configuration.java +++ b/src/main/java/teetime/framework/Configuration.java @@ -25,8 +25,4 @@ package teetime.framework; */ public abstract class Configuration extends AbstractCompositeStage { - public Configuration() { - super(new ConfigurationContext()); - } - } diff --git a/src/main/java/teetime/framework/ConfigurationContext.java b/src/main/java/teetime/framework/ConfigurationContext.java index 483b1ecbdb93ee23cfd9fec89906d947ba1d9787..236f4c3808d5dce6801b62cc7b62ffdfad291b76 100644 --- a/src/main/java/teetime/framework/ConfigurationContext.java +++ b/src/main/java/teetime/framework/ConfigurationContext.java @@ -29,7 +29,7 @@ import teetime.framework.pipe.InstantiationPipe; * * @since 2.0 */ -public final class ConfigurationContext { +public class ConfigurationContext { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationContext.class); @@ -63,7 +63,21 @@ public final class ConfigurationContext { LOGGER.warn("Overwriting existing pipe while connecting stages " + sourcePort.getOwningStage().getId() + " and " + targetPort.getOwningStage().getId() + "."); } + mergeContexts(sourcePort.getOwningStage(), targetPort.getOwningStage()); new InstantiationPipe(sourcePort, targetPort, capacity); } + final void mergeContexts(final Stage sourceStage, final Stage targetStage) { + if (!sourceStage.owningContext.equals(EmptyContext.getInstance())) { + this.threadableStages.putAll(sourceStage.owningContext.threadableStages); + } else { + sourceStage.owningContext = this; + } + if (!targetStage.owningContext.equals(EmptyContext.getInstance())) { + this.threadableStages.putAll(targetStage.owningContext.threadableStages); + } else { + targetStage.owningContext = this; + } + } + } diff --git a/src/main/java/teetime/framework/EmptyContext.java b/src/main/java/teetime/framework/EmptyContext.java new file mode 100644 index 0000000000000000000000000000000000000000..3a676ebc9bdc556ad474775955b4955ed9233d48 --- /dev/null +++ b/src/main/java/teetime/framework/EmptyContext.java @@ -0,0 +1,15 @@ +package teetime.framework; + +class EmptyContext extends ConfigurationContext { + + private static final EmptyContext INSTANCE = new EmptyContext(); + + private EmptyContext() { + + } + + static EmptyContext getInstance() { + return EmptyContext.INSTANCE; + } + +} diff --git a/src/main/java/teetime/framework/Stage.java b/src/main/java/teetime/framework/Stage.java index 1c9ce2e20146941636db8db2f4e19b826b8d47f8..7b9398ca6c254c464f4c28c77e80c55d9325f86a 100644 --- a/src/main/java/teetime/framework/Stage.java +++ b/src/main/java/teetime/framework/Stage.java @@ -48,6 +48,8 @@ public abstract class Stage { /** The owning thread of this stage if this stage is directly executed by a {@link AbstractRunnableStage}, <code>null</code> otherwise. */ protected Thread owningThread; + protected ConfigurationContext owningContext = EmptyContext.getInstance(); + protected Stage() { this.id = this.createId(); this.logger = LoggerFactory.getLogger(this.getClass().getCanonicalName() + ":" + id); diff --git a/src/main/java/teetime/stage/io/EveryXthPrinter.java b/src/main/java/teetime/stage/io/EveryXthPrinter.java index 6f38fbab37e218bcde981c63263513d8a993632e..4b62916d1f65cae5b08540e4ea7d5fff8bce7826 100644 --- a/src/main/java/teetime/stage/io/EveryXthPrinter.java +++ b/src/main/java/teetime/stage/io/EveryXthPrinter.java @@ -33,7 +33,6 @@ public final class EveryXthPrinter<T> extends AbstractCompositeStage { private final List<Stage> lastStages = new ArrayList<Stage>(); public EveryXthPrinter(final int threshold, final ConfigurationContext context) { - super(context); distributor = new Distributor<T>(new CopyByReferenceStrategy()); EveryXthStage<T> everyXthStage = new EveryXthStage<T>(threshold); Printer<Integer> printer = new Printer<Integer>(); diff --git a/src/main/java/teetime/stage/string/WordCounter.java b/src/main/java/teetime/stage/string/WordCounter.java index 1508c15edbf052f26a265df4253c750ef2917944..6d15a3f20f5833463f1cd3ee37bea1173edc06e7 100644 --- a/src/main/java/teetime/stage/string/WordCounter.java +++ b/src/main/java/teetime/stage/string/WordCounter.java @@ -37,7 +37,6 @@ public final class WordCounter extends AbstractCompositeStage { private final MappingCounter<String> mapCounter; public WordCounter(final ConfigurationContext context) { - super(context); this.tokenizer = new Tokenizer(" "); final ToLowerCase toLowerCase = new ToLowerCase(); diff --git a/src/site/markdown/wiki b/src/site/markdown/wiki new file mode 160000 index 0000000000000000000000000000000000000000..709c839c447a50c93b37fcc633a01297115d4823 --- /dev/null +++ b/src/site/markdown/wiki @@ -0,0 +1 @@ +Subproject commit 709c839c447a50c93b37fcc633a01297115d4823