use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class AbstractRunnableStage method run.
@Override
public final void run() {
// should prevent the stage to be reloaded after a volatile read
final AbstractStage stage = this.stage;
// should prevent the logger to be reloaded after a volatile read
final Logger logger = this.logger;
logger.debug("Executing runnable stage...");
try {
beforeStageExecution();
stopWatch.start();
try {
StageFacade.INSTANCE.runStage(stage);
} finally {
stopWatch.end();
durationsInNs = stopWatch.getDurationInNs();
// create and pass TERM to all input ports (for both producer and consumer)
afterStageExecution();
}
} catch (RuntimeException e) {
logger.error(TERMINATING_THREAD_DUE_TO_THE_FOLLOWING_EXCEPTION, e);
throw e;
} catch (InterruptedException e) {
// logger.error(TERMINATING_THREAD_DUE_TO_THE_FOLLOWING_EXCEPTION, e);
StageFacade.INSTANCE.getExceptionListener(stage).reportException(e, stage);
}
logger.debug("Finished runnable stage. ({})", stage.getId());
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class ActiveConsumerStageFinder method visit.
@Override
public VisitorBehavior visit(final AbstractPort<?> outputPort) {
InputPort<?> targetPort = outputPort.getPipe().getTargetPort();
AbstractStage targetStage = targetPort.getOwningStage();
if (targetStage.isActive() && !targetStage.isProducer()) {
activeConsumerStageInputPort = targetPort;
return VisitorBehavior.STOP;
}
return VisitorBehavior.CONTINUE_FORWARD;
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class StageFactory method getProducerFromInputPort.
@SuppressWarnings("unchecked")
static <T> InitialElementProducer<T> getProducerFromInputPort(final InputPort<T> inputPort) {
OutputPort<?> sourcePort = inputPort.getPipe().getSourcePort();
AbstractStage owningStage = sourcePort.getOwningStage();
if (owningStage instanceof InitialElementProducer) {
return (InitialElementProducer<T>) owningStage;
}
String message = String.format("%s", owningStage);
throw new IllegalArgumentException(message);
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class StageFactory method getSinkFromOutputPort.
@SuppressWarnings("unchecked")
static <T> CollectorSink<T> getSinkFromOutputPort(final OutputPort<T> outputPort) {
InputPort<?> targetPort = outputPort.getPipe().getTargetPort();
AbstractStage owningStage = targetPort.getOwningStage();
if (owningStage instanceof CollectorSink) {
return (CollectorSink<T>) owningStage;
}
String message = String.format("%s", owningStage);
throw new IllegalArgumentException(message);
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class DynamicTaskFarmStage method addStageAtRuntime.
/**
* Adds a new enclosed stage at Runtime
*
* @return new created Stage
* @throws InterruptedException
*
* @author Christian Claus Wiechmann, Christoph Dornieden (code moved from TaskFarmController)
*/
public ITaskFarmDuplicable<I, O> addStageAtRuntime() throws InterruptedException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Adding stage (current amount of stages: {})", getWorkerStages().size());
}
if (!getMerger().isActive()) {
getMerger().declareActive();
}
AbstractStage basicEnclosedStage = getBasicEnclosedStage().getInputPort().getOwningStage();
if (!basicEnclosedStage.isActive()) {
basicEnclosedStage.declareActive();
}
final ITaskFarmDuplicable<I, O> newStage = getBasicEnclosedStage().duplicate();
// newStage.setTaskFarmStage(this);
final CreatePortActionDistributor<I> distributorPortAction = new CreatePortActionDistributor<I>(newStage.getInputPort(), getPipeCapacity());
getDistributor().addPortActionRequest(distributorPortAction);
distributorPortAction.waitForCompletion();
final CreatePortActionMerger<O> mergerPortAction = new CreatePortActionMerger<O>(newStage.getOutputPort(), getPipeCapacity());
getMerger().addPortActionRequest(mergerPortAction);
mergerPortAction.waitForCompletion();
// the validating and the starting signal is sent by the create action
RuntimeServiceFacade.INSTANCE.startWithinNewThread(getDistributor(), newStage.getInputPort().getOwningStage());
getWorkerStages().add(newStage);
return newStage;
}
Aggregations