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

moved the factory field from Execution to Configuration

parent c89ddf01
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ public abstract class AbstractCompositeStage {
private final ConfigurationContext context;
public AbstractCompositeStage() {
this.context = new ConfigurationContext();
this.context = new ConfigurationContext(this);
}
ConfigurationContext getContext() {
......
......@@ -32,14 +32,19 @@ import teetime.framework.pipe.InstantiationPipe;
*/
final class ConfigurationContext {
public static final ConfigurationContext EMPTY_CONTEXT = new ConfigurationContext();
public static final ConfigurationContext EMPTY_CONTEXT = new ConfigurationContext(null);
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationContext.class);
private ThreadService runtimeService = new ThreadService();
private final List<ConfigurationContext> childs = new ArrayList<ConfigurationContext>(); // parent-child-tree
private final AbstractCompositeStage compositeStage;
ConfigurationContext() {}
private ThreadService runtimeService;
ConfigurationContext(final AbstractCompositeStage compositeStage) {
this.compositeStage = compositeStage;
this.runtimeService = new ThreadService(compositeStage);
}
Map<Stage, String> getThreadableStages() {
return runtimeService.getThreadableStages();
......
......@@ -20,8 +20,6 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import teetime.framework.exceptionHandling.IExceptionListenerFactory;
import teetime.framework.exceptionHandling.TerminatingExceptionListenerFactory;
import teetime.framework.signal.ValidatingSignal;
import teetime.framework.validation.AnalysisNotValidException;
......@@ -45,8 +43,6 @@ public final class Execution<T extends Configuration> {
private final T configuration;
private final IExceptionListenerFactory factory;
private final boolean executionInterrupted = false;
/**
......@@ -59,30 +55,6 @@ public final class Execution<T extends Configuration> {
this(configuration, false);
}
/**
* Creates a new {@link Execution} that uses the default listener.
*
* @param configuration
* to be used for the analysis
* @param validationEnabled
* whether or not the validation should be executed
*/
public Execution(final T configuration, final boolean validationEnabled) {
this(configuration, validationEnabled, new TerminatingExceptionListenerFactory());
}
/**
* Creates a new {@link Execution} that skips validating the port connections and uses a specific listener.
*
* @param configuration
* to be used for the analysis
* @param factory
* specific listener for the exception handling
*/
public Execution(final T configuration, final IExceptionListenerFactory factory) {
this(configuration, false, factory);
}
/**
* Creates a new {@link Execution} that uses a specific listener.
*
......@@ -93,9 +65,8 @@ public final class Execution<T extends Configuration> {
* @param factory
* specific listener for the exception handling
*/
public Execution(final T configuration, final boolean validationEnabled, final IExceptionListenerFactory factory) {
public Execution(final T configuration, final boolean validationEnabled) {
this.configuration = configuration;
this.factory = factory;
if (configuration.isExecuted()) {
throw new IllegalStateException("Configuration was already executed");
}
......@@ -185,13 +156,4 @@ public final class Execution<T extends Configuration> {
return this.configuration;
}
/**
* @return
* the given ExceptionListenerFactory instance
*
* @since 2.0
*/
public IExceptionListenerFactory getExceptionListenerFactory() {
return factory;
}
}
......@@ -12,7 +12,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import teetime.framework.exceptionHandling.AbstractExceptionListener;
import teetime.framework.exceptionHandling.TerminatingExceptionListenerFactory;
import teetime.framework.signal.InitializingSignal;
import teetime.util.ThreadThrowableContainer;
import teetime.util.framework.concurrent.SignalingCounter;
......@@ -36,6 +35,13 @@ class ThreadService extends AbstractService<ThreadService> {
private final SignalingCounter runnableCounter = new SignalingCounter();
private final AbstractCompositeStage compositeStage;
public ThreadService(final AbstractCompositeStage compositeStage) {
this.compositeStage = compositeStage;
}
SignalingCounter getRunnableCounter() {
return runnableCounter;
}
......@@ -46,6 +52,7 @@ class ThreadService extends AbstractService<ThreadService> {
@Override
void initialize() {
Configuration config = (Configuration) compositeStage;
if (threadableStages.isEmpty()) {
throw new IllegalStateException("No stage was added using the addThreadableStage(..) method. Add at least one stage.");
}
......@@ -56,7 +63,7 @@ class ThreadService extends AbstractService<ThreadService> {
final Set<Stage> intraStages = traverseIntraStages(stage);
// FIXME: receive factory from config!
final AbstractExceptionListener newListener = new TerminatingExceptionListenerFactory().createInstance();
final AbstractExceptionListener newListener = config.getFactory().createInstance();
initializeIntraStages(intraStages, thread, newListener);
}
......
......@@ -30,7 +30,7 @@ public class ExceptionHandlingTest {
public ExceptionTestConfiguration newInstances() {
ExceptionTestConfiguration configuration = new ExceptionTestConfiguration();
execution = new Execution<ExceptionTestConfiguration>(configuration, new TestListenerFactory());
execution = new Execution<ExceptionTestConfiguration>(configuration);
return configuration;
}
......
......@@ -24,6 +24,8 @@ public class ExceptionTestConfiguration extends Configuration {
ExceptionTestProducerStage third;
public ExceptionTestConfiguration() {
super(new TestListenerFactory());
first = new ExceptionTestProducerStage();
second = new ExceptionTestConsumerStage();
third = new ExceptionTestProducerStage();
......
......@@ -49,8 +49,7 @@ public class DynamicMergerTest {
}
DynamicMergerTestConfig<Integer> config = new DynamicMergerTestConfig<Integer>(inputNumbers, Arrays.asList(inputActions));
Execution<DynamicMergerTestConfig<Integer>> analysis = new Execution<DynamicMergerTestConfig<Integer>>(config,
new TerminatingExceptionListenerFactory());
Execution<DynamicMergerTestConfig<Integer>> analysis = new Execution<DynamicMergerTestConfig<Integer>>(config);
analysis.executeBlocking();
......@@ -68,8 +67,7 @@ public class DynamicMergerTest {
}
DynamicMergerTestConfig<Integer> config = new DynamicMergerTestConfig<Integer>(inputNumbers, Arrays.asList(inputActions));
Execution<DynamicMergerTestConfig<Integer>> analysis = new Execution<DynamicMergerTestConfig<Integer>>(config,
new TerminatingExceptionListenerFactory());
Execution<DynamicMergerTestConfig<Integer>> analysis = new Execution<DynamicMergerTestConfig<Integer>>(config);
analysis.executeBlocking();
......@@ -90,8 +88,7 @@ public class DynamicMergerTest {
inputActions[5] = new RemovePortAction<Integer>(null);
DynamicMergerTestConfig<Integer> config = new DynamicMergerTestConfig<Integer>(inputNumbers, Arrays.asList(inputActions));
Execution<DynamicMergerTestConfig<Integer>> analysis = new Execution<DynamicMergerTestConfig<Integer>>(config,
new TerminatingExceptionListenerFactory());
Execution<DynamicMergerTestConfig<Integer>> analysis = new Execution<DynamicMergerTestConfig<Integer>>(config);
analysis.executeBlocking();
......@@ -119,6 +116,7 @@ public class DynamicMergerTest {
private final CollectorSink<T> collectorSink;
public DynamicMergerTestConfig(final List<T> elements, final List<PortAction<DynamicMerger<T>>> inputActions) {
super(new TerminatingExceptionListenerFactory());
InitialElementProducer<T> initialElementProducer = new InitialElementProducer<T>(elements);
DynamicMerger<T> merger = new DynamicMerger<T>(new BusyWaitingRoundRobinStrategy());
collectorSink = new CollectorSink<T>();
......
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