Throw transition events.

@param MachineInterface $machine        Machine
@param mixed            $object         Object
@param StateLineStack   $stateLineStack StateLine Stack
@param Transition       $transition     Transition

@return $this Self object
14961
public function dispatchTransitionEvents(
        MachineInterface $machine,
        $object,
        StateLineStack $stateLineStack,
        Transition $transition
    ) {
        $this
            ->eventDispatcher
            ->dispatch(
                ElcodiStateTransitionMachineEvents::ALL_TRANSITIONS,
                TransitionEvent::create(
                    $object,
                    $stateLineStack,
                    $transition
                )
            );

        $this
            ->eventDispatcher
            ->dispatch(
                str_replace(
                    [
                        '{machine_id}',
                        '{state_name}',
                    ],
                    [
                        $machine->getId(),
                        $transition->getStart()->getName(),
                    ],
                    ElcodiStateTransitionMachineEvents::TRANSITION_FROM_STATE
                ),
                TransitionEvent::create(
                    $object,
                    $stateLineStack,
                    $transition
                )
            );

        $this
            ->eventDispatcher
            ->dispatch(
                str_replace(
                    [
                        '{machine_id}',
                        '{state_name}',
                    ],
                    [
                        $machine->getId(),
                        $transition->getFinal()->getName(),
                    ],
                    ElcodiStateTransitionMachineEvents::TRANSITION_TO_STATE
                ),
                TransitionEvent::create(
                    $object,
                    $stateLineStack,
                    $transition
                )
            );

        $this
            ->eventDispatcher
            ->dispatch(
                str_replace(
                    [
                        '{machine_id}',
                        '{transition_name}',
                    ],
                    [
                        $machine->getId(),
                        $transition->getName(),
                    ],
                    ElcodiStateTransitionMachineEvents::TRANSITION
                ),
                TransitionEvent::create(
                    $object,
                    $stateLineStack,
                    $transition
                )
            );
    }
623363
public function process(
        ObjectInterface $object,
        ResolvedFixtureSet $fixtureSet,
        GenerationContext $context,
        MethodCallInterface $methodCall
    ): ResolvedFixtureSet {
        /** @var StaticReference $reference */
        $reference = $methodCall->getCaller();

        if (false === ($reference instanceof StaticReference)) {
            throw new \LogicException('TODO');
        }

        $result = $reference->getId()::{$methodCall->getMethod()}(...$methodCall->getArguments());

        if ($context->needsCallResult()) {
            $object = $object->withInstance($result);
        }

        return $fixtureSet->withObjects(
            $fixtureSet->getObjects()->with($object)
        );
    }
1051609
public function addTransition(TransitionInterface $transition): self
    {
        if (!$this->states->hasKey($transition->getFrom())) {
            throw new UnknownState('Trying to add transition from unknown state: ' . $transition->getFrom());
        }
        if (!$this->states->hasKey($transition->getTo())) {
            throw new UnknownState('Trying to add transition to unknown state: ' . $transition->getTo());
        }
        $transition_key = $transition->getFrom().$transition->getTo();
        if ($this->transitions->hasKey($transition_key)) {
            throw new InvalidStructure(
                sprintf('Trying to add same transition twice: %s -> %s', $transition->getFrom(), $transition->getTo())
            );
        }
        $builder = clone $this;
        $builder->transitions[$transition_key] = $transition;
        return $builder;
    }
39366
public function addTransition(callable $transitionBuilderCallable)
    {
        $transitionBuilder = new TransitionBuilder();
        call_user_func($transitionBuilderCallable, $transitionBuilder);
        $transition = $transitionBuilder->getTransition();

        $this->transitions[$transition->getInitialStateName()][$transition->getName()] = $transition;
        return $this;
    }
70461
public static function reset(IStateMachine $machine)
    {
        $machineHash = sha1(json_encode($machine->getConfig()->__toArray()));
        static::$statesTries[$machineHash] = [];
    }
816616
public function performTransition(WorkflowTransition $transition)
    {
        // first make sure that the transition is valid to execute!
        $action          = $this->CurrentAction();
        $allTransitions  = $action->BaseAction()->Transitions();

        $valid = $allTransitions->find('ID', $transition->ID);
        if (!$valid) {
            throw new Exception(
                sprintf(_t(
                    'WorkflowInstance.WORKFLOW_TRANSITION_EXCEPTION',
                    'Invalid transition state for action #%s'
                ), $action->ID)
            );
        }

        $action->actionComplete($transition);

        $definition = DataObject::get_by_id(WorkflowAction::class, $transition->NextActionID);
        $action = $definition->getInstanceForWorkflow();
        $action->WorkflowID   = $this->ID;
        $action->write();

        $this->CurrentActionID = $action->ID;
        $this->write();
        $this->components = array(); // manually clear the has_one cache

        $action->actionStart($transition);

        $transition->extend('onTransition');
        $this->execute();
    }
