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

introduced a flag which indicates if exceptions should be logged

parent 4c666ac8
No related branches found
No related tags found
No related merge requests found
...@@ -119,7 +119,7 @@ public abstract class Stage { ...@@ -119,7 +119,7 @@ public abstract class Stage {
} catch (TerminateException e) { } catch (TerminateException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
final FurtherExecution furtherExecution = this.exceptionListener.onStageException(e, this); final FurtherExecution furtherExecution = this.exceptionListener.reportException(e, this);
if (furtherExecution == FurtherExecution.TERMINATE) { if (furtherExecution == FurtherExecution.TERMINATE) {
throw TerminateException.INSTANCE; throw TerminateException.INSTANCE;
} }
......
...@@ -31,6 +31,7 @@ import teetime.framework.Stage; ...@@ -31,6 +31,7 @@ import teetime.framework.Stage;
public abstract class AbstractExceptionListener { public abstract class AbstractExceptionListener {
private final List<Exception> exceptionsList = new ArrayList<Exception>(); private final List<Exception> exceptionsList = new ArrayList<Exception>();
private final boolean logExceptions;
public enum FurtherExecution { public enum FurtherExecution {
CONTINUE, TERMINATE CONTINUE, TERMINATE
...@@ -41,8 +42,9 @@ public abstract class AbstractExceptionListener { ...@@ -41,8 +42,9 @@ public abstract class AbstractExceptionListener {
*/ */
protected final Logger logger; protected final Logger logger;
public AbstractExceptionListener() { protected AbstractExceptionListener(final boolean shouldLogExceptions) {
this.logger = LoggerFactory.getLogger(this.getClass().getCanonicalName()); this.logger = LoggerFactory.getLogger(this.getClass().getCanonicalName());
this.logExceptions = shouldLogExceptions;
} }
/** /**
...@@ -61,4 +63,11 @@ public abstract class AbstractExceptionListener { ...@@ -61,4 +63,11 @@ public abstract class AbstractExceptionListener {
return exceptionsList; return exceptionsList;
} }
public FurtherExecution reportException(final Exception e, final Stage stage) {
if (logExceptions) {
exceptionsList.add(e);
}
return onStageException(e, stage);
}
} }
...@@ -19,6 +19,10 @@ import teetime.framework.Stage; ...@@ -19,6 +19,10 @@ import teetime.framework.Stage;
class IgnoringExceptionListener extends AbstractExceptionListener { class IgnoringExceptionListener extends AbstractExceptionListener {
IgnoringExceptionListener() {
super(false);
}
@Override @Override
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) { public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
return FurtherExecution.CONTINUE; return FurtherExecution.CONTINUE;
......
...@@ -19,6 +19,10 @@ import teetime.framework.Stage; ...@@ -19,6 +19,10 @@ import teetime.framework.Stage;
class LoggingExceptionListener extends AbstractExceptionListener { class LoggingExceptionListener extends AbstractExceptionListener {
LoggingExceptionListener() {
super(true);
}
@Override @Override
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) { public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
logger.warn("Exception occurred in " + throwingStage.getId(), e); logger.warn("Exception occurred in " + throwingStage.getId(), e);
......
...@@ -25,7 +25,7 @@ class TerminatingExceptionListener extends AbstractExceptionListener { ...@@ -25,7 +25,7 @@ class TerminatingExceptionListener extends AbstractExceptionListener {
private final List<Exception> exceptions = new ArrayList<Exception>(); private final List<Exception> exceptions = new ArrayList<Exception>();
TerminatingExceptionListener() { TerminatingExceptionListener() {
// should only be instantiated by its factory super(true);
} }
@Override @Override
......
...@@ -19,6 +19,10 @@ import teetime.framework.Stage; ...@@ -19,6 +19,10 @@ import teetime.framework.Stage;
public class TestListener extends AbstractExceptionListener { public class TestListener extends AbstractExceptionListener {
protected TestListener() {
super(false);
}
private int numExceptionsInvoked; private int numExceptionsInvoked;
@Override @Override
......
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