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

removed AnalysisConfigurationTest

removed StageLists from AnalysisConfiguration and adapted Analysis and
corresponding tests
parent be471aa0
No related branches found
No related tags found
No related merge requests found
...@@ -28,20 +28,22 @@ public class Analysis implements UncaughtExceptionHandler { ...@@ -28,20 +28,22 @@ public class Analysis implements UncaughtExceptionHandler {
} }
public void init() { public void init() {
for (Stage stage : this.configuration.getConsumerStages()) { List<Stage> threadableStageJobs = this.configuration.getThreadableStageJobs();
for (Stage stage : threadableStageJobs) {
Thread thread = new Thread(new RunnableStage(stage)); Thread thread = new Thread(new RunnableStage(stage));
this.consumerThreads.add(thread); switch (stage.getTerminationStrategy()) {
} case BY_SIGNAL:
this.consumerThreads.add(thread);
for (Stage stage : this.configuration.getFiniteProducerStages()) { break;
Thread thread = new Thread(new RunnableStage(stage)); case BY_SELF_DECISION:
this.finiteProducerThreads.add(thread); this.finiteProducerThreads.add(thread);
break;
case BY_INTERRUPT:
this.infiniteProducerThreads.add(thread);
break;
}
} }
for (Stage stage : this.configuration.getInfiniteProducerStages()) {
Thread thread = new Thread(new RunnableStage(stage));
this.infiniteProducerThreads.add(thread);
}
} }
/** /**
......
package teetime.framework; package teetime.framework;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set;
import teetime.framework.pipe.PipeFactoryRegistry; import teetime.framework.pipe.PipeFactoryRegistry;
...@@ -11,51 +9,14 @@ public class AnalysisConfiguration { ...@@ -11,51 +9,14 @@ public class AnalysisConfiguration {
protected static final PipeFactoryRegistry PIPE_FACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE; protected static final PipeFactoryRegistry PIPE_FACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE;
private final List<Runnable> threadableStageJobs = new LinkedList<Runnable>(); private final List<Stage> threadableStageJobs = new LinkedList<Stage>();
private final Set<Stage> consumerStages = new HashSet<Stage>(); List<Stage> getThreadableStageJobs() {
private final Set<Stage> finiteProducerStages = new HashSet<Stage>(); return threadableStageJobs;
private final Set<Stage> infiniteProducerStages = new HashSet<Stage>();
Set<Stage> getConsumerStages() {
return this.consumerStages;
}
Set<Stage> getFiniteProducerStages() {
return this.finiteProducerStages;
}
Set<Stage> getInfiniteProducerStages() {
return this.infiniteProducerStages;
} }
public void addThreadableStage(final Stage stage) { public void addThreadableStage(final Stage stage) {
// wrap the stage categorization in a runnable threadableStageJobs.add(stage);
// because the termination strategy could depend on port configuration that is set later
final Runnable addThreadableStageJob = new Runnable() {
@Override
public void run() {
switch (stage.getTerminationStrategy()) {
case BY_SIGNAL:
consumerStages.add(stage);
break;
case BY_SELF_DECISION:
finiteProducerStages.add(stage);
break;
case BY_INTERRUPT:
infiniteProducerStages.add(stage);
break;
}
}
};
threadableStageJobs.add(addThreadableStageJob);
}
void init() {
for (Runnable job : threadableStageJobs) {
job.run();
}
} }
} }
...@@ -13,6 +13,7 @@ public class LoopStageAnalysisConfiguration extends AnalysisConfiguration { ...@@ -13,6 +13,7 @@ public class LoopStageAnalysisConfiguration extends AnalysisConfiguration {
IPipeFactory factory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.QUEUE_BASED, true); IPipeFactory factory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.QUEUE_BASED, true);
factory.create(countdown.getNewCountdownOutputPort(), countdown.getCountdownInputPort()); factory.create(countdown.getNewCountdownOutputPort(), countdown.getCountdownInputPort());
this.getFiniteProducerStages().add(countdown); // this.getFiniteProducerStages().add(countdown);
this.addThreadableStage(countdown);
} }
} }
...@@ -37,7 +37,8 @@ public class CipherConfiguration extends AnalysisConfiguration { ...@@ -37,7 +37,8 @@ public class CipherConfiguration extends AnalysisConfiguration {
factory.create(decomp.getOutputPort(), decrypt.getInputPort()); factory.create(decomp.getOutputPort(), decrypt.getInputPort());
factory.create(decrypt.getOutputPort(), writer.getInputPort()); factory.create(decrypt.getOutputPort(), writer.getInputPort());
this.getFiniteProducerStages().add(init); // this.getFiniteProducerStages().add(init);
this.addThreadableStage(init);
} }
} }
...@@ -43,7 +43,8 @@ public class TokenizerConfiguration extends AnalysisConfiguration { ...@@ -43,7 +43,8 @@ public class TokenizerConfiguration extends AnalysisConfiguration {
PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create(
tokenizer.getOutputPort(), counter.getInputPort()); tokenizer.getOutputPort(), counter.getInputPort());
this.getFiniteProducerStages().add(init); // this.getFiniteProducerStages().add(init);
this.addThreadableStage(init);
} }
public int getTokenCount() { public int getTokenCount() {
......
package teetime.framework;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import teetime.stage.Clock;
import teetime.stage.Counter;
import teetime.stage.InitialElementProducer;
public class AnalysisConfigurationTest {
@Test
public void checkIfCorrectAdded() {
AnalysisConfiguration config = new AnalysisConfiguration();
// Consumer -> BY_SIGNAL
Counter<String> counter = new Counter<String>();
config.addThreadableStage(counter);
// Infinite producer -> BY_INTERRUPT
Clock clock = new Clock();
config.addThreadableStage(clock);
// Finite Producer -> BY_SELF_DECISION
InitialElementProducer<Integer> producer = new InitialElementProducer<Integer>(1, 2, 3, 4);
config.addThreadableStage(producer);
config.init();
assertTrue(config.getConsumerStages().contains(counter));
assertFalse(config.getConsumerStages().contains(clock));
assertTrue(config.getInfiniteProducerStages().contains(clock));
assertTrue(config.getFiniteProducerStages().contains(producer));
}
}
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