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

new version with boolean-return instead of explicit method, to kill the

thread
parent a27e967f
No related branches found
No related tags found
No related merge requests found
...@@ -99,7 +99,6 @@ public class Analysis implements UncaughtExceptionHandler { ...@@ -99,7 +99,6 @@ public class Analysis implements UncaughtExceptionHandler {
} else { } else {
runnable = new RunnableConsumerStage(stage, newListener); runnable = new RunnableConsumerStage(stage, newListener);
} }
newListener.setRunnableStage(runnable);
final Thread thread = new Thread(runnable); final Thread thread = new Thread(runnable);
stage.setOwningThread(thread); stage.setOwningThread(thread);
this.consumerThreads.add(thread); this.consumerThreads.add(thread);
...@@ -107,7 +106,6 @@ public class Analysis implements UncaughtExceptionHandler { ...@@ -107,7 +106,6 @@ public class Analysis implements UncaughtExceptionHandler {
} }
case BY_SELF_DECISION: { case BY_SELF_DECISION: {
RunnableProducerStage runnable = new RunnableProducerStage(stage, newListener); RunnableProducerStage runnable = new RunnableProducerStage(stage, newListener);
newListener.setRunnableStage(runnable);
final Thread thread = new Thread(runnable); final Thread thread = new Thread(runnable);
stage.setOwningThread(thread); stage.setOwningThread(thread);
this.finiteProducerThreads.add(thread); this.finiteProducerThreads.add(thread);
...@@ -115,7 +113,6 @@ public class Analysis implements UncaughtExceptionHandler { ...@@ -115,7 +113,6 @@ public class Analysis implements UncaughtExceptionHandler {
} }
case BY_INTERRUPT: { case BY_INTERRUPT: {
RunnableProducerStage runnable = new RunnableProducerStage(stage, newListener); RunnableProducerStage runnable = new RunnableProducerStage(stage, newListener);
newListener.setRunnableStage(runnable);
final Thread thread = new Thread(runnable); final Thread thread = new Thread(runnable);
stage.setOwningThread(thread); stage.setOwningThread(thread);
this.infiniteProducerThreads.add(thread); this.infiniteProducerThreads.add(thread);
......
...@@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; ...@@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
import teetime.framework.exceptionHandling.StageException; import teetime.framework.exceptionHandling.StageException;
import teetime.framework.exceptionHandling.StageExceptionListener; import teetime.framework.exceptionHandling.StageExceptionListener;
public abstract class RunnableStage implements Runnable { abstract class RunnableStage implements Runnable {
protected final Stage stage; protected final Stage stage;
@SuppressWarnings("PMD.LoggerIsNotStaticFinal") @SuppressWarnings("PMD.LoggerIsNotStaticFinal")
...@@ -30,7 +30,9 @@ public abstract class RunnableStage implements Runnable { ...@@ -30,7 +30,9 @@ public abstract class RunnableStage implements Runnable {
try { try {
executeStage(); executeStage();
} catch (StageException e) { } catch (StageException e) {
this.listener.onStageException(e, e.getThrowingStage()); if (!this.listener.onStageException(e, e.getThrowingStage())) {
this.stage.terminate();
}
} }
} while (!this.stage.shouldBeTerminated()); } while (!this.stage.shouldBeTerminated());
...@@ -47,11 +49,6 @@ public abstract class RunnableStage implements Runnable { ...@@ -47,11 +49,6 @@ public abstract class RunnableStage implements Runnable {
this.logger.debug("Finished runnable stage. (" + this.stage.getId() + ")"); this.logger.debug("Finished runnable stage. (" + this.stage.getId() + ")");
} }
public final void abortExecution() {
this.stage.terminate();
// TODO: flag error and throw exception
}
protected abstract void beforeStageExecution(); protected abstract void beforeStageExecution();
protected abstract void executeStage(); protected abstract void executeStage();
......
...@@ -10,7 +10,7 @@ public class DefaultListener extends StageExceptionListener { ...@@ -10,7 +10,7 @@ public class DefaultListener extends StageExceptionListener {
} }
@Override @Override
public void onStageException(final Exception e, final Stage throwingStage) { public boolean onStageException(final Exception e, final Stage throwingStage) {
// TODO Auto-generated method stub return true;
} }
} }
...@@ -3,7 +3,6 @@ package teetime.framework.exceptionHandling; ...@@ -3,7 +3,6 @@ package teetime.framework.exceptionHandling;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import teetime.framework.RunnableStage;
import teetime.framework.Stage; import teetime.framework.Stage;
/** /**
...@@ -12,8 +11,6 @@ import teetime.framework.Stage; ...@@ -12,8 +11,6 @@ import teetime.framework.Stage;
*/ */
public abstract class StageExceptionListener { public abstract class StageExceptionListener {
private RunnableStage runnable;
/** /**
* The default logger, which can be used by all subclasses * The default logger, which can be used by all subclasses
*/ */
...@@ -31,16 +28,6 @@ public abstract class StageExceptionListener { ...@@ -31,16 +28,6 @@ public abstract class StageExceptionListener {
* @param throwingStage * @param throwingStage
* the stage, which has thrown the exception. * the stage, which has thrown the exception.
*/ */
public abstract void onStageException(Exception e, Stage throwingStage); public abstract boolean onStageException(Exception e, Stage throwingStage);
/**
* This method can be used to terminate the execution of the thread.
*/
protected final void terminateExecution() {
this.runnable.abortExecution();
}
public final void setRunnableStage(final RunnableStage runnableStage) {
this.runnable = runnableStage;
}
} }
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