use of teetime.stage.basic.merger.dynamic.CreatePortActionMerger 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