732424
public synchronized void transition(State newState) throws IllegalStateException {
        if (transitions.containsEntry(currentState, newState)) {
            currentState = newState;
        } else {
            throw new IllegalStateException(String.format(Locale.US,
                    "Attempted invalid transition from %s to %s", currentState, newState));
        }
    }
618769
void createTransitionInstances(ProcessInstance processInstanceVO,
            List<Transition> transitions, Long fromActInstId)
           throws ProcessException,DataAccessException {
        TransitionInstance transInst;
        for (Transition transition : transitions) {
            try {
                if (tooManyMaxTransitionInstances(transition, processInstanceVO.getId())) {
                    // Look for a error transition at this time
                    // In case we find it, raise the error event
                    // Otherwise do not do anything
                    handleWorkTransitionError(processInstanceVO, transition.getId(), fromActInstId);
                } else {
                    transInst = createTransitionInstance(transition, processInstanceVO.getId());
                    String tag = logtag(processInstanceVO.getProcessId(),
                            processInstanceVO.getId(), transInst);
                    logger.info(tag, "Transition initiated from " + transition.getFromId() + " to " + transition.getToId());

                    InternalEvent jmsmsg;
                    int delay = 0;
                    jmsmsg = InternalEvent.createActivityStartMessage(
                            transition.getToId(), processInstanceVO.getId(),
                            transInst.getTransitionInstanceID(), processInstanceVO.getMasterRequestId(),
                            transition.getLabel());
                    delay = transition.getTransitionDelay();
                    String msgid = ScheduledEvent.INTERNAL_EVENT_PREFIX + processInstanceVO.getId()
                            + "start" + transition.getToId() + "by" + transInst.getTransitionInstanceID();
                    if (delay>0) this.sendDelayedInternalEvent(jmsmsg, delay, msgid, false);
                    else sendInternalEvent(jmsmsg);
                }
            } catch (SQLException ex) {
                throw new ProcessException(-1, ex.getMessage(), ex);
            } catch (MdwException ex) {
                throw new ProcessException(-1, ex.getMessage(), ex);
            }
        }
    }
672107
private function determineStartState(InputInterface $input, string $state_name = null): StateInterface
    {
        if (!$state_name) {
            return $this->getInitialState();
        }
        if (!$this->states->has($state_name)) {
            throw new ExecutionError("Trying to start statemachine execution at unknown state: ".$state_name);
        }
        $start_state = $this->states->get($state_name);
        if ($start_state->isFinal()) {
            throw new ExecutionError("Trying to (re)execute statemachine at final state: ".$state_name);
        }
        if ($start_state->isInteractive() && !$input->hasEvent()) {
            throw new ExecutionError("Trying to resume statemachine executing without providing an event/signal.");
        }
        return $start_state->isInteractive()
            ? $this->activateTransition($input, Output::fromInput($start_state->getName(), $input))
            : $start_state;
    }
1208528
private function selectSequenceFlow(TransitionalInterface $currentFlowObject)
    {
        foreach ($this->connectingObjectCollection->filterBySource($currentFlowObject) as $connectingObject) { /* @var $connectingObject ConnectingObjectInterface */
            if ($connectingObject instanceof SequenceFlow) {
                if (!($currentFlowObject instanceof ConditionalInterface) || $connectingObject->getId() !== $currentFlowObject->getDefaultSequenceFlowId()) {
                    $condition = $connectingObject->getCondition();
                    if ($condition === null) {
                        $selectedSequenceFlow = $connectingObject;
                        break;
                    } else {
                        $expressionLanguage = $this->expressionLanguage ?: new ExpressionLanguage();
                        if ($expressionLanguage->evaluate($condition, $this->processData)) {
                            $selectedSequenceFlow = $connectingObject;
                            break;
                        }
                    }
                }
            }
        }

        if (!isset($selectedSequenceFlow)) {
            if (!($currentFlowObject instanceof ConditionalInterface) || $currentFlowObject->getDefaultSequenceFlowId() === null) {
                throw new SequenceFlowNotSelectedException(sprintf('No sequence flow can be selected on "%s".', $currentFlowObject->getId()));
            }

            $selectedSequenceFlow = $this->connectingObjectCollection->get($currentFlowObject->getDefaultSequenceFlowId());
        }

        $this->stateMachine->triggerEvent($selectedSequenceFlow->getDestination()->getId());

        if ($this->getCurrentFlowObject() instanceof GatewayInterface) {
            $gateway = $this->getCurrentFlowObject();
            $this->selectSequenceFlow(/* @var $gateway GatewayInterface */$gateway);
        }
    }
