Search in sources :

Example 1 with AbstractStage

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());
}
Also used : AbstractStage(teetime.framework.AbstractStage) Logger(org.slf4j.Logger)

Example 2 with AbstractStage

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;
}
Also used : AbstractStage(teetime.framework.AbstractStage)

Example 3 with AbstractStage

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);
}
Also used : InitialElementProducer(teetime.stage.InitialElementProducer) AbstractStage(teetime.framework.AbstractStage)

Example 4 with AbstractStage

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);
}
Also used : CollectorSink(teetime.stage.CollectorSink) AbstractStage(teetime.framework.AbstractStage)

Example 5 with AbstractStage

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;
}
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)23 Test (org.junit.Test)9 Traverser (teetime.framework.Traverser)3 StateChange (teetime.framework.performancelogging.StateChange)3 ObjectIntHashMap (com.carrotsearch.hppc.ObjectIntHashMap)1 Logger (org.slf4j.Logger)1 InstantiationPipe (teetime.framework.InstantiationPipe)1 TestConfiguration (teetime.framework.TestConfiguration)1 StageActivationState (teetime.framework.performancelogging.StateChange.StageActivationState)1 CollectorSink (teetime.stage.CollectorSink)1 InitialElementProducer (teetime.stage.InitialElementProducer)1 CreatePortActionDistributor (teetime.stage.basic.distributor.dynamic.CreatePortActionDistributor)1 CreatePortActionMerger (teetime.stage.basic.merger.dynamic.CreatePortActionMerger)1