diff --git a/src/main/java/teetime/framework/A4StageAttributeSetter.java b/src/main/java/teetime/framework/A4StageAttributeSetter.java index 3b57d5eb50abbdf6aeb7225b0759698383755485..5d95bec9e2dbc4a3e0c813cc9a3d303407c3de0a 100644 --- a/src/main/java/teetime/framework/A4StageAttributeSetter.java +++ b/src/main/java/teetime/framework/A4StageAttributeSetter.java @@ -46,7 +46,7 @@ class A4StageAttributeSetter { } private void setAttributes(final Stage threadableStage, final Set<Stage> intraStages) { - threadableStage.setExceptionHandler(configuration.getFactory().createInstance()); + threadableStage.setExceptionHandler(configuration.getFactory().getInstance(threadableStage.getOwningThread())); // threadableStage.setOwningThread(owningThread); threadableStage.setOwningContext(configuration.getContext()); diff --git a/src/main/java/teetime/framework/Configuration.java b/src/main/java/teetime/framework/Configuration.java index 97e9c344ade98c7c9b65ce50ac0324bb5c77c125..4102d7fcb5f2e8df890a515ff89d7e3d7e5ecdee 100644 --- a/src/main/java/teetime/framework/Configuration.java +++ b/src/main/java/teetime/framework/Configuration.java @@ -15,7 +15,7 @@ */ package teetime.framework; -import teetime.framework.exceptionHandling.IExceptionListenerFactory; +import teetime.framework.exceptionHandling.AbstractExceptionListenerFactory; import teetime.framework.exceptionHandling.TerminatingExceptionListenerFactory; /** @@ -28,7 +28,7 @@ import teetime.framework.exceptionHandling.TerminatingExceptionListenerFactory; */ public abstract class Configuration extends AbstractCompositeStage { - private final IExceptionListenerFactory<?> factory; + private final AbstractExceptionListenerFactory<?> factory; private final ConfigurationContext context; private boolean executed; @@ -38,7 +38,7 @@ public abstract class Configuration extends AbstractCompositeStage { this(new TerminatingExceptionListenerFactory()); } - protected Configuration(final IExceptionListenerFactory<?> factory) { + protected Configuration(final AbstractExceptionListenerFactory<?> factory) { this.factory = factory; this.context = new ConfigurationContext(this); } @@ -51,7 +51,7 @@ public abstract class Configuration extends AbstractCompositeStage { this.executed = executed; } - public IExceptionListenerFactory<?> getFactory() { + public AbstractExceptionListenerFactory<?> getFactory() { return factory; } diff --git a/src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListener.java b/src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListener.java index c34480fa78fa3f8643af4d52e01804a825272683..3cc9dcae8d3218c23cc5194e0ebae60f4b2055ff 100644 --- a/src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListener.java +++ b/src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListener.java @@ -15,6 +15,9 @@ */ package teetime.framework.exceptionHandling; +import java.util.ArrayList; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,6 +30,8 @@ import teetime.framework.Stage; */ public abstract class AbstractExceptionListener { + private final List<Exception> exceptionsList = new ArrayList<Exception>(); + public enum FurtherExecution { CONTINUE, TERMINATE } @@ -52,4 +57,8 @@ public abstract class AbstractExceptionListener { */ public abstract FurtherExecution onStageException(Exception e, Stage throwingStage); + public List<Exception> getLoggedExceptions() { + return exceptionsList; + } + } diff --git a/src/main/java/teetime/framework/exceptionHandling/IExceptionListenerFactory.java b/src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListenerFactory.java similarity index 55% rename from src/main/java/teetime/framework/exceptionHandling/IExceptionListenerFactory.java rename to src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListenerFactory.java index cc0f1463883c089c8149a155f104c07204e1e091..918478905659f0e6dce4aaf75ee9140a443d8e38 100644 --- a/src/main/java/teetime/framework/exceptionHandling/IExceptionListenerFactory.java +++ b/src/main/java/teetime/framework/exceptionHandling/AbstractExceptionListenerFactory.java @@ -15,8 +15,24 @@ */ package teetime.framework.exceptionHandling; -public interface IExceptionListenerFactory<T extends AbstractExceptionListener> { +import java.util.HashMap; +import java.util.List; +import java.util.Map; - public T createInstance(); +public abstract class AbstractExceptionListenerFactory<T extends AbstractExceptionListener> { + + private final Map<Thread, List<Exception>> threadExceptionsMap = new HashMap<Thread, List<Exception>>(); + + protected abstract T createInstance(); + + public T getInstance(final Thread thread) { + T instance = createInstance(); + threadExceptionsMap.put(thread, instance.getLoggedExceptions()); + return instance; + } + + public Map<Thread, List<Exception>> getThreadExceptionsMap() { + return threadExceptionsMap; + } } diff --git a/src/main/java/teetime/framework/exceptionHandling/IgnoringExceptionListenerFactory.java b/src/main/java/teetime/framework/exceptionHandling/IgnoringExceptionListenerFactory.java index 200e5eb2c2e840f8aa9c52187861f74de72ac52a..ff3d76467af26f690e963426b18a8b27195f07bc 100644 --- a/src/main/java/teetime/framework/exceptionHandling/IgnoringExceptionListenerFactory.java +++ b/src/main/java/teetime/framework/exceptionHandling/IgnoringExceptionListenerFactory.java @@ -15,10 +15,10 @@ */ package teetime.framework.exceptionHandling; -public class IgnoringExceptionListenerFactory implements IExceptionListenerFactory { +public class IgnoringExceptionListenerFactory extends AbstractExceptionListenerFactory<IgnoringExceptionListener> { @Override - public AbstractExceptionListener createInstance() { + protected final IgnoringExceptionListener createInstance() { return new IgnoringExceptionListener(); } diff --git a/src/main/java/teetime/framework/exceptionHandling/LoggingExceptionListenerFactory.java b/src/main/java/teetime/framework/exceptionHandling/LoggingExceptionListenerFactory.java index 3eb9130fd221208f455b9fcd619726ad98185e41..fb5895e026af801eeff5f28656a73376d26c05f8 100644 --- a/src/main/java/teetime/framework/exceptionHandling/LoggingExceptionListenerFactory.java +++ b/src/main/java/teetime/framework/exceptionHandling/LoggingExceptionListenerFactory.java @@ -15,10 +15,10 @@ */ package teetime.framework.exceptionHandling; -public class LoggingExceptionListenerFactory implements IExceptionListenerFactory { +public class LoggingExceptionListenerFactory extends AbstractExceptionListenerFactory<LoggingExceptionListener> { @Override - public AbstractExceptionListener createInstance() { + protected final LoggingExceptionListener createInstance() { return new LoggingExceptionListener(); } diff --git a/src/main/java/teetime/framework/exceptionHandling/TerminatingExceptionListenerFactory.java b/src/main/java/teetime/framework/exceptionHandling/TerminatingExceptionListenerFactory.java index 354a04cb0889c2fc1229c4e4ca1cb888e2d7b47a..7ad763e6a1f1418e257799b91fa0ebf9ffce2fd4 100644 --- a/src/main/java/teetime/framework/exceptionHandling/TerminatingExceptionListenerFactory.java +++ b/src/main/java/teetime/framework/exceptionHandling/TerminatingExceptionListenerFactory.java @@ -15,7 +15,7 @@ */ package teetime.framework.exceptionHandling; -public class TerminatingExceptionListenerFactory implements IExceptionListenerFactory<TerminatingExceptionListener> { +public class TerminatingExceptionListenerFactory extends AbstractExceptionListenerFactory<TerminatingExceptionListener> { @Override public TerminatingExceptionListener createInstance() { diff --git a/src/test/java/teetime/framework/exceptionHandling/TestListenerFactory.java b/src/test/java/teetime/framework/exceptionHandling/TestListenerFactory.java index 270f4f0bd5c5501ffe9b4dac5cc46292af24fd69..b4ebf7141b8967ad608b6ba6c7097b3a50a3a135 100644 --- a/src/test/java/teetime/framework/exceptionHandling/TestListenerFactory.java +++ b/src/test/java/teetime/framework/exceptionHandling/TestListenerFactory.java @@ -18,12 +18,12 @@ package teetime.framework.exceptionHandling; import java.util.ArrayList; import java.util.List; -public class TestListenerFactory implements IExceptionListenerFactory { +public class TestListenerFactory extends AbstractExceptionListenerFactory<TestListener> { private final List<TestListener> instances = new ArrayList<TestListener>(); @Override - public AbstractExceptionListener createInstance() { + public TestListener createInstance() { TestListener listener = new TestListener(); instances.add(listener); return listener;