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

moved catch to onSignal and removed obsolete AbstractSignal

parent d655afa6
No related branches found
No related tags found
No related merge requests found
......@@ -49,9 +49,9 @@ abstract class AbstractRunnableStage implements Runnable {
throw new IllegalArgumentException("Argument stage may not have a nullable owning context");
}
try {
do {
while (!stage.shouldBeTerminated()) {
executeStage();
} while (!stage.shouldBeTerminated());
}
} catch (TerminateException e) {
this.stage.terminate();
stage.getOwningContext().abortConfigurationRun();
......@@ -65,13 +65,16 @@ abstract class AbstractRunnableStage implements Runnable {
} catch (InterruptedException e) {
this.logger.error(TERMINATING_THREAD_DUE_TO_THE_FOLLOWING_EXCEPTION, e);
}
} finally {
} finally
{
if (stage.getTerminationStrategy() != TerminationStrategy.BY_INTERRUPT) {
stage.getOwningContext().getThreadService().getRunnableCounter().dec();
}
}
logger.debug("Finished runnable stage. (" + stage.getId() + ")");
}
protected abstract void beforeStageExecution() throws InterruptedException;
......
......@@ -55,7 +55,11 @@ public abstract class AbstractStage extends Stage {
@Override
public void onSignal(final ISignal signal, final InputPort<?> inputPort) {
if (!this.signalAlreadyReceived(signal, inputPort)) {
signal.trigger(this);
try {
signal.trigger(this);
} catch (Exception e) {
this.getOwningContext().abortConfigurationRun();
}
for (OutputPort<?> outputPort : outputPorts.getOpenedPorts()) {
outputPort.sendSignal(signal);
}
......
/**
* Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://christianwulf.github.io/teetime)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package teetime.framework.signal;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
abstract class AbstractSignal implements ISignal {
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractSignal.class);
protected final List<Exception> catchedExceptions = new LinkedList<Exception>();
protected AbstractSignal() {
super();
}
public List<Exception> getCatchedExceptions() {
return this.catchedExceptions;
}
}
......@@ -23,7 +23,7 @@ import teetime.framework.Stage;
public interface ISignal {
void trigger(Stage stage);
void trigger(Stage stage) throws Exception;
// Only used by the merger so far
boolean mayBeTriggered(Set<InputPort<?>> receivedInputPorts, List<InputPort<?>> allInputPorts);
......
......@@ -19,20 +19,13 @@ import java.util.List;
import java.util.Set;
import teetime.framework.InputPort;
import teetime.framework.RuntimeServiceFacade;
import teetime.framework.Stage;
public final class StartingSignal extends AbstractSignal {
public final class StartingSignal implements ISignal {
@Override
public void trigger(final Stage stage) {
try {
stage.onStarting();
} catch (final Exception e) { // NOCS NOPMD (Stages can throw any arbitrary Exception)
this.catchedExceptions.add(e);
RuntimeServiceFacade.INSTANCE.abortExecution(stage);
LOGGER.error("Exception while sending the start signal", e);
}
public void trigger(final Stage stage) throws Exception {
stage.onStarting();
}
@Override
......
......@@ -19,20 +19,13 @@ import java.util.List;
import java.util.Set;
import teetime.framework.InputPort;
import teetime.framework.RuntimeServiceFacade;
import teetime.framework.Stage;
public final class TerminatingSignal extends AbstractSignal {
public final class TerminatingSignal implements ISignal {
@Override
public void trigger(final Stage stage) {
try {
stage.onTerminating();
} catch (final Exception e) { // NOCS NOPMD (Stages can throw any arbitrary Exception)
this.catchedExceptions.add(e);
RuntimeServiceFacade.INSTANCE.abortExecution(stage);
LOGGER.error("Exception while sending the termination signal", e);
}
public void trigger(final Stage stage) throws Exception {
stage.onTerminating();
}
@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