Search in sources :

Example 1 with CreatePortActionDistributor

use of teetime.stage.basic.distributor.dynamic.CreatePortActionDistributor 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;
}
Also used : CreatePortActionMerger(teetime.stage.basic.merger.dynamic.CreatePortActionMerger) AbstractStage(teetime.framework.AbstractStage) CreatePortActionDistributor(teetime.stage.basic.distributor.dynamic.CreatePortActionDistributor)

Aggregations

AbstractStage (teetime.framework.AbstractStage)1 CreatePortActionDistributor (teetime.stage.basic.distributor.dynamic.CreatePortActionDistributor)1 CreatePortActionMerger (teetime.stage.basic.merger.dynamic.CreatePortActionMerger)1