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

use of enums instead of a boolean

parent f998bce4
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ public class Analysis implements UncaughtExceptionHandler {
private final Collection<Pair<Thread, Throwable>> exceptions = new ConcurrentLinkedQueue<Pair<Thread, Throwable>>();
/**
* Creates a new {@link Analysis} that skips validating the port connections.
* Creates a new {@link Analysis} that skips validating the port connections and uses the default listener.
*
* @param configuration
* to be used for the analysis
......@@ -50,6 +50,14 @@ public class Analysis implements UncaughtExceptionHandler {
this(configuration, validationEnabled, new IgnoringStageListener());
}
/**
* Creates a new {@link Analysis} that skips validating the port connections and uses a specific listener.
*
* @param configuration
* to be used for the analysis
* @param listener
* specific listener for the exception handling
*/
public Analysis(final AnalysisConfiguration configuration, final StageExceptionListener listener) {
this(configuration, false, listener);
}
......
......@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
import teetime.framework.exceptionHandling.StageException;
import teetime.framework.exceptionHandling.StageExceptionListener;
import teetime.framework.exceptionHandling.StageExceptionListener.FurtherExecution;
abstract class RunnableStage implements Runnable {
......@@ -30,7 +31,7 @@ abstract class RunnableStage implements Runnable {
try {
executeStage();
} catch (StageException e) {
if (this.listener.onStageException(e, e.getThrowingStage())) {
if (this.listener.onStageException(e, e.getThrowingStage()) == FurtherExecution.TERMINATE) {
this.stage.terminate();
}
}
......
......@@ -9,7 +9,7 @@ public class IgnoringStageListener extends StageExceptionListener {
}
@Override
public boolean onStageException(final Exception e, final Stage throwingStage) {
return false;
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
return FurtherExecution.CONTINUE;
}
}
......@@ -5,9 +5,9 @@ import teetime.framework.Stage;
public class LoggingStageListener extends StageExceptionListener {
@Override
public boolean onStageException(final Exception e, final Stage throwingStage) {
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
logger.warn("Exception arised from" + throwingStage.getId(), e);
return false;
return FurtherExecution.CONTINUE;
}
}
......@@ -11,6 +11,10 @@ import teetime.framework.Stage;
*/
public abstract class StageExceptionListener {
public enum FurtherExecution {
CONTINUE, TERMINATE
}
/**
* The default logger, which can be used by all subclasses
*/
......@@ -30,6 +34,6 @@ public abstract class StageExceptionListener {
* @return
* true, if the thread should be terminated, false otherwise
*/
public abstract boolean onStageException(Exception e, Stage throwingStage);
public abstract FurtherExecution onStageException(Exception e, Stage throwingStage);
}
......@@ -5,9 +5,9 @@ import teetime.framework.Stage;
public class TerminatingStageListener extends StageExceptionListener {
@Override
public boolean onStageException(final Exception e, final Stage throwingStage) {
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
logger.warn("Exception arised from" + throwingStage.getId(), e);
return true;
return FurtherExecution.TERMINATE;
}
}
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