Skip to content
Snippets Groups Projects
Commit 5a2a268c authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

removed empty context

parent aa9edb16
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ public abstract class AbstractCompositeStage { ...@@ -36,7 +36,7 @@ public abstract class AbstractCompositeStage {
this.context = new ConfigurationContext(); this.context = new ConfigurationContext();
} }
protected ConfigurationContext getContext() { ConfigurationContext getContext() {
return context; return context;
} }
......
...@@ -29,7 +29,9 @@ import teetime.framework.pipe.InstantiationPipe; ...@@ -29,7 +29,9 @@ import teetime.framework.pipe.InstantiationPipe;
* *
* @since 2.0 * @since 2.0
*/ */
public class ConfigurationContext { final class ConfigurationContext {
public static final ConfigurationContext EMPTY_CONTEXT = new ConfigurationContext();
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationContext.class); private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationContext.class);
...@@ -70,7 +72,7 @@ public class ConfigurationContext { ...@@ -70,7 +72,7 @@ public class ConfigurationContext {
} }
final void mergeContexts(final Stage stage) { final void mergeContexts(final Stage stage) {
if (!stage.owningContext.equals(EmptyContext.getInstance())) { if (!stage.owningContext.equals(EMPTY_CONTEXT)) {
if (stage.owningContext != this) { // Performance if (stage.owningContext != this) { // Performance
this.threadableStages.putAll(stage.owningContext.threadableStages); this.threadableStages.putAll(stage.owningContext.threadableStages);
stage.owningContext.threadableStages = this.threadableStages; stage.owningContext.threadableStages = this.threadableStages;
......
package teetime.framework;
class EmptyContext extends ConfigurationContext {
private static final EmptyContext INSTANCE = new EmptyContext();
private EmptyContext() {
}
static EmptyContext getInstance() {
return EmptyContext.INSTANCE;
}
}
...@@ -48,7 +48,7 @@ public abstract class Stage { ...@@ -48,7 +48,7 @@ public abstract class Stage {
/** The owning thread of this stage if this stage is directly executed by a {@link AbstractRunnableStage}, <code>null</code> otherwise. */ /** The owning thread of this stage if this stage is directly executed by a {@link AbstractRunnableStage}, <code>null</code> otherwise. */
protected Thread owningThread; protected Thread owningThread;
public ConfigurationContext owningContext = EmptyContext.getInstance(); public ConfigurationContext owningContext = ConfigurationContext.EMPTY_CONTEXT;
protected Stage() { protected Stage() {
this.id = this.createId(); this.id = this.createId();
......
...@@ -19,7 +19,6 @@ import java.util.ArrayList; ...@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import teetime.framework.AbstractCompositeStage; import teetime.framework.AbstractCompositeStage;
import teetime.framework.ConfigurationContext;
import teetime.framework.InputPort; import teetime.framework.InputPort;
import teetime.framework.OutputPort; import teetime.framework.OutputPort;
import teetime.framework.Stage; import teetime.framework.Stage;
...@@ -32,7 +31,7 @@ public final class EveryXthPrinter<T> extends AbstractCompositeStage { ...@@ -32,7 +31,7 @@ public final class EveryXthPrinter<T> extends AbstractCompositeStage {
private final Distributor<T> distributor; private final Distributor<T> distributor;
private final List<Stage> lastStages = new ArrayList<Stage>(); private final List<Stage> lastStages = new ArrayList<Stage>();
public EveryXthPrinter(final int threshold, final ConfigurationContext context) { public EveryXthPrinter(final int threshold) {
distributor = new Distributor<T>(new CopyByReferenceStrategy()); distributor = new Distributor<T>(new CopyByReferenceStrategy());
EveryXthStage<T> everyXthStage = new EveryXthStage<T>(threshold); EveryXthStage<T> everyXthStage = new EveryXthStage<T>(threshold);
Printer<Integer> printer = new Printer<Integer>(); Printer<Integer> printer = new Printer<Integer>();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package teetime.stage.string; package teetime.stage.string;
import teetime.framework.AbstractCompositeStage; import teetime.framework.AbstractCompositeStage;
import teetime.framework.ConfigurationContext;
import teetime.framework.InputPort; import teetime.framework.InputPort;
import teetime.framework.OutputPort; import teetime.framework.OutputPort;
import teetime.stage.MappingCounter; import teetime.stage.MappingCounter;
...@@ -36,7 +35,7 @@ public final class WordCounter extends AbstractCompositeStage { ...@@ -36,7 +35,7 @@ public final class WordCounter extends AbstractCompositeStage {
private final Tokenizer tokenizer; private final Tokenizer tokenizer;
private final MappingCounter<String> mapCounter; private final MappingCounter<String> mapCounter;
public WordCounter(final ConfigurationContext context) { public WordCounter() {
this.tokenizer = new Tokenizer(" "); this.tokenizer = new Tokenizer(" ");
final ToLowerCase toLowerCase = new ToLowerCase(); final ToLowerCase toLowerCase = new ToLowerCase();
......
...@@ -77,7 +77,7 @@ public class TraversorTest { ...@@ -77,7 +77,7 @@ public class TraversorTest {
// Middle part... multiple instances of WordCounter are created and connected to the merger and distrubuter stages // Middle part... multiple instances of WordCounter are created and connected to the merger and distrubuter stages
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
// final InputPortSizePrinter<String> inputPortSizePrinter = new InputPortSizePrinter<String>(); // final InputPortSizePrinter<String> inputPortSizePrinter = new InputPortSizePrinter<String>();
final WordCounter wc = new WordCounter(this.getContext()); final WordCounter wc = new WordCounter();
// intraFact.create(inputPortSizePrinter.getOutputPort(), wc.getInputPort()); // intraFact.create(inputPortSizePrinter.getOutputPort(), wc.getInputPort());
connectPorts(distributor.getNewOutputPort(), wc.getInputPort()); connectPorts(distributor.getNewOutputPort(), wc.getInputPort());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment