From 4c666ac826d99c77583c4512fc09818136ab541d Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Mon, 24 Aug 2015 15:04:34 +0200 Subject: [PATCH] each factory now holds a map of thread-exceptions elements --- .../framework/A4StageAttributeSetter.java | 2 +- .../java/teetime/framework/Configuration.java | 8 ++++---- .../AbstractExceptionListener.java | 9 +++++++++ ... => AbstractExceptionListenerFactory.java} | 20 +++++++++++++++++-- .../IgnoringExceptionListenerFactory.java | 4 ++-- .../LoggingExceptionListenerFactory.java | 4 ++-- .../TerminatingExceptionListenerFactory.java | 2 +- .../TestListenerFactory.java | 4 ++-- 8 files changed, 39 insertions(+), 14 deletions(-) rename src/main/java/teetime/framework/exceptionHandling/{IExceptionListenerFactory.java => AbstractExceptionListenerFactory.java} (55%) diff --git a/src/main/java/teetime/framework/A4StageAttributeSetter.java b/src/main/java/teetime/framework/A4StageAttributeSetter.java index 3b57d5eb..5d95bec9 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 97e9c344..4102d7fc 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 c34480fa..3cc9dcae 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 cc0f1463..91847890 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 200e5eb2..ff3d7646 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 3eb9130f..fb5895e0 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 354a04cb..7ad763e6 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 270f4f0b..b4ebf714 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; -- GitLab