609168
public function logTransition(Transition $transition)
    {
        $this
            ->logger
            ->info(
                'Transition {transition_name} in machine "{machine_id}" from "{state_from}" to "{state_to}"',
                [
                    'transition_name' => $transition->getName(),
                    'machine_id' => $this->machine->getId(),
                    'state_from' => $transition->getStart()->getName(),
                    'state_to' => $transition->getFinal()->getName(),
                ]
            );
    }
1214784
public void stateMachine(ShanksSimulation sim) throws Exception{
        logger.fine("Using default state machine for ScenarioManager");
//        switch (this.simulationStateMachineStatus) {
//        case CHECK_FAILURES:
//            this.checkFailures(sim);
//            this.simulationStateMachineStatus = GENERATE_FAILURES;
//            break;
//        case GENERATE_FAILURES:
//            this.generateFailures(sim);
//            this.simulationStateMachineStatus = CHECK_PERIODIC_;
//            break;
//        case GENERATE_PERIODIC_EVENTS:
//            this.generatePeriodicEvents(sim);
//            this.simulationStateMachineStatus = CHECK_FAILURES;
//            break;
//        case GENERATE_RANDOM_EVENTS:
//            this.generateRandomEvents(sim);
//            this.simulationStateMachineStatus = CHECK_FAILURES;
//            break;
//        }

        this.checkFailures(sim);
        this.generateFailures(sim);
        this.generateScenarioEvents(sim);
        this.generateNetworkElementEvents(sim);
        long step = sim.getSchedule().getSteps();
        if (step%500==0) {
            logger.info("Step: " + step);
            logger.finest("In step " + step + ", there are " + sim.getScenario().getCurrentFailures().size() + " current failures.");
            logger.finest("In step " + step + ", there are " + sim.getNumOfResolvedFailures() + " resolved failures.");
        }
    }
1286694
protected function callCallbacks(TransitionEvent $event, $position)
    {
        if (!isset($this->config['callbacks'][$position])) {
            return true;
        }

        $result = true;
        foreach ($this->config['callbacks'][$position] as &$callback) {
            if (!$callback instanceof CallbackInterface) {
                $callback = $this->callbackFactory->get($callback);
            }

            $result = call_user_func($callback, $event) && $result;
        }
        return $result;
    }
1022
public function getPosibleTransitions(StatableInterface $object =  null, $objectIdentifier = 'id')
    {
        if (empty($object)) {
            return;
        }

        $sm = $this->factory->get($object, $object->getStateGraph());

        if (empty($sm)) {
            return;
        }

        $tasks = array();
        $accessor = PropertyAccess::createPropertyAccessor();

        foreach ($object->getStateTransitions() as $transition) {
            if ($sm->can($transition)) {

                $color = $this->getTransitionColor($transition);
                $tasks[] = array(
                    'id' => $accessor->getValue($object, $objectIdentifier),
                    'name' => $transition,
                    'color' => $color,
                    'graph' => $object->getStateGraph(),
                    'label' => $this->getTransition($transition),
                    'negative' => $this->isNegativeColor($color, 'transition'),
                    'positive' => $this->isPositiveColor($color, 'transition'),
                );
            }
        }

        return empty($tasks) ? null : $tasks;
    }
243402
public function getAvailableTransitions(Workflow $workflow, AbstractSubject $subject, array $metaData = null): Generator
    {
        if (!$workflow instanceof StateMachine) {
            throw new Exception(sprintf('Generator %s only support model type state machine', static::getName()));
        }

        $graph = $this->graphBuilder->build($workflow);
        $algorithm = new Bruteforce($graph);
        $edges = $algorithm->getEdges();
        $edges = $edges->getVector();
        while (!empty($edges)) {
            $edge = array_shift($edges);
            $transitionName = $edge->getAttribute('name');
            if ($workflow->can($subject, $transitionName)) {
                yield $transitionName;
            } else {
                break;
            }
        }
    }
1099646
public function createTransition(StateInterface $sourceState, StateInterface $targetState, $eventName = null, ConditionInterface $condition = null)
    {
        return new Transition($targetState, $eventName, $condition);
    }
369376
public static function create(
        $object,
        StateLineStack $stateLineStack,
        Transition $transition
    ) {
        return new self(
            $object,
            $stateLineStack,
            $transition
        );
    }