/** * {@inheritdoc} */ public function signal(Execution $execution, $signal, array $variables = [], array $delegation = []) { foreach ($variables as $k => $v) { $execution->setVariable($k, $v); } if ($signal === NULL) { return $execution->takeAll(NULL, [$execution]); } return $execution->take($signal); }
public function signal(Execution $execution, $signal, array $variables = [], array $delegation = []) { $sub = $execution->getEngine()->findExecution($delegation['executionId']); if (!$sub instanceof Execution) { throw new \RuntimeException('Missing reference to nested execution'); } foreach ($this->outputs as $target => $source) { if ($sub->hasVariable($source)) { $execution->setVariable($target, $sub->getVariable($source)); } } $execution->takeAll(NULL, [$execution]); }
/** * {@inheritdoc} */ public function execute(Execution $execution) { $execution->setActive(false); $numberExecutions = count($execution->getProcessModel()->findIncomingTransitions($execution->getNode()->getId())); // Collect recycled executions, initialize with current execution: $recycle = [$execution->getTransition()->getId() => $execution]; foreach ($execution->findInactiveConcurrentExecutions($execution->getNode()) as $concurrent) { // Collect at most 1 execution per incoming transition. $transId = $concurrent->getTransition()->getId(); if (empty($recycle[$transId]) || $concurrent->getTimestamp() < $recycle[$transId]->getTimestamp()) { $recycle[$transId] = $concurrent; } } if (count($recycle) !== $numberExecutions) { return; } return $execution->takeAll(NULL, $recycle); }
/** * {@inheritdoc} */ public function execute(Execution $execution) { $execution->takeAll(); }
/** * Take all given transitions (or every transition when given NULL) recycling the given * executions in the process. * * @param array<string> $transitions * @param array<Execution> $recycle * * @throws \RuntimeException When the execution has been terminated. */ public function takeAll(array $transitions = NULL, array $recycle = []) { if ($this->isTerminated()) { throw new \RuntimeException(sprintf('Cannot take transition in terminated %s', $this)); } $this->engine->pushCommand(new CallbackCommand(function () use($transitions, $recycle) { if ($this->isConcurrent()) { if (1 === count($this->findConcurrentExecutions())) { foreach ($recycle as $rec) { foreach ($recycle as $rec) { if ($rec !== $this) { $rec->terminate(false); } } } foreach ($this->findChildExecutions() as $child) { $this->parentExecution->registerChildExecution($child); } $this->parentExecution->node = $this->node; $this->parentExecution->transition = $this->transition; $this->parentExecution->setActive(true); $this->engine->debug('Merged concurrent {execution} into {root}', ['execution' => (string) $this, 'root' => (string) $this->parentExecution]); $this->terminate(false); return $this->parentExecution->takeAll($transitions); } } if ($transitions === NULL) { $transitions = $this->getProcessModel()->findOutgoingTransitions($this->node->getId()); } else { $transitions = array_map(function ($trans) { return $trans instanceof Transition ? $trans : $this->getProcessModel()->findTransition($trans); }, $transitions); } $transitions = array_filter($transitions, function (Transition $trans) { return $trans->isEnabled($this); }); if (!in_array($this, $recycle, true)) { array_unshift($recycle, $this); } if (empty($transitions)) { foreach ($recycle as $rec) { if ($rec !== $this) { $rec->terminate(false); } } if ($this->isConcurrent() && 0 == count($this->findConcurrentExecutions())) { $this->parentExecution->setActive(true); $this->terminate(false); return $this->parentExecution->terminate(); } $this->terminate(); return; } $root = $this->isConcurrent() ? $this->parentExecution : $this; $merge = count($root->findChildExecutions()) == count($root->findChildExecutions($this->node)); $active = []; foreach ($root->findChildExecutions() as $exec) { if ($exec->isActive()) { $active[] = $exec; } } $recycle = array_filter($recycle, function (Execution $execution) use($root) { return $execution !== $root; }); if (count($transitions) == 1 && empty($active) && $merge) { $terminated = 0; foreach ($recycle as $rec) { if (!$rec->isTerminated()) { $rec->terminate(false); $terminated++; } } $this->setState(self::STATE_CONCURRENT, false); $root->setNode($this->node); $root->setActive(true); if ($terminated > 0) { $this->engine->debug('Merged {count} concurrent executions into {execution}', ['count' => $terminated, 'execution' => (string) $root]); } $this->markModified(true); return $root->take(array_shift($transitions)); } $outgoing = []; while (!empty($transitions)) { $transition = array_shift($transitions); if (empty($recycle)) { $exec = $root->createExecution(true); } else { $exec = array_shift($recycle); } $exec->setActive(true); $exec->setNode($this->node); $exec->setState(self::STATE_CONCURRENT, true); $outgoing[] = [$exec, $transition]; } $root->setActive(false); foreach ($recycle as $rec) { $rec->terminate(false); } foreach ($outgoing as $out) { $out[0]->take($out[1]); } })